-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Group CRUD 구현 * refactor: dto 및 스킴의 ObjectId 타입 > string * fix: group/update SQL Injection issue * feat: member crud * fix: member crud npm test --------- Co-authored-by: ssoxong <[email protected]>
- Loading branch information
Showing
18 changed files
with
285 additions
and
54 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
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,4 +1,15 @@ | ||
import { PartialType } from '@nestjs/swagger'; | ||
import { CreateGroupDto } from './create-group.dto'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class UpdateGroupDto extends PartialType(CreateGroupDto) {} | ||
export class UpdateGroupDto { | ||
@ApiProperty({ | ||
description: '모임 이름', | ||
example: 'SSU', | ||
}) | ||
readonly name: string; | ||
|
||
@ApiProperty({ | ||
description: '모임 설명', | ||
example: '숭실대학교 학생들의 모임', | ||
}) | ||
readonly description: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
export class Group {} | ||
export class Group { | ||
id: string; | ||
name: string; | ||
description: string; | ||
manager: string; | ||
subManagers: [ | ||
{ | ||
user: string; | ||
authorities: string[]; | ||
}, | ||
]; | ||
members: 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 |
---|---|---|
@@ -1,5 +1,14 @@ | ||
import { Document } from 'mongoose'; | ||
|
||
export interface Group extends Document { | ||
readonly name: string; | ||
name: string; | ||
description: string; | ||
manager: string; | ||
subManagers: [ | ||
{ | ||
user: string; | ||
authorities: string[]; | ||
}, | ||
]; | ||
members: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
export class CreateMemberDto {} | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class CreateMemberDto { | ||
@ApiProperty({ | ||
description: '회원 이름', | ||
example: '박하은', | ||
}) | ||
readonly name: string; | ||
|
||
@ApiProperty({ | ||
description: '회원 연락처', | ||
example: '010-1234-5678', | ||
}) | ||
readonly phoneNumber: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
import { PartialType } from '@nestjs/swagger'; | ||
import { ApiProperty, PartialType } from '@nestjs/swagger'; | ||
import { CreateMemberDto } from './create-member.dto'; | ||
|
||
export class UpdateMemberDto extends PartialType(CreateMemberDto) {} | ||
export class UpdateMemberDto extends PartialType(CreateMemberDto) { | ||
@ApiProperty({ | ||
description: '회원 이름', | ||
example: '박하은', | ||
}) | ||
readonly name: string; | ||
|
||
@ApiProperty({ | ||
description: '회원 연락처', | ||
example: '010-1234-5678', | ||
}) | ||
readonly phoneNumber: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
export class Member {} | ||
export class Member { | ||
id: string; | ||
name: string; | ||
phoneNumber: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Document } from 'mongoose'; | ||
|
||
export interface Member extends Document { | ||
name: string; | ||
phoneNumber: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { MemberController } from './member.controller'; | ||
import { MemberService } from './member.service'; | ||
import { Member } from './interfaces/member.interface'; | ||
import { HydratedDocument, Model } from 'mongoose'; | ||
|
||
describe('MemberController', () => { | ||
let controller: MemberController; | ||
let memberController: MemberController; | ||
let memberService: MemberService; | ||
let memberModel: Model<Member>; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [MemberController], | ||
providers: [MemberService], | ||
}).compile(); | ||
|
||
controller = module.get<MemberController>(MemberController); | ||
memberService = new MemberService(memberModel); | ||
memberController = new MemberController(memberService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
describe('findAll', () => { | ||
it('should return an array of members', async () => { | ||
const result: HydratedDocument<any> = [ | ||
{ _id: 1, name: '테스트1' }, | ||
{ _id: 2, name: '테스트2' }, | ||
]; | ||
jest.spyOn(memberService, 'findAll').mockImplementation(() => result); | ||
|
||
expect(await memberController.findAll()).toBe(result); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { MemberService } from './member.service'; | ||
import { MemberController } from './member.controller'; | ||
import { DatabaseModule } from '../database/database.module'; | ||
import { memberProvider } from './member.provider'; | ||
|
||
@Module({ | ||
imports: [DatabaseModule], | ||
controllers: [MemberController], | ||
providers: [MemberService], | ||
providers: [MemberService, ...memberProvider], | ||
}) | ||
export class MemberModule {} |
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,11 @@ | ||
import { Connection } from 'mongoose'; | ||
import { MemberSchema } from './schemas/member.schema'; | ||
|
||
export const memberProvider = [ | ||
{ | ||
provide: 'MEMBER_MODEL', | ||
useFactory: (connection: Connection) => | ||
connection.model('Member', MemberSchema), | ||
inject: ['MONGODB_CONNECTION'], | ||
}, | ||
]; |
Oops, something went wrong.