-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from 5th-Neordinary-HACKATHON-MEETA/issue/3
Feat: entity 1차 생성 - #3
- Loading branch information
Showing
19 changed files
with
276 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Controller } from '@nestjs/common'; | ||
|
||
@Controller('announcements') | ||
export class AnnouncementsController { | ||
constructor() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { Announcement } from './entities/announcement.entity'; | ||
import { AnnouncementsService } from './announcements.service'; | ||
import { AnnouncementsController } from './announcements.controller'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([Announcement])], | ||
controllers: [AnnouncementsController], | ||
providers: [AnnouncementsService], | ||
exports: [], | ||
}) | ||
export class AnnouncementsModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class AnnouncementsService { | ||
constructor() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
Column, | ||
Entity, | ||
JoinColumn, | ||
ManyToOne, | ||
OneToOne, | ||
PrimaryGeneratedColumn, | ||
} from 'typeorm'; | ||
import { IsString } from 'class-validator'; | ||
import { User } from '../../users/entities/users.entity'; | ||
import { Meeting } from '../../meetings/entities/meeting.entity'; | ||
|
||
@Entity() | ||
export class Announcement { | ||
@PrimaryGeneratedColumn('uuid') | ||
id!: string; | ||
|
||
@ManyToOne((type) => User, (user) => user.announcements, { | ||
onDelete: 'SET NULL', | ||
}) | ||
writer!: User; | ||
|
||
@OneToOne((type) => Meeting, (meeting) => meeting.announcement) | ||
@JoinColumn() | ||
meeting!: Meeting; | ||
|
||
@Column() | ||
@IsString() | ||
title!: string; | ||
|
||
@Column() | ||
@IsString() | ||
content!: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { | ||
Column, | ||
Entity, | ||
JoinColumn, | ||
OneToMany, | ||
OneToOne, | ||
PrimaryGeneratedColumn, | ||
} from 'typeorm'; | ||
import { IsDate, IsNumber, IsString } from 'class-validator'; | ||
import { Announcement } from '../../announcements/entities/announcement.entity'; | ||
import { Possible_Time } from '../../relationentities/possible_time.entity'; | ||
|
||
@Entity() | ||
export class Meeting { | ||
@PrimaryGeneratedColumn('uuid') | ||
id!: string; | ||
|
||
@Column() | ||
@IsString() | ||
name!: string; | ||
|
||
@Column() | ||
@IsDate() | ||
dateTime?: Date; | ||
|
||
@Column() | ||
@IsNumber() | ||
duration!: number; | ||
|
||
@Column() | ||
@IsString() | ||
location?: string; | ||
|
||
@OneToOne((type) => Announcement, (announcement) => announcement.meeting) | ||
@JoinColumn() | ||
announcement?: Announcement; | ||
|
||
@OneToMany((type) => Possible_Time, (possibleTime) => possibleTime) | ||
possibleTimes?: Possible_Time[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Controller } from '@nestjs/common'; | ||
|
||
@Controller('meetings') | ||
export class MeetingsController { | ||
constructor() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { Meeting } from './entities/meeting.entity'; | ||
import { MeetingsController } from './meetings.controller'; | ||
import { MeetingsService } from './meetings.service'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([Meeting])], | ||
controllers: [MeetingsController], | ||
providers: [MeetingsService], | ||
exports: [], | ||
}) | ||
export class MeetingsModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class MeetingsService { | ||
constructor() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; | ||
import { User } from '../users/entities/users.entity'; | ||
import { Team } from '../teams/entities/team.entity'; | ||
|
||
@Entity() | ||
export class Participant { | ||
@PrimaryGeneratedColumn('uuid') | ||
id!: string; | ||
|
||
@ManyToOne((type) => User, (user) => user.participants, { | ||
nullable: false, | ||
onDelete: 'CASCADE', | ||
}) | ||
user!: User; | ||
|
||
@ManyToOne((type) => Team, (team) => team.participants, { | ||
nullable: false, | ||
onDelete: 'CASCADE', | ||
}) | ||
team!: Team; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; | ||
import { User } from '../users/entities/users.entity'; | ||
import { Meeting } from '../meetings/entities/meeting.entity'; | ||
|
||
@Entity() | ||
export class Possible_Time { | ||
@PrimaryGeneratedColumn('uuid') | ||
id!: string; | ||
|
||
@ManyToOne((type) => User, (user) => user.possibleTimes, { | ||
nullable: false, | ||
onDelete: 'CASCADE', | ||
}) | ||
user!: User; | ||
|
||
@ManyToOne((type) => Meeting, (meeting) => meeting.possibleTimes, { | ||
nullable: false, | ||
onDelete: 'CASCADE', | ||
}) | ||
meeting!: Meeting; | ||
|
||
@Column() | ||
possibleTime!: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { Participant } from './participant.entity'; | ||
import { Possible_Time } from './possible_time.entity'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([Participant, Possible_Time])], | ||
controllers: [], | ||
providers: [], | ||
exports: [], | ||
}) | ||
export class RelationentitiesModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { | ||
Column, | ||
Entity, | ||
ManyToOne, | ||
OneToMany, | ||
PrimaryGeneratedColumn, | ||
} from 'typeorm'; | ||
import { IsDate, IsNumber, IsString } from 'class-validator'; | ||
import { Participant } from '../../relationentities/participant.entity'; | ||
import { User } from '../../users/entities/users.entity'; | ||
|
||
@Entity() | ||
export class Team { | ||
@PrimaryGeneratedColumn('uuid') | ||
id!: string; | ||
|
||
@ManyToOne(() => User) | ||
boss!: User; | ||
|
||
@Column() | ||
@IsString() | ||
name!: string; | ||
|
||
@Column() | ||
@IsNumber() | ||
maxMember!: number; | ||
|
||
@Column() | ||
@IsDate() | ||
startedAt!: Date; | ||
|
||
@Column() | ||
@IsDate() | ||
endedAt!: Date; | ||
|
||
@OneToMany((type) => Participant, (participant) => participant, { | ||
nullable: true, | ||
}) | ||
participants: Participant[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Controller } from '@nestjs/common'; | ||
|
||
@Controller('teams') | ||
export class TeamsController { | ||
constructor() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { Team } from './entities/team.entity'; | ||
import { TeamsController } from './teams.controller'; | ||
import { TeamsService } from './teams.service'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([Team])], | ||
controllers: [TeamsController], | ||
providers: [TeamsService], | ||
exports: [], | ||
}) | ||
export class TeamsModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class TeamsService { | ||
constructor() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,35 @@ | ||
import { InternalServerErrorException } from '@nestjs/common'; | ||
import { | ||
BeforeInsert, | ||
BeforeUpdate, | ||
Column, | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
} from 'typeorm'; | ||
import { IsEmail, IsString, Matches } from 'class-validator'; | ||
import * as bcrypt from 'bcrypt'; | ||
import { Column, Entity, OneToMany, PrimaryColumn, Unique } from 'typeorm'; | ||
import { IsString } from 'class-validator'; | ||
import { Participant } from '../../relationentities/participant.entity'; | ||
import { Announcement } from '../../announcements/entities/announcement.entity'; | ||
import { Possible_Time } from '../../relationentities/possible_time.entity'; | ||
|
||
@Entity() | ||
@Unique(['nickname']) | ||
export class User { | ||
@PrimaryGeneratedColumn('uuid') | ||
id!: number; | ||
@PrimaryColumn() | ||
id!: string; | ||
|
||
@Column() | ||
@IsString() | ||
nickname!: string; | ||
|
||
@Column({ unique: true }) | ||
@IsEmail() | ||
email!: string; | ||
|
||
@Column({ select: false }) | ||
@IsString() | ||
@Matches(/^(?=.*\d)[A-Za-z\d@$!%*?&]{8,}$/, { | ||
message: | ||
'Password must be at least 8 characters(en) long, contain 1 number', | ||
}) | ||
//@Matches(/^(?=.*\d)[A-Za-z\d@$!%*?&]{8,}$/, { | ||
// message: | ||
// 'Password must be at least 8 characters(en) long, contain 1 number', | ||
//}) | ||
password!: string; | ||
|
||
@BeforeInsert() | ||
@BeforeUpdate() | ||
async hashPassword(): Promise<void> { | ||
if (this.password) { | ||
try { | ||
this.password = await bcrypt.hash(this.password, 10); | ||
} catch (e) { | ||
throw new InternalServerErrorException(); | ||
} | ||
} | ||
} | ||
@OneToMany((type) => Participant, (participant) => participant, { | ||
nullable: true, | ||
}) | ||
participants: Participant[]; | ||
|
||
@OneToMany((type) => Announcement, (announcement) => announcement.writer) | ||
announcements: Announcement[]; | ||
|
||
async checkPassword(plainPassword: string): Promise<boolean> { | ||
try { | ||
return await bcrypt.compare(plainPassword, this.password); | ||
} catch (e) { | ||
throw new InternalServerErrorException(); | ||
} | ||
} | ||
@OneToMany((type) => Possible_Time, (possibleTime) => possibleTime) | ||
possibleTimes: Possible_Time[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,6 @@ export class UsersService { | |
|
||
async deleteAccount() { | ||
const user: User = new User(); | ||
user.nickname = 'test'; | ||
user.email = '[email protected]'; | ||
user.password = '1234'; | ||
await this.usersRepository.save(user); | ||
} | ||
|