From 2ce03183b44e25d23c096e757b675dca65d2ac0e Mon Sep 17 00:00:00 2001 From: w8385 Date: Thu, 18 Apr 2024 20:59:05 +0900 Subject: [PATCH 01/13] =?UTF-8?q?feat:=20Group=20=EC=86=8D=EC=84=B1?= =?UTF-8?q?=EC=97=90=20`events`=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/group/entities/group.entity.ts | 1 + src/group/interfaces/group.interface.ts | 1 + src/group/schemas/group.schema.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/src/group/entities/group.entity.ts b/src/group/entities/group.entity.ts index d19745f..5968a8d 100644 --- a/src/group/entities/group.entity.ts +++ b/src/group/entities/group.entity.ts @@ -10,4 +10,5 @@ export class Group { }, ]; members: string[]; + events: string[]; } diff --git a/src/group/interfaces/group.interface.ts b/src/group/interfaces/group.interface.ts index aeb4422..ab3cdec 100644 --- a/src/group/interfaces/group.interface.ts +++ b/src/group/interfaces/group.interface.ts @@ -11,4 +11,5 @@ export interface Group extends Document { }, ]; members: string[]; + events: string[]; } diff --git a/src/group/schemas/group.schema.ts b/src/group/schemas/group.schema.ts index 12de0ba..30ad9b0 100644 --- a/src/group/schemas/group.schema.ts +++ b/src/group/schemas/group.schema.ts @@ -14,4 +14,5 @@ export const GroupSchema = new Schema({ default: [], }, members: { type: [String], default: [] }, + events: { type: [String], default: [] }, }); From 303820e0e8d15f66ee3fff129ed46a3fb7982c7d Mon Sep 17 00:00:00 2001 From: w8385 Date: Sun, 21 Apr 2024 17:32:23 +0900 Subject: [PATCH 02/13] feat: Event CRUD --- src/event/entities/event.entity.ts | 9 +++++- src/event/event.controller.ts | 42 +++++++++++-------------- src/event/event.module.ts | 7 ++++- src/event/event.providers.ts | 11 +++++++ src/event/event.repository.ts | 34 ++++++++++++++++++++ src/event/event.service.ts | 36 ++++++++++++++++----- src/event/interfaces/event.interface.ts | 10 ++++++ src/event/schemas/event.schema.ts | 10 ++++++ 8 files changed, 126 insertions(+), 33 deletions(-) create mode 100644 src/event/event.providers.ts create mode 100644 src/event/event.repository.ts create mode 100644 src/event/interfaces/event.interface.ts create mode 100644 src/event/schemas/event.schema.ts diff --git a/src/event/entities/event.entity.ts b/src/event/entities/event.entity.ts index 8c34a9a..0e15c7c 100644 --- a/src/event/entities/event.entity.ts +++ b/src/event/entities/event.entity.ts @@ -1 +1,8 @@ -export class Event {} +export class Event { + name: string; + description: string; + startDate: Date; + endDate: Date; + fee: number; + attendees: string[]; +} diff --git a/src/event/event.controller.ts b/src/event/event.controller.ts index 309eca1..0bf8e55 100644 --- a/src/event/event.controller.ts +++ b/src/event/event.controller.ts @@ -1,12 +1,4 @@ -import { - Body, - Controller, - Delete, - Get, - Param, - Patch, - Post, -} from '@nestjs/common'; +import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'; import { EventService } from './event.service'; import { CreateEventDto } from './dto/create-event.dto'; import { UpdateEventDto } from './dto/update-event.dto'; @@ -23,20 +15,23 @@ export class EventController { constructor(private readonly eventService: EventService) {} @Post() - create(@Body() createEventDto: CreateEventDto) { - return this.eventService.create(createEventDto); + create( + @Param('groupId') groupId: string, + @Body() createEventDto: CreateEventDto, + ) { + return this.eventService.create(groupId, createEventDto); } @Get() - findAll() { - return this.eventService.findAll(); + findAll(@Param('groupId') groupId: string) { + return this.eventService.findAll(groupId); } @Get(':eventId') @ApiParam({ - name: 'memberId', + name: 'eventId', required: true, - description: '모임 회원 ID', + description: '이벤트 ID', }) findOne( @Param('groupId') groupId: string, @@ -47,24 +42,25 @@ export class EventController { @Patch(':eventId') @ApiParam({ - name: 'memberId', + name: 'eventId', required: true, - description: '모임 회원 ID', + description: '이벤트 ID', }) update( + @Param('groupId') groupId: string, @Param('eventId') eventId: string, @Body() updateEventDto: UpdateEventDto, ) { - return this.eventService.update(+eventId, updateEventDto); + return this.eventService.update(groupId, eventId, updateEventDto); } - @Delete(':eventId') + @Patch(':eventId') @ApiParam({ - name: 'memberId', + name: 'eventId', required: true, - description: '모임 회원 ID', + description: '이벤트 ID', }) - remove(@Param('eventId') eventId: string) { - return this.eventService.remove(+eventId); + remove(@Param('groupId') groupId: string, @Param('eventId') eventId: string) { + return this.eventService.remove(groupId, eventId); } } diff --git a/src/event/event.module.ts b/src/event/event.module.ts index 0ae4e92..168dab0 100644 --- a/src/event/event.module.ts +++ b/src/event/event.module.ts @@ -1,9 +1,14 @@ import { Module } from '@nestjs/common'; import { EventService } from './event.service'; import { EventController } from './event.controller'; +import { DatabaseModule } from '../database/database.module'; +import { EventRepository } from './event.repository'; +import { eventProviders } from './event.providers'; +import { GroupModule } from '../group/group.module'; @Module({ + imports: [DatabaseModule, GroupModule], controllers: [EventController], - providers: [EventService], + providers: [EventService, ...eventProviders, EventRepository], }) export class EventModule {} diff --git a/src/event/event.providers.ts b/src/event/event.providers.ts new file mode 100644 index 0000000..255d467 --- /dev/null +++ b/src/event/event.providers.ts @@ -0,0 +1,11 @@ +import { Connection } from 'mongoose'; +import { EventSchema } from './schemas/event.schema'; + +export const eventProviders = [ + { + provide: 'EVENT_MODEL', + useFactory: (connection: Connection) => + connection.model('Event', EventSchema), + inject: ['MONGODB_CONNECTION'], + }, +]; diff --git a/src/event/event.repository.ts b/src/event/event.repository.ts new file mode 100644 index 0000000..4552573 --- /dev/null +++ b/src/event/event.repository.ts @@ -0,0 +1,34 @@ +import { Inject, Injectable } from '@nestjs/common'; +import { Model } from 'mongoose'; +import { Event } from './interfaces/event.interface'; +import { CreateEventDto } from './dto/create-event.dto'; + +@Injectable() +export class EventRepository { + constructor( + @Inject('EVENT_MODEL') + private readonly eventModel: Model, + ) {} + + create(createEventDto: CreateEventDto): Promise { + return this.eventModel.create(createEventDto); + } + + findAll(): Promise { + return this.eventModel.find().exec(); + } + + findOne(eventId: string): Promise { + return this.eventModel.findById(eventId).exec(); + } + + update(eventId: string, updateEventDto: CreateEventDto): Promise { + return this.eventModel + .findByIdAndUpdate(eventId, updateEventDto, { new: true }) + .exec(); + } + + delete(eventId: string) { + this.eventModel.findByIdAndDelete(eventId); + } +} diff --git a/src/event/event.service.ts b/src/event/event.service.ts index 75652ca..fa42d99 100644 --- a/src/event/event.service.ts +++ b/src/event/event.service.ts @@ -1,29 +1,49 @@ import { Injectable } from '@nestjs/common'; import { CreateEventDto } from './dto/create-event.dto'; import { UpdateEventDto } from './dto/update-event.dto'; +import { EventRepository } from './event.repository'; +import { GroupService } from '../group/group.service'; @Injectable() export class EventService { - create(createEventDto: CreateEventDto) { - return createEventDto; + constructor( + private readonly eventRepository: EventRepository, + private readonly groupService: GroupService, + ) {} + + create(groupId: string, createEventDto: CreateEventDto) { + return { groupId, event: this.eventRepository.create(createEventDto) }; } - findAll() { - return `This action returns all event`; + async findAll(groupId: string) { + const group = await this.groupService.findOne(groupId); + return { + groupId, + events: group.events, + }; } findOne(groupId: string, eventId: string) { + const group = this.groupService.findOne(groupId); + const event = this.eventRepository.findOne(eventId); return { groupId, + group, eventId, + event, }; } - update(eventId: number, updateEventDto: UpdateEventDto) { - return `This action updates a #${eventId} event` + updateEventDto; + update(groupId: string, eventId: string, updateEventDto: UpdateEventDto) { + return { + groupId, + eventId, + event: this.eventRepository.update(eventId, updateEventDto), + }; } - remove(eventId: number) { - return `This action removes a #${eventId} event`; + remove(groupId: string, eventId: string) { + const group = this.groupService.findOne(groupId); + return this.eventRepository.delete(eventId); } } diff --git a/src/event/interfaces/event.interface.ts b/src/event/interfaces/event.interface.ts new file mode 100644 index 0000000..f1095cc --- /dev/null +++ b/src/event/interfaces/event.interface.ts @@ -0,0 +1,10 @@ +import { Document } from 'mongoose'; + +export interface Event extends Document { + name: string; + description: string; + startDate: Date; + endDate: Date; + fee: number; + attendees: string[]; +} diff --git a/src/event/schemas/event.schema.ts b/src/event/schemas/event.schema.ts new file mode 100644 index 0000000..ad9608e --- /dev/null +++ b/src/event/schemas/event.schema.ts @@ -0,0 +1,10 @@ +import { Schema } from 'mongoose'; + +export const EventSchema = new Schema({ + name: String, + description: String, + startDate: Date, + endDate: Date, + fee: Number, + attendees: { type: [String], default: [] }, +}); From c2d2c9da11baa3098e293f8857729e533c660c4c Mon Sep 17 00:00:00 2001 From: w8385 Date: Sun, 21 Apr 2024 21:52:47 +0900 Subject: [PATCH 03/13] feat: Group.members > `any` --- src/group/entities/group.entity.ts | 2 +- src/group/interfaces/group.interface.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/group/entities/group.entity.ts b/src/group/entities/group.entity.ts index 5968a8d..dfdf42f 100644 --- a/src/group/entities/group.entity.ts +++ b/src/group/entities/group.entity.ts @@ -9,6 +9,6 @@ export class Group { authorities: string[]; }, ]; - members: string[]; + members: any[]; events: string[]; } diff --git a/src/group/interfaces/group.interface.ts b/src/group/interfaces/group.interface.ts index ab3cdec..cadcb74 100644 --- a/src/group/interfaces/group.interface.ts +++ b/src/group/interfaces/group.interface.ts @@ -10,6 +10,6 @@ export interface Group extends Document { authorities: string[]; }, ]; - members: string[]; + members: any[]; events: string[]; } From c1fed499eb92274e8d27603b0d6b55c2f914cd0d Mon Sep 17 00:00:00 2001 From: w8385 Date: Sun, 21 Apr 2024 21:56:05 +0900 Subject: [PATCH 04/13] =?UTF-8?q?feat:=20[GET]=20/group/member=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/member/member.repository.ts | 4 ---- src/member/member.service.ts | 10 ++++++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/member/member.repository.ts b/src/member/member.repository.ts index 46fc391..8649141 100644 --- a/src/member/member.repository.ts +++ b/src/member/member.repository.ts @@ -15,10 +15,6 @@ export class MemberRepository { return this.memberModel.create(createMemberDto); } - findAll(members: string[]): Promise { - return this.memberModel.find({ _id: { $in: members } }).exec(); - } - findOne(memberId: string): Promise { return this.memberModel.findById(memberId).exec(); } diff --git a/src/member/member.service.ts b/src/member/member.service.ts index 74ec67b..b4a7ab8 100644 --- a/src/member/member.service.ts +++ b/src/member/member.service.ts @@ -42,9 +42,15 @@ export class MemberService { } async findAll(groupId: string): Promise { - //lookup 써서 join하려고 했는데 model처리가 어려워서 임시로..디비 두번 접근 const group = await this.groupService.findOne(groupId); - return (await this.memberRepository.findAll(group.members)) as Member[]; + + const members = []; + for (const memberId of group.members) { + const member = await this.memberRepository.findOne(memberId); + if (member) members.push(member); + } + + return members; } async findOne(groupId: string, memberId: string): Promise { From 883ecfe2bb84a7956630a6c9e1ab76491f2cdfb8 Mon Sep 17 00:00:00 2001 From: w8385 Date: Sun, 21 Apr 2024 22:48:22 +0900 Subject: [PATCH 05/13] feat: groupService > addEvent, deleteEvent --- src/group/group.service.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/group/group.service.ts b/src/group/group.service.ts index 8ce3051..ebb1b6e 100644 --- a/src/group/group.service.ts +++ b/src/group/group.service.ts @@ -22,6 +22,13 @@ export class GroupService { return group; } + async addEvent(groupId: string, eventId: string): Promise { + const group = (await this.groupRepository.findOne(groupId)) as Group; + group.events.push(eventId); + await this.groupRepository.update(groupId, group); + return group; + } + async findAll(): Promise { return (await this.groupRepository.findAll()) as Group[]; } @@ -55,6 +62,15 @@ export class GroupService { await this.groupRepository.update(groupId, group); } + async deleteEvent(groupId: string, eventId: string): Promise { + const group = (await this.groupRepository.findOne(groupId)) as Group; + const groupEvents = group.events; + + group.events = groupEvents.filter((event) => event !== eventId); + + await this.groupRepository.update(groupId, group); + } + async deleteAll(): Promise { return this.groupRepository.deleteAll(); } From 745945227c4663a1a7505cddeb6f1f86ab29c03a Mon Sep 17 00:00:00 2001 From: w8385 Date: Sun, 21 Apr 2024 22:48:30 +0900 Subject: [PATCH 06/13] feat: Event CRUD --- src/event/dto/create-event.dto.ts | 34 ++++++++++++++++++++- src/event/event.controller.ts | 34 +++++++++++++++++++-- src/event/event.repository.ts | 11 ++++--- src/event/event.service.ts | 51 ++++++++++++++++++++----------- 4 files changed, 103 insertions(+), 27 deletions(-) diff --git a/src/event/dto/create-event.dto.ts b/src/event/dto/create-event.dto.ts index f23a408..fbb7d5e 100644 --- a/src/event/dto/create-event.dto.ts +++ b/src/event/dto/create-event.dto.ts @@ -1 +1,33 @@ -export class CreateEventDto {} +import { ApiProperty } from '@nestjs/swagger'; + +export class CreateEventDto { + @ApiProperty({ + description: '이벤트 이름', + example: '2024년 1학기 모임', + }) + name: string; + + @ApiProperty({ + description: '이벤트 설명', + example: '2024년 1학기 모임입니다.', + }) + description: string; + + @ApiProperty({ + description: '이벤트 시작일', + example: new Date().toISOString(), + }) + startDate: Date; + + @ApiProperty({ + description: '이벤트 종료일', + example: new Date(), + }) + endDate: Date; + + @ApiProperty({ + description: '이벤트 참가비', + example: 10000, + }) + fee: number; +} diff --git a/src/event/event.controller.ts b/src/event/event.controller.ts index 0bf8e55..6c0b3cd 100644 --- a/src/event/event.controller.ts +++ b/src/event/event.controller.ts @@ -1,8 +1,16 @@ -import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'; +import { + Body, + Controller, + Delete, + Get, + Param, + Patch, + Post, +} from '@nestjs/common'; import { EventService } from './event.service'; import { CreateEventDto } from './dto/create-event.dto'; import { UpdateEventDto } from './dto/update-event.dto'; -import { ApiParam, ApiTags } from '@nestjs/swagger'; +import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger'; @ApiTags('Event') @Controller('group/:groupId/event') @@ -15,6 +23,10 @@ export class EventController { constructor(private readonly eventService: EventService) {} @Post() + @ApiOperation({ + summary: '이벤트 생성', + description: '모임의 이벤트를 생성합니다.', + }) create( @Param('groupId') groupId: string, @Body() createEventDto: CreateEventDto, @@ -23,11 +35,19 @@ export class EventController { } @Get() + @ApiOperation({ + summary: '모임 모든 이벤트 조회', + description: '모임의 모든 이벤트를 조회합니다.', + }) findAll(@Param('groupId') groupId: string) { return this.eventService.findAll(groupId); } @Get(':eventId') + @ApiOperation({ + summary: '이벤트 상세 조회', + description: '특정 이벤트를 조회합니다.', + }) @ApiParam({ name: 'eventId', required: true, @@ -41,6 +61,10 @@ export class EventController { } @Patch(':eventId') + @ApiOperation({ + summary: '이벤트 수정', + description: '특정 이벤트를 수정합니다.', + }) @ApiParam({ name: 'eventId', required: true, @@ -54,7 +78,11 @@ export class EventController { return this.eventService.update(groupId, eventId, updateEventDto); } - @Patch(':eventId') + @Delete(':eventId') + @ApiOperation({ + summary: '이벤트 삭제', + description: '특정 이벤트를 삭제합니다.', + }) @ApiParam({ name: 'eventId', required: true, diff --git a/src/event/event.repository.ts b/src/event/event.repository.ts index 4552573..c4847dd 100644 --- a/src/event/event.repository.ts +++ b/src/event/event.repository.ts @@ -2,6 +2,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { Model } from 'mongoose'; import { Event } from './interfaces/event.interface'; import { CreateEventDto } from './dto/create-event.dto'; +import { UpdateEventDto } from './dto/update-event.dto'; @Injectable() export class EventRepository { @@ -10,19 +11,19 @@ export class EventRepository { private readonly eventModel: Model, ) {} - create(createEventDto: CreateEventDto): Promise { - return this.eventModel.create(createEventDto); + async create(createEventDto: CreateEventDto): Promise { + return await this.eventModel.create(createEventDto); } findAll(): Promise { return this.eventModel.find().exec(); } - findOne(eventId: string): Promise { - return this.eventModel.findById(eventId).exec(); + async findOne(eventId: string): Promise { + return await this.eventModel.findById(eventId).exec(); } - update(eventId: string, updateEventDto: CreateEventDto): Promise { + update(eventId: string, updateEventDto: UpdateEventDto): Promise { return this.eventModel .findByIdAndUpdate(eventId, updateEventDto, { new: true }) .exec(); diff --git a/src/event/event.service.ts b/src/event/event.service.ts index fa42d99..c4dc93a 100644 --- a/src/event/event.service.ts +++ b/src/event/event.service.ts @@ -11,39 +11,54 @@ export class EventService { private readonly groupService: GroupService, ) {} - create(groupId: string, createEventDto: CreateEventDto) { - return { groupId, event: this.eventRepository.create(createEventDto) }; + async create(groupId: string, createEventDto: CreateEventDto) { + const createdEvent = await this.eventRepository.create(createEventDto); + await this.groupService.addEvent(groupId, createdEvent.id); + + return createdEvent; } async findAll(groupId: string) { const group = await this.groupService.findOne(groupId); - return { - groupId, - events: group.events, - }; + + const events = []; + for (const eventId of group.events) { + events.push(await this.eventRepository.findOne(eventId)); + } + + return events; } - findOne(groupId: string, eventId: string) { - const group = this.groupService.findOne(groupId); - const event = this.eventRepository.findOne(eventId); + async findOne(groupId: string, eventId: string) { + const group = await this.groupService.findOne(groupId); + const event = await this.eventRepository.findOne(eventId); + return { - groupId, group, - eventId, event, }; } - update(groupId: string, eventId: string, updateEventDto: UpdateEventDto) { + async update( + groupId: string, + eventId: string, + updateEventDto: UpdateEventDto, + ) { + const group = await this.groupService.findOne(groupId); + const event = await this.eventRepository.findOne(eventId); + + for (const key in updateEventDto) { + event[key] = updateEventDto[key]; + } + await this.eventRepository.update(eventId, event); + return { - groupId, - eventId, - event: this.eventRepository.update(eventId, updateEventDto), + group, + event, }; } - remove(groupId: string, eventId: string) { - const group = this.groupService.findOne(groupId); - return this.eventRepository.delete(eventId); + async remove(groupId: string, eventId: string) { + return await this.groupService.deleteEvent(groupId, eventId); } } From 8fae09c0409e4cd44ff5437581757f38add1fb4b Mon Sep 17 00:00:00 2001 From: w8385 Date: Sun, 21 Apr 2024 23:14:07 +0900 Subject: [PATCH 07/13] =?UTF-8?q?feat:=20excel=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20common/excel=EB=A1=9C=20=EC=9D=B4=EC=A0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/excel/excel.service.ts | 64 +++++++++++++++++++++++++++++ src/group/group.service.ts | 67 ++----------------------------- 2 files changed, 67 insertions(+), 64 deletions(-) create mode 100644 src/common/excel/excel.service.ts diff --git a/src/common/excel/excel.service.ts b/src/common/excel/excel.service.ts new file mode 100644 index 0000000..dfa55a5 --- /dev/null +++ b/src/common/excel/excel.service.ts @@ -0,0 +1,64 @@ +import * as XLSX from 'exceljs'; + +export class ExcelService { + async convertExcelToJSON(groupId: string, excel: Express.Multer.File) { + const workbook = new XLSX.Workbook(); + await workbook.xlsx.load(excel.buffer); + + const worksheet = workbook.getWorksheet(1); + + const columns = []; + worksheet.getRow(1).eachCell((cell) => { + columns.push(cell.value); + }); + + const data = []; + worksheet.eachRow((row, rowNumber) => { + if (rowNumber !== 1) { + const rowObject = {}; + row.eachCell((cell, colNumber) => { + const col = columns[colNumber - 1]; + rowObject[col] = cell.value; + }); + data.push(rowObject); + } + }); + + return { + groupId, + data, + }; + } + + async convertMemberExcelToJSON(excel: Express.Multer.File) { + const workbook = new XLSX.Workbook(); + await workbook.xlsx.load(excel.buffer); + + const worksheet = workbook.getWorksheet(1); + + const columns = []; + worksheet.getRow(1).eachCell((cell) => { + columns.push(cell.value); + }); + + const data = []; + worksheet.eachRow((row, rowNumber) => { + if (rowNumber !== 1) { + const rowObject = {}; + const memberInfo = {}; + row.eachCell((cell, colNumber) => { + const col = columns[colNumber - 1]; + if (col == 'name' || col == '이름') { + rowObject['name'] = String(cell.value).trim(); + } else { + memberInfo[col] = String(cell.value).trim(); + } + }); + rowObject['memberInfo'] = memberInfo; + data.push(rowObject); + } + }); + + return data; + } +} diff --git a/src/group/group.service.ts b/src/group/group.service.ts index ebb1b6e..9583730 100644 --- a/src/group/group.service.ts +++ b/src/group/group.service.ts @@ -1,9 +1,9 @@ import { Injectable } from '@nestjs/common'; -import { GroupRepository } from './group.repository'; + import { CreateGroupDto } from './dto/create-group.dto'; -import { Group } from './entities/group.entity'; import { UpdateGroupDto } from './dto/update-group.dto'; -import * as XLSX from 'exceljs'; +import { Group } from './entities/group.entity'; +import { GroupRepository } from './group.repository'; @Injectable() export class GroupService { @@ -74,65 +74,4 @@ export class GroupService { async deleteAll(): Promise { return this.groupRepository.deleteAll(); } - - async convertExcelToJSON(groupId: string, excel: Express.Multer.File) { - const workbook = new XLSX.Workbook(); - await workbook.xlsx.load(excel.buffer); - - const worksheet = workbook.getWorksheet(1); - - const columns = []; - worksheet.getRow(1).eachCell((cell) => { - columns.push(cell.value); - }); - - const data = []; - worksheet.eachRow((row, rowNumber) => { - if (rowNumber !== 1) { - const rowObject = {}; - row.eachCell((cell, colNumber) => { - const col = columns[colNumber - 1]; - rowObject[col] = cell.value; - }); - data.push(rowObject); - } - }); - - return { - groupId, - data, - }; - } - - async convertMemberExcelToJSON(excel: Express.Multer.File) { - const workbook = new XLSX.Workbook(); - await workbook.xlsx.load(excel.buffer); - - const worksheet = workbook.getWorksheet(1); - - const columns = []; - worksheet.getRow(1).eachCell((cell) => { - columns.push(cell.value); - }); - - const data = []; - worksheet.eachRow((row, rowNumber) => { - if (rowNumber !== 1) { - const rowObject = {}; - const memberInfo = {}; - row.eachCell((cell, colNumber) => { - const col = columns[colNumber - 1]; - if (col == 'name' || col == '이름') { - rowObject['name'] = String(cell.value).trim(); - } else { - memberInfo[col] = String(cell.value).trim(); - } - }); - rowObject['memberInfo'] = memberInfo; - data.push(rowObject); - } - }); - - return data; - } } From 19d0c7955d4a4e4fc44c532ba786420bcae8e78d Mon Sep 17 00:00:00 2001 From: w8385 Date: Sun, 21 Apr 2024 23:38:33 +0900 Subject: [PATCH 08/13] lint: format @trivago/prettier-plugin-sort-imports --- .github/workflows/eslint.yml | 2 +- .prettierrc | 16 +++++++++++++++- src/api-file.decorator.ts | 4 ++-- src/app.module.ts | 9 +++++---- src/auth/auth.module.ts | 3 ++- src/database/database.module.ts | 1 + src/database/database.providers.ts | 2 +- src/event/dto/update-event.dto.ts | 1 + src/event/event.controller.ts | 5 +++-- src/event/event.module.ts | 9 +++++---- src/event/event.providers.ts | 1 + src/event/event.repository.ts | 3 ++- src/event/event.service.ts | 3 ++- src/group/group.controller.spec.ts | 13 +++++++------ src/group/group.controller.ts | 27 ++++----------------------- src/group/group.module.ts | 5 +++-- src/group/group.provider.ts | 1 + src/group/group.repository.ts | 3 ++- src/main.ts | 5 +++-- src/member/dto/update-member.dto.ts | 1 + src/member/member.controller.spec.ts | 11 ++++++----- src/member/member.controller.ts | 9 +++++---- src/member/member.module.ts | 10 ++++++---- src/member/member.provider.ts | 1 + src/member/member.repository.ts | 3 ++- src/member/member.service.ts | 13 ++++++++----- src/user/dto/update-user.dto.ts | 1 + src/user/user.controller.ts | 5 +++-- src/user/user.module.ts | 3 ++- src/user/user.service.ts | 1 + test/app.e2e-spec.ts | 3 ++- 31 files changed, 99 insertions(+), 75 deletions(-) diff --git a/.github/workflows/eslint.yml b/.github/workflows/eslint.yml index c4a9239..a094a94 100644 --- a/.github/workflows/eslint.yml +++ b/.github/workflows/eslint.yml @@ -37,7 +37,7 @@ jobs: - name: Run ESLint run: npx eslint . - --config .eslintrc.js + --config .eslintrc --ext .js,.jsx,.ts,.tsx --format @microsoft/eslint-formatter-sarif --output-file eslint-results.sarif diff --git a/.prettierrc b/.prettierrc index 743afce..75beb3f 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,8 +1,22 @@ { "printWidth": 80, + "tabWidth": 2, "trailingComma": "all", "singleQuote": true, "semi": true, + "plugins": [ + "@trivago/prettier-plugin-sort-imports" + ], + "importOrderParserPlugins": [ + "typescript", + "decorators-legacy" + ], + "importOrder": [ + "^@core/(.*)$", + "^@server/(.*)$", + "^@ui/(.*)$", + "^[./]" + ], "importOrderSeparation": true, "importOrderSortSpecifiers": true -} \ No newline at end of file +} diff --git a/src/api-file.decorator.ts b/src/api-file.decorator.ts index 5ef8c87..dd4ac66 100644 --- a/src/api-file.decorator.ts +++ b/src/api-file.decorator.ts @@ -1,6 +1,6 @@ -import { ApiBody, ApiConsumes } from '@nestjs/swagger'; +import { UseInterceptors, applyDecorators } from '@nestjs/common'; import { FileInterceptor } from '@nestjs/platform-express'; -import { applyDecorators, UseInterceptors } from '@nestjs/common'; +import { ApiBody, ApiConsumes } from '@nestjs/swagger'; export function ApiFile(fieldName: string = 'file') { return applyDecorators( diff --git a/src/app.module.ts b/src/app.module.ts index c670f4c..e5c7b8c 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,10 +1,11 @@ import { Module } from '@nestjs/common'; -import { UserModule } from './user/user.module'; -import { GroupModule } from './group/group.module'; -import { AuthModule } from './auth/auth.module'; -import { MemberModule } from './member/member.module'; import { ConfigModule } from '@nestjs/config'; + +import { AuthModule } from './auth/auth.module'; import { EventModule } from './event/event.module'; +import { GroupModule } from './group/group.module'; +import { MemberModule } from './member/member.module'; +import { UserModule } from './user/user.module'; @Module({ imports: [ diff --git a/src/auth/auth.module.ts b/src/auth/auth.module.ts index 46e183a..0b99e8e 100644 --- a/src/auth/auth.module.ts +++ b/src/auth/auth.module.ts @@ -1,6 +1,7 @@ import { Module } from '@nestjs/common'; -import { AuthService } from './auth.service'; + import { AuthController } from './auth.controller'; +import { AuthService } from './auth.service'; @Module({ controllers: [AuthController], diff --git a/src/database/database.module.ts b/src/database/database.module.ts index 857bc80..8211a38 100644 --- a/src/database/database.module.ts +++ b/src/database/database.module.ts @@ -1,4 +1,5 @@ import { Module } from '@nestjs/common'; + import { databaseProviders } from './database.providers'; @Module({ diff --git a/src/database/database.providers.ts b/src/database/database.providers.ts index 2111b88..a2d82cd 100644 --- a/src/database/database.providers.ts +++ b/src/database/database.providers.ts @@ -1,5 +1,5 @@ -import * as mongoose from 'mongoose'; import { ConfigService } from '@nestjs/config'; +import * as mongoose from 'mongoose'; export const databaseProviders = [ { diff --git a/src/event/dto/update-event.dto.ts b/src/event/dto/update-event.dto.ts index f161e01..c26d0b1 100644 --- a/src/event/dto/update-event.dto.ts +++ b/src/event/dto/update-event.dto.ts @@ -1,4 +1,5 @@ import { PartialType } from '@nestjs/swagger'; + import { CreateEventDto } from './create-event.dto'; export class UpdateEventDto extends PartialType(CreateEventDto) {} diff --git a/src/event/event.controller.ts b/src/event/event.controller.ts index 6c0b3cd..59294b8 100644 --- a/src/event/event.controller.ts +++ b/src/event/event.controller.ts @@ -7,10 +7,11 @@ import { Patch, Post, } from '@nestjs/common'; -import { EventService } from './event.service'; +import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger'; + import { CreateEventDto } from './dto/create-event.dto'; import { UpdateEventDto } from './dto/update-event.dto'; -import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger'; +import { EventService } from './event.service'; @ApiTags('Event') @Controller('group/:groupId/event') diff --git a/src/event/event.module.ts b/src/event/event.module.ts index 168dab0..e15569d 100644 --- a/src/event/event.module.ts +++ b/src/event/event.module.ts @@ -1,10 +1,11 @@ import { Module } from '@nestjs/common'; -import { EventService } from './event.service'; -import { EventController } from './event.controller'; + import { DatabaseModule } from '../database/database.module'; -import { EventRepository } from './event.repository'; -import { eventProviders } from './event.providers'; import { GroupModule } from '../group/group.module'; +import { EventController } from './event.controller'; +import { eventProviders } from './event.providers'; +import { EventRepository } from './event.repository'; +import { EventService } from './event.service'; @Module({ imports: [DatabaseModule, GroupModule], diff --git a/src/event/event.providers.ts b/src/event/event.providers.ts index 255d467..201b57a 100644 --- a/src/event/event.providers.ts +++ b/src/event/event.providers.ts @@ -1,4 +1,5 @@ import { Connection } from 'mongoose'; + import { EventSchema } from './schemas/event.schema'; export const eventProviders = [ diff --git a/src/event/event.repository.ts b/src/event/event.repository.ts index c4847dd..06f2640 100644 --- a/src/event/event.repository.ts +++ b/src/event/event.repository.ts @@ -1,8 +1,9 @@ import { Inject, Injectable } from '@nestjs/common'; import { Model } from 'mongoose'; -import { Event } from './interfaces/event.interface'; + import { CreateEventDto } from './dto/create-event.dto'; import { UpdateEventDto } from './dto/update-event.dto'; +import { Event } from './interfaces/event.interface'; @Injectable() export class EventRepository { diff --git a/src/event/event.service.ts b/src/event/event.service.ts index c4dc93a..4c8fc07 100644 --- a/src/event/event.service.ts +++ b/src/event/event.service.ts @@ -1,8 +1,9 @@ import { Injectable } from '@nestjs/common'; + +import { GroupService } from '../group/group.service'; import { CreateEventDto } from './dto/create-event.dto'; import { UpdateEventDto } from './dto/update-event.dto'; import { EventRepository } from './event.repository'; -import { GroupService } from '../group/group.service'; @Injectable() export class EventService { diff --git a/src/group/group.controller.spec.ts b/src/group/group.controller.spec.ts index 6a46ba4..e75ebed 100644 --- a/src/group/group.controller.spec.ts +++ b/src/group/group.controller.spec.ts @@ -1,14 +1,15 @@ -import { GroupController } from './group.controller'; -import { GroupService } from './group.service'; import { Test, TestingModule } from '@nestjs/testing'; -import { DatabaseModule } from '../database/database.module'; -import { groupProvider } from './group.provider'; import { MongoMemoryServer } from 'mongodb-memory-server'; -import * as process from 'process'; -import { Group } from './entities/group.entity'; import mongoose from 'mongoose'; +import * as process from 'process'; + +import { DatabaseModule } from '../database/database.module'; import { CreateGroupDto } from './dto/create-group.dto'; +import { Group } from './entities/group.entity'; +import { GroupController } from './group.controller'; +import { groupProvider } from './group.provider'; import { GroupRepository } from './group.repository'; +import { GroupService } from './group.service'; describe('GroupController', () => { let groupController: GroupController; diff --git a/src/group/group.controller.ts b/src/group/group.controller.ts index 535b8f0..3899f92 100644 --- a/src/group/group.controller.ts +++ b/src/group/group.controller.ts @@ -6,15 +6,14 @@ import { Param, Patch, Post, - UploadedFile, UseFilters, } from '@nestjs/common'; -import { GroupService } from './group.service'; -import { CreateGroupDto } from './dto/create-group.dto'; -import { UpdateGroupDto } from './dto/update-group.dto'; import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger'; + import { HttpExceptionFilter } from '../http-exception.filter'; -import { ApiFile } from '../api-file.decorator'; +import { CreateGroupDto } from './dto/create-group.dto'; +import { UpdateGroupDto } from './dto/update-group.dto'; +import { GroupService } from './group.service'; @ApiTags('Group') @Controller('group') @@ -93,22 +92,4 @@ export class GroupController { delete(@Param('groupId') groupId: string) { return this.groupService.delete(groupId); } - - @Post(':groupId/member/excel') - @ApiParam({ - name: 'groupId', - required: true, - description: '모임 ID', - }) - @ApiOperation({ - summary: '모임 회원 엑셀 파일 업로드', - description: '모임 회원 엑셀 파일을 업로드합니다.', - }) - @ApiFile('excel') - async uploadMemberFile( - @Param('groupId') groupId: string, - @UploadedFile() excel: Express.Multer.File, - ) { - return await this.groupService.convertExcelToJSON(groupId, excel); - } } diff --git a/src/group/group.module.ts b/src/group/group.module.ts index 1363d92..6589077 100644 --- a/src/group/group.module.ts +++ b/src/group/group.module.ts @@ -1,9 +1,10 @@ import { Module } from '@nestjs/common'; -import { GroupService } from './group.service'; + +import { DatabaseModule } from '../database/database.module'; import { GroupController } from './group.controller'; import { groupProvider } from './group.provider'; -import { DatabaseModule } from '../database/database.module'; import { GroupRepository } from './group.repository'; +import { GroupService } from './group.service'; @Module({ imports: [DatabaseModule], diff --git a/src/group/group.provider.ts b/src/group/group.provider.ts index c6093d0..33a4e2f 100644 --- a/src/group/group.provider.ts +++ b/src/group/group.provider.ts @@ -1,4 +1,5 @@ import { Connection } from 'mongoose'; + import { GroupSchema } from './schemas/group.schema'; export const groupProvider = [ diff --git a/src/group/group.repository.ts b/src/group/group.repository.ts index 2229422..c731e96 100644 --- a/src/group/group.repository.ts +++ b/src/group/group.repository.ts @@ -1,8 +1,9 @@ import { Inject, Injectable } from '@nestjs/common'; import { Model } from 'mongoose'; -import { Group } from './interfaces/group.interface'; + import { CreateGroupDto } from './dto/create-group.dto'; import { UpdateGroupDto } from './dto/update-group.dto'; +import { Group } from './interfaces/group.interface'; @Injectable() export class GroupRepository { diff --git a/src/main.ts b/src/main.ts index 2a46ca4..9c3141c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,9 @@ +import { ValidationPipe } from '@nestjs/common'; import { NestFactory } from '@nestjs/core'; +import * as process from 'process'; + import { AppModule } from './app.module'; import { configSwagger } from './config.swagger'; -import * as process from 'process'; -import { ValidationPipe } from '@nestjs/common'; async function bootstrap() { const app = await NestFactory.create(AppModule); diff --git a/src/member/dto/update-member.dto.ts b/src/member/dto/update-member.dto.ts index 7a0a493..75b6f9d 100644 --- a/src/member/dto/update-member.dto.ts +++ b/src/member/dto/update-member.dto.ts @@ -1,4 +1,5 @@ import { ApiProperty, PartialType } from '@nestjs/swagger'; + import { CreateMemberDto } from './create-member.dto'; export class UpdateMemberDto extends PartialType(CreateMemberDto) { diff --git a/src/member/member.controller.spec.ts b/src/member/member.controller.spec.ts index 6defd3b..ed3101a 100644 --- a/src/member/member.controller.spec.ts +++ b/src/member/member.controller.spec.ts @@ -1,13 +1,14 @@ -import { MemberController } from './member.controller'; -import { MemberService } from './member.service'; -import mongoose from 'mongoose'; import { Test } from '@nestjs/testing'; -import { DatabaseModule } from '../database/database.module'; import { MongoMemoryServer } from 'mongodb-memory-server'; +import mongoose from 'mongoose'; import * as process from 'process'; + +import { DatabaseModule } from '../database/database.module'; +import { GroupModule } from '../group/group.module'; +import { MemberController } from './member.controller'; import { memberProvider } from './member.provider'; import { MemberRepository } from './member.repository'; -import { GroupModule } from '../group/group.module'; +import { MemberService } from './member.service'; describe('MemberController', () => { // let memberController: MemberController; diff --git a/src/member/member.controller.ts b/src/member/member.controller.ts index f366ac6..65e304a 100644 --- a/src/member/member.controller.ts +++ b/src/member/member.controller.ts @@ -9,12 +9,13 @@ import { UploadedFile, UseFilters, } from '@nestjs/common'; -import { MemberService } from './member.service'; -import { CreateMemberDto } from './dto/create-member.dto'; -import { UpdateMemberDto } from './dto/update-member.dto'; import { ApiBody, ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger'; -import { HttpExceptionFilter } from '../http-exception.filter'; + import { ApiFile } from '../api-file.decorator'; +import { HttpExceptionFilter } from '../http-exception.filter'; +import { CreateMemberDto } from './dto/create-member.dto'; +import { UpdateMemberDto } from './dto/update-member.dto'; +import { MemberService } from './member.service'; @UseFilters(HttpExceptionFilter) @ApiTags('Member') diff --git a/src/member/member.module.ts b/src/member/member.module.ts index bed589c..e581caf 100644 --- a/src/member/member.module.ts +++ b/src/member/member.module.ts @@ -1,14 +1,16 @@ import { Module } from '@nestjs/common'; -import { MemberService } from './member.service'; -import { MemberController } from './member.controller'; + +import { ExcelService } from '../common/excel/excel.service'; import { DatabaseModule } from '../database/database.module'; +import { GroupModule } from '../group/group.module'; +import { MemberController } from './member.controller'; import { memberProvider } from './member.provider'; import { MemberRepository } from './member.repository'; -import { GroupModule } from '../group/group.module'; +import { MemberService } from './member.service'; @Module({ imports: [DatabaseModule, GroupModule], controllers: [MemberController], - providers: [MemberService, ...memberProvider, MemberRepository], + providers: [MemberService, ...memberProvider, MemberRepository, ExcelService], }) export class MemberModule {} diff --git a/src/member/member.provider.ts b/src/member/member.provider.ts index 6c18893..3a266b7 100644 --- a/src/member/member.provider.ts +++ b/src/member/member.provider.ts @@ -1,4 +1,5 @@ import { Connection } from 'mongoose'; + import { MemberSchema } from './schemas/member.schema'; export const memberProvider = [ diff --git a/src/member/member.repository.ts b/src/member/member.repository.ts index 8649141..0807985 100644 --- a/src/member/member.repository.ts +++ b/src/member/member.repository.ts @@ -1,8 +1,9 @@ import { Inject, Injectable } from '@nestjs/common'; -import { Member } from './interfaces/member.interface'; import { Model } from 'mongoose'; + import { CreateMemberDto } from './dto/create-member.dto'; import { UpdateMemberDto } from './dto/update-member.dto'; +import { Member } from './interfaces/member.interface'; @Injectable() export class MemberRepository { diff --git a/src/member/member.service.ts b/src/member/member.service.ts index b4a7ab8..9c50388 100644 --- a/src/member/member.service.ts +++ b/src/member/member.service.ts @@ -1,16 +1,19 @@ import { Injectable, NotFoundException } from '@nestjs/common'; -import { MemberRepository } from './member.repository'; -import { Member } from './entities/member.entity'; +import mongoose from 'mongoose'; + +import { ExcelService } from '../common/excel/excel.service'; +import { GroupService } from '../group/group.service'; import { CreateMemberDto } from './dto/create-member.dto'; import { UpdateMemberDto } from './dto/update-member.dto'; -import { GroupService } from '../group/group.service'; -import mongoose from 'mongoose'; +import { Member } from './entities/member.entity'; +import { MemberRepository } from './member.repository'; @Injectable() export class MemberService { constructor( private readonly memberRepository: MemberRepository, private readonly groupService: GroupService, + private readonly excelService: ExcelService, ) {} async create( @@ -107,7 +110,7 @@ export class MemberService { excel: Express.Multer.File, ): Promise { const members: Member[] = - await this.groupService.convertMemberExcelToJSON(excel); + await this.excelService.convertMemberExcelToJSON(excel); //멤버 삭제 await this.deleteAllGroupMembers(groupId); //group에 멤버 추가 diff --git a/src/user/dto/update-user.dto.ts b/src/user/dto/update-user.dto.ts index 78ab602..e1cec90 100644 --- a/src/user/dto/update-user.dto.ts +++ b/src/user/dto/update-user.dto.ts @@ -1,4 +1,5 @@ import { PartialType } from '@nestjs/swagger'; + import { CreateUserDto } from './create-user.dto'; export class UpdateUserDto extends PartialType(CreateUserDto) {} diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts index ffad450..f975628 100644 --- a/src/user/user.controller.ts +++ b/src/user/user.controller.ts @@ -7,10 +7,11 @@ import { Patch, Post, } from '@nestjs/common'; -import { UserService } from './user.service'; +import { ApiTags } from '@nestjs/swagger'; + import { CreateUserDto } from './dto/create-user.dto'; import { UpdateUserDto } from './dto/update-user.dto'; -import { ApiTags } from '@nestjs/swagger'; +import { UserService } from './user.service'; @ApiTags('User') @Controller('user') diff --git a/src/user/user.module.ts b/src/user/user.module.ts index e21d51f..c59c53a 100644 --- a/src/user/user.module.ts +++ b/src/user/user.module.ts @@ -1,6 +1,7 @@ import { Module } from '@nestjs/common'; -import { UserService } from './user.service'; + import { UserController } from './user.controller'; +import { UserService } from './user.service'; @Module({ controllers: [UserController], diff --git a/src/user/user.service.ts b/src/user/user.service.ts index 23b2ef6..af873a0 100644 --- a/src/user/user.service.ts +++ b/src/user/user.service.ts @@ -1,4 +1,5 @@ import { Injectable } from '@nestjs/common'; + import { CreateUserDto } from './dto/create-user.dto'; import { UpdateUserDto } from './dto/update-user.dto'; diff --git a/test/app.e2e-spec.ts b/test/app.e2e-spec.ts index 50cda62..4d7057c 100644 --- a/test/app.e2e-spec.ts +++ b/test/app.e2e-spec.ts @@ -1,6 +1,7 @@ -import { Test, TestingModule } from '@nestjs/testing'; import { INestApplication } from '@nestjs/common'; +import { Test, TestingModule } from '@nestjs/testing'; import * as request from 'supertest'; + import { AppModule } from './../src/app.module'; describe('AppController (e2e)', () => { From 9ad1221d20672f20d7f31971467c088a35185f23 Mon Sep 17 00:00:00 2001 From: w8385 Date: Sun, 21 Apr 2024 23:44:53 +0900 Subject: [PATCH 09/13] =?UTF-8?q?refactor:=20/common=20/excel=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{config.swagger.ts => common/configs/swagger.config.ts} | 2 +- src/{ => common/decorators}/api-file.decorator.ts | 0 src/{ => common/filters}/http-exception.filter.ts | 0 src/{common => }/excel/excel.service.ts | 0 src/group/group.controller.ts | 2 +- src/main.ts | 4 ++-- src/member/member.controller.ts | 4 ++-- src/member/member.module.ts | 2 +- src/member/member.service.ts | 2 +- test/app.e2e-spec.ts | 2 +- 10 files changed, 9 insertions(+), 9 deletions(-) rename src/{config.swagger.ts => common/configs/swagger.config.ts} (89%) rename src/{ => common/decorators}/api-file.decorator.ts (100%) rename src/{ => common/filters}/http-exception.filter.ts (100%) rename src/{common => }/excel/excel.service.ts (100%) diff --git a/src/config.swagger.ts b/src/common/configs/swagger.config.ts similarity index 89% rename from src/config.swagger.ts rename to src/common/configs/swagger.config.ts index 23b9ac6..3262b13 100644 --- a/src/config.swagger.ts +++ b/src/common/configs/swagger.config.ts @@ -1,7 +1,7 @@ import { INestApplication } from '@nestjs/common'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; -export const configSwagger = (app: INestApplication) => { +export const swaggerConfig = (app: INestApplication) => { const config = new DocumentBuilder() .setTitle('sometime API') .addTag('Group', '모임 관련 API') diff --git a/src/api-file.decorator.ts b/src/common/decorators/api-file.decorator.ts similarity index 100% rename from src/api-file.decorator.ts rename to src/common/decorators/api-file.decorator.ts diff --git a/src/http-exception.filter.ts b/src/common/filters/http-exception.filter.ts similarity index 100% rename from src/http-exception.filter.ts rename to src/common/filters/http-exception.filter.ts diff --git a/src/common/excel/excel.service.ts b/src/excel/excel.service.ts similarity index 100% rename from src/common/excel/excel.service.ts rename to src/excel/excel.service.ts diff --git a/src/group/group.controller.ts b/src/group/group.controller.ts index 3899f92..c52e5b2 100644 --- a/src/group/group.controller.ts +++ b/src/group/group.controller.ts @@ -10,7 +10,7 @@ import { } from '@nestjs/common'; import { ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger'; -import { HttpExceptionFilter } from '../http-exception.filter'; +import { HttpExceptionFilter } from '../common/filters/http-exception.filter'; import { CreateGroupDto } from './dto/create-group.dto'; import { UpdateGroupDto } from './dto/update-group.dto'; import { GroupService } from './group.service'; diff --git a/src/main.ts b/src/main.ts index 9c3141c..5f4bc5b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,11 +3,11 @@ import { NestFactory } from '@nestjs/core'; import * as process from 'process'; import { AppModule } from './app.module'; -import { configSwagger } from './config.swagger'; +import { swaggerConfig } from './common/configs/swagger.config'; async function bootstrap() { const app = await NestFactory.create(AppModule); - configSwagger(app); + swaggerConfig(app); app.useGlobalPipes(new ValidationPipe()); app.enableCors(); await app.listen(process.env.SERVER_PORT); diff --git a/src/member/member.controller.ts b/src/member/member.controller.ts index 65e304a..30ea9fb 100644 --- a/src/member/member.controller.ts +++ b/src/member/member.controller.ts @@ -11,8 +11,8 @@ import { } from '@nestjs/common'; import { ApiBody, ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger'; -import { ApiFile } from '../api-file.decorator'; -import { HttpExceptionFilter } from '../http-exception.filter'; +import { ApiFile } from '../common/decorators/api-file.decorator'; +import { HttpExceptionFilter } from '../common/filters/http-exception.filter'; import { CreateMemberDto } from './dto/create-member.dto'; import { UpdateMemberDto } from './dto/update-member.dto'; import { MemberService } from './member.service'; diff --git a/src/member/member.module.ts b/src/member/member.module.ts index e581caf..1abc293 100644 --- a/src/member/member.module.ts +++ b/src/member/member.module.ts @@ -1,7 +1,7 @@ import { Module } from '@nestjs/common'; -import { ExcelService } from '../common/excel/excel.service'; import { DatabaseModule } from '../database/database.module'; +import { ExcelService } from '../excel/excel.service'; import { GroupModule } from '../group/group.module'; import { MemberController } from './member.controller'; import { memberProvider } from './member.provider'; diff --git a/src/member/member.service.ts b/src/member/member.service.ts index 9c50388..93da30e 100644 --- a/src/member/member.service.ts +++ b/src/member/member.service.ts @@ -1,7 +1,7 @@ import { Injectable, NotFoundException } from '@nestjs/common'; import mongoose from 'mongoose'; -import { ExcelService } from '../common/excel/excel.service'; +import { ExcelService } from '../excel/excel.service'; import { GroupService } from '../group/group.service'; import { CreateMemberDto } from './dto/create-member.dto'; import { UpdateMemberDto } from './dto/update-member.dto'; diff --git a/test/app.e2e-spec.ts b/test/app.e2e-spec.ts index 4d7057c..22e885e 100644 --- a/test/app.e2e-spec.ts +++ b/test/app.e2e-spec.ts @@ -2,7 +2,7 @@ import { INestApplication } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import * as request from 'supertest'; -import { AppModule } from './../src/app.module'; +import { AppModule } from '../src/app.module'; describe('AppController (e2e)', () => { let app: INestApplication; From c980aa122ad273229f1b264406ccf873debceef2 Mon Sep 17 00:00:00 2001 From: w8385 Date: Sun, 21 Apr 2024 23:50:20 +0900 Subject: [PATCH 10/13] fix: eventService Update --- src/event/event.repository.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/event/event.repository.ts b/src/event/event.repository.ts index 06f2640..298a672 100644 --- a/src/event/event.repository.ts +++ b/src/event/event.repository.ts @@ -2,7 +2,6 @@ import { Inject, Injectable } from '@nestjs/common'; import { Model } from 'mongoose'; import { CreateEventDto } from './dto/create-event.dto'; -import { UpdateEventDto } from './dto/update-event.dto'; import { Event } from './interfaces/event.interface'; @Injectable() @@ -24,9 +23,9 @@ export class EventRepository { return await this.eventModel.findById(eventId).exec(); } - update(eventId: string, updateEventDto: UpdateEventDto): Promise { + update(eventId: string, event: Event): Promise { return this.eventModel - .findByIdAndUpdate(eventId, updateEventDto, { new: true }) + .findByIdAndUpdate(eventId, event, { new: true }) .exec(); } From ee792f4c984e511799e4b60f13855eef248623db Mon Sep 17 00:00:00 2001 From: w8385 Date: Mon, 22 Apr 2024 00:04:58 +0900 Subject: [PATCH 11/13] fix: member.controller.spec.ts module dependency --- src/member/member.controller.spec.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/member/member.controller.spec.ts b/src/member/member.controller.spec.ts index ed3101a..f44ded1 100644 --- a/src/member/member.controller.spec.ts +++ b/src/member/member.controller.spec.ts @@ -4,6 +4,7 @@ import mongoose from 'mongoose'; import * as process from 'process'; import { DatabaseModule } from '../database/database.module'; +import { ExcelService } from '../excel/excel.service'; import { GroupModule } from '../group/group.module'; import { MemberController } from './member.controller'; import { memberProvider } from './member.provider'; @@ -22,7 +23,12 @@ describe('MemberController', () => { await Test.createTestingModule({ imports: [DatabaseModule, GroupModule], controllers: [MemberController], - providers: [MemberService, ...memberProvider, MemberRepository], + providers: [ + MemberService, + ...memberProvider, + MemberRepository, + ExcelService, + ], }).compile(); // memberService = module.get(MemberService); From fbeebf41eb01e04050d4158fbb9583f008bb82c5 Mon Sep 17 00:00:00 2001 From: w8385 Date: Mon, 22 Apr 2024 00:06:01 +0900 Subject: [PATCH 12/13] fix: eslint.yml --- .github/workflows/eslint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/eslint.yml b/.github/workflows/eslint.yml index a094a94..fd35ef9 100644 --- a/.github/workflows/eslint.yml +++ b/.github/workflows/eslint.yml @@ -37,14 +37,14 @@ jobs: - name: Run ESLint run: npx eslint . - --config .eslintrc + --config .eslintrc.js --ext .js,.jsx,.ts,.tsx --format @microsoft/eslint-formatter-sarif --output-file eslint-results.sarif continue-on-error: true - name: Upload analysis results to GitHub - uses: github/codeql-action/upload-sarif@v2 + uses: github/codeql-action/upload-sarif@v3 with: sarif_file: eslint-results.sarif wait-for-processing: true From 1346fe323f14391c44bc77fe8cb641fdc75c6435 Mon Sep 17 00:00:00 2001 From: w8385 Date: Mon, 22 Apr 2024 00:22:14 +0900 Subject: [PATCH 13/13] =?UTF-8?q?feat:=20member/excel=20=EC=97=94=EB=93=9C?= =?UTF-8?q?=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/member/member.controller.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/member/member.controller.ts b/src/member/member.controller.ts index 30ea9fb..410beba 100644 --- a/src/member/member.controller.ts +++ b/src/member/member.controller.ts @@ -53,6 +53,19 @@ export class MemberController { return this.memberService.createGroupMembers(groupId, createMemberDto); } + @Post('/excel') + @ApiOperation({ + summary: '모임 회원 명단 업로드', + description: '모임 회원 명단을 재구성합니다.', + }) + @ApiFile('excel') + uploadMemberFIle( + @Param('groupId') groupId: string, + @UploadedFile() excel: Express.Multer.File, + ) { + return this.memberService.uploadMemberFile(groupId, excel); + } + @Get() @ApiOperation({ summary: '모임 모든 회원 조회', @@ -142,17 +155,4 @@ export class MemberController { deleteAllGroupMembers(@Param('groupId') groupId: string) { return this.memberService.deleteAllGroupMembers(groupId); } - - @Post('/upload/excel') - @ApiOperation({ - summary: '회원 명단 업로드', - description: '회원 명단을 재구성합니다.', - }) - @ApiFile('excel') - async uploadMemberFIle( - @Param('groupId') groupId: string, - @UploadedFile() excel: Express.Multer.File, - ) { - return await this.memberService.uploadMemberFile(groupId, excel); - } }