Skip to content

Commit

Permalink
Merge pull request #171 from boostcampwm2023/feature-be-#15
Browse files Browse the repository at this point in the history
[BE] feat#15 ์‚ฌ์šฉ์ž ์ƒํƒœ๋ฅผ ์ƒˆ๋กญ๊ฒŒ ๋งŒ๋“ ๋‹ค
  • Loading branch information
flydog98 authored Nov 29, 2023
2 parents 22dfb05 + b7f87bf commit e49e1c7
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/backend/src/quiz-wizard/comparers/test.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ export async function getTreeHead(
);

return stdoutData;
}
}
18 changes: 18 additions & 0 deletions packages/backend/src/session/session.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { SessionController } from './session.controller';

describe('SessionController', () => {
let controller: SessionController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [SessionController],
}).compile();

controller = module.get<SessionController>(SessionController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
29 changes: 29 additions & 0 deletions packages/backend/src/session/session.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Controller, Delete, Res, UseGuards } from '@nestjs/common';
import { SessionService } from './session.service';
import { SessionGuard } from './session.guard';
import { SessionId } from './session.decorator';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { Response } from 'express';

@ApiTags('session')
@Controller('api/v1/session')
export class SessionController {
constructor(private readonly sessionService: SessionService) {}

@Delete()
@UseGuards(SessionGuard)
@ApiOperation({ summary: '์„ธ์…˜์„ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.' })
@ApiResponse({
status: 200,
description: '์„ธ์…˜์„ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.',
})
async deleteSession(
@SessionId() sessionId: string,
@Res() response: Response,
) {
response.clearCookie('sessionId');
this.sessionService.deleteSession(sessionId);
response.end();
return;
}
}
2 changes: 2 additions & 0 deletions packages/backend/src/session/session.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SessionService } from './session.service';
import { MongooseModule } from '@nestjs/mongoose';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { Session, SessionSchema } from './schema/session.schema';
import { SessionController } from './session.controller';

@Module({
imports: [
Expand All @@ -17,5 +18,6 @@ import { Session, SessionSchema } from './schema/session.schema';
],
providers: [SessionService],
exports: [SessionService],
controllers: [SessionController],
})
export class SessionModule {}
8 changes: 8 additions & 0 deletions packages/backend/src/session/session.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,12 @@ export class SessionService {
private async getSessionById(id: string): Promise<Session> {
return await this.sessionModel.findById(id);
}

async deleteSession(sessionId: string): Promise<void> {
//soft delete
const session = await this.getSessionById(sessionId);
session.deletedAt = new Date();
session.save();
this.logger.log('info', `session ${session._id as ObjectId} deleted`);
}
}

0 comments on commit e49e1c7

Please sign in to comment.