Skip to content

Commit 829adc3

Browse files
Merge pull request #360 from boostcampwm-2024/refactor-be-#357
백엔드 로직 리팩토링
2 parents 3322052 + 3649a90 commit 829adc3

18 files changed

+304
-233
lines changed

apps/backend/src/app.module.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ import { RedLockModule } from './red-lock/red-lock.module';
2727
@Module({
2828
imports: [
2929
ScheduleModule.forRoot(),
30-
ServeStaticModule.forRoot({
31-
rootPath: path.join(__dirname, '..', '..', 'frontend', 'dist'),
32-
}),
3330
ConfigModule.forRoot({
3431
isGlobal: true,
3532
envFilePath: path.join(__dirname, '..', '.env'), // * nest 디렉터리 기준
@@ -38,18 +35,15 @@ import { RedLockModule } from './red-lock/red-lock.module';
3835
imports: [ConfigModule],
3936
inject: [ConfigService],
4037
useFactory: (configService: ConfigService) => ({
41-
42-
// type: 'sqlite',
43-
// database: 'db.sqlite',
4438
type: 'postgres',
4539
host: configService.get('DB_HOST'),
4640
port: configService.get('DB_PORT'),
4741
username: configService.get('DB_USER'),
4842
password: configService.get('DB_PASSWORD'),
4943
database: configService.get('DB_NAME'),
5044
entities: [Node, Page, Edge, User, Workspace, Role],
51-
logging: true,
52-
synchronize: true,
45+
logging: process.env.NODE_ENV === 'development',
46+
synchronize: process.env.NODE_ENV === 'development',
5347
}),
5448
}),
5549
NodeModule,

apps/backend/src/auth/strategies/kakao.strategy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class KakaoStrategy extends PassportStrategy(Strategy, 'kakao') {
2222
provider: 'kakao',
2323
email: profile._json.kakao_account.email,
2424
};
25+
2526
let user = await this.authService.findUser(createUserDto);
2627
if (!user) {
2728
user = await this.authService.signUp(createUserDto);

apps/backend/src/auth/strategies/naver.strategy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class NaverStrategy extends PassportStrategy(Strategy, 'naver') {
2222
provider: 'naver',
2323
email: profile._json.email,
2424
};
25+
2526
let user = await this.authService.findUser(createUserDto);
2627
if (!user) {
2728
user = await this.authService.signUp(createUserDto);

apps/backend/src/auth/token/token.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class TokenService {
4040
generateInviteToken(workspaceId: number, role: string): string {
4141
// 초대용 JWT 토큰 생성
4242
const payload = { workspaceId, role };
43+
4344
return this.jwtService.sign(payload, {
4445
expiresIn: DAY, // 초대 유효 기간: 1일
4546
secret: process.env.JWT_SECRET,
@@ -98,6 +99,7 @@ export class TokenService {
9899
secure: true,
99100
sameSite: 'strict',
100101
});
102+
101103
response.clearCookie('refreshToken', {
102104
httpOnly: true,
103105
secure: true,

apps/backend/src/edge/edge.controller.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class EdgeController {
3131
@HttpCode(HttpStatus.CREATED)
3232
async createEdge(@Body() body: CreateEdgeDto) {
3333
await this.edgeService.createEdge(body);
34+
3435
return {
3536
message: EdgeResponseMessage.EDGE_CREATED,
3637
};
@@ -44,6 +45,7 @@ export class EdgeController {
4445
@Param('id', ParseIntPipe) id: number,
4546
): Promise<{ message: string }> {
4647
await this.edgeService.deleteEdge(id);
48+
4749
return {
4850
message: EdgeResponseMessage.EDGE_DELETED,
4951
};
@@ -59,6 +61,7 @@ export class EdgeController {
5961
@Param('workspaceId') workspaceId: string, // Snowflake ID
6062
): Promise<FindEdgesResponseDto> {
6163
const edges = await this.edgeService.findEdgesByWorkspace(workspaceId);
64+
6265
return {
6366
message: EdgeResponseMessage.EDGES_RETURNED,
6467
edges,

apps/backend/src/node/node.controller.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class NodeController {
4545
@HttpCode(HttpStatus.OK)
4646
async getNodeById(@Param('id', ParseIntPipe) id: number) {
4747
const node = await this.nodeService.findNodeById(id);
48+
4849
return {
4950
message: NodeResponseMessage.NODE_RETURNED,
5051
node: node,
@@ -59,6 +60,7 @@ export class NodeController {
5960
@HttpCode(HttpStatus.CREATED)
6061
async createNode(@Body() body: CreateNodeDto) {
6162
await this.nodeService.createNode(body);
63+
6264
return {
6365
message: NodeResponseMessage.NODE_CREATED,
6466
};
@@ -76,6 +78,7 @@ export class NodeController {
7678
@Param('id', ParseIntPipe) id: number,
7779
): Promise<{ message: string }> {
7880
await this.nodeService.deleteNode(id);
81+
7982
return {
8083
message: NodeResponseMessage.NODE_DELETED,
8184
};
@@ -92,6 +95,7 @@ export class NodeController {
9295
@Body() body: UpdateNodeDto,
9396
): Promise<{ message: string }> {
9497
await this.nodeService.updateNode(id, body);
98+
9599
return {
96100
message: NodeResponseMessage.NODE_UPDATED,
97101
};
@@ -105,6 +109,7 @@ export class NodeController {
105109
@HttpCode(HttpStatus.OK)
106110
async getCoordinates(@Param('id', ParseIntPipe) id: number) {
107111
const coordinate = await this.nodeService.getCoordinates(id);
112+
108113
return {
109114
message: NodeResponseMessage.NODE_GET_COORDINAE,
110115
coordinate: coordinate,
@@ -118,6 +123,7 @@ export class NodeController {
118123
@Body() body: MoveNodeDto,
119124
) {
120125
await this.nodeService.moveNode(id, body);
126+
121127
return {
122128
message: NodeResponseMessage.NODE_MOVED,
123129
};
@@ -133,6 +139,7 @@ export class NodeController {
133139
@Param('workspaceId') workspaceId: string, // Snowflake ID
134140
): Promise<FindNodesResponseDto> {
135141
const nodes = await this.nodeService.findNodesByWorkspace(workspaceId);
142+
136143
return {
137144
message: NodeResponseMessage.NODES_RETURNED,
138145
nodes,

apps/backend/src/node/node.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class NodeService {
3434
async createLinkedNode(x: number, y: number, pageId: number): Promise<Node> {
3535
// 페이지를 조회한다.
3636
const existingPage = await this.pageRepository.findOneBy({ id: pageId });
37+
3738
// 노드를 생성한다.
3839
const node = this.nodeRepository.create({ x, y });
3940

@@ -71,6 +72,7 @@ export class NodeService {
7172
if (!node) {
7273
throw new NodeNotFoundException();
7374
}
75+
7476
// 노드와 연결된 페이지를 조회한다.
7577
const linkedPage = await this.pageRepository.findOneBy({
7678
id: node.page.id,

apps/backend/src/page/page.controller.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class PageController {
4545
@Body() body: CreatePageDto,
4646
): Promise<CreatePageResponseDto> {
4747
const newPage = await this.pageService.createPage(body);
48+
4849
return {
4950
message: PageResponseMessage.PAGE_CREATED,
5051
pageId: newPage.id,
@@ -63,6 +64,7 @@ export class PageController {
6364
@Param('id', ParseIntPipe) id: number,
6465
): Promise<MessageResponseDto> {
6566
await this.pageService.deletePage(id);
67+
6668
return {
6769
message: PageResponseMessage.PAGE_DELETED,
6870
};
@@ -79,6 +81,7 @@ export class PageController {
7981
@Body() body: UpdatePageDto,
8082
): Promise<MessageResponseDto> {
8183
await this.pageService.updatePage(id, body);
84+
8285
return {
8386
message: PageResponseMessage.PAGE_UPDATED,
8487
};
@@ -94,6 +97,7 @@ export class PageController {
9497
@Param('workspaceId') workspaceId: string, // Snowflake ID
9598
): Promise<FindPagesResponseDto> {
9699
const pages = await this.pageService.findPagesByWorkspace(workspaceId);
100+
97101
return {
98102
message: PageResponseMessage.PAGES_RETURNED,
99103
pages,

apps/backend/src/page/page.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { WorkspaceNotFoundException } from '../exception/workspace.exception';
1111
import Redlock from 'redlock';
1212

1313
const RED_LOCK_TOKEN = 'RED_LOCK';
14+
1415
@Injectable()
1516
export class PageService {
1617
constructor(

apps/backend/src/redis/redis.service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ type RedisPage = {
99
title?: string;
1010
content?: string;
1111
};
12+
1213
@Injectable()
1314
export class RedisService {
14-
// private readonly redisClient: Redis;
15-
1615
constructor(
1716
@Inject(REDIS_CLIENT_TOKEN) private readonly redisClient: Redis,
1817
@Inject(RED_LOCK_TOKEN) private readonly redisLock: Redlock,

0 commit comments

Comments
 (0)