Skip to content

Commit e744605

Browse files
authored
Merge pull request #23 from modern-agile-team/feature/kjs/#15
[Feature] Add typeDoc to server source
2 parents ab2edeb + a8da974 commit e744605

File tree

6 files changed

+189
-25
lines changed

6 files changed

+189
-25
lines changed

server/app/src/apis/middlewares/validationCheck.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ interface ValidationErrorItem {
77
constraints?: object;
88
}
99

10+
/**
11+
* @description Validation logic for request
12+
* @param {Request} req
13+
* @param {Response} res
14+
* @param {NextFunction} next
15+
* @returns
16+
*/
1017
async function validationCheck(
1118
req: Request,
1219
res: Response,

server/app/src/apis/module/error.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,25 @@ import {
55
} from '../../service/error';
66
import { Response } from 'express';
77

8+
/**
9+
* Branch handling of error code capabilities for error codes
10+
* @param err `{ unknown | ServerError | BadRequestError | NotFoundError }`
11+
* @param res
12+
* @returns {Response<ErrorResponse>} res
13+
*/
814
function errorResposne(
915
err: unknown | ServerError | BadRequestError | NotFoundError,
1016
res: Response
1117
) {
1218
if (err instanceof ServerError) {
13-
console.error(err);
1419
return res.status(500).json({ statusCode: err.code, msg: err.message });
1520
}
1621
if (err instanceof BadRequestError) {
17-
console.error(err);
1822
return res.status(400).json({ statusCode: err.code, msg: err.message });
1923
}
2024
if (err instanceof NotFoundError) {
21-
console.error(err);
2225
return res.status(404).json({ statusCode: err.code, msg: err.message });
2326
}
24-
console.error(err);
2527
return res.status(500).json({ statusCode: 500, msg: 'Unknown error' });
2628
}
2729

server/app/src/apis/visitor/visitor.ctrl.ts

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import { Request, Response } from 'express';
22
import Visitor from '../../service/visitor';
33
import VisitorRepository from '../../model/visitorRepository';
4-
import { BadRequestError } from '../../service/error';
4+
import { BadRequestError, ServerError } from '../../service/error';
55
import errorResposne from '../module/error';
6-
6+
import { VisitorCmtDto } from './visitor';
7+
8+
/**
9+
* Visitor increase and lookup API
10+
* @url /apis/visitor/count
11+
* @method patch
12+
* @resBody `{ statusCode: number, todayCount: number, totalCount: number }`
13+
* success response body
14+
* @resBody `{ statusCode: number, msg: string }` fail response body
15+
*/
716
const updateAndGetVisitor = async (req: Request, res: Response) => {
817
try {
918
const visitor = new Visitor(new VisitorRepository());
@@ -16,75 +25,119 @@ const updateAndGetVisitor = async (req: Request, res: Response) => {
1625
}
1726
};
1827

28+
/**
29+
* Visit comment generation API
30+
* @url /apis/visitor/comment
31+
* @method post
32+
* @reqBody `{ nickname: string, password: string, description: string }`
33+
* @resBody `{ statusCode: number, commendId: number, msg: string }` success response body
34+
* @resBody `{ statusCode: number, msg: string }` fail response body
35+
*/
1936
const createVisitComment = async (req: Request, res: Response) => {
20-
const RequestVisitorComment = Object.assign(req.body);
37+
const RequestVisitorComment: VisitorCmtDto = Object.assign(req.body);
2138

2239
try {
23-
if (RequestVisitorComment.nickname?.length === 0)
40+
if (RequestVisitorComment.nickname?.length === 0) {
2441
req.body.nickname = '익명';
42+
}
2543

2644
const visitor = new Visitor(new VisitorRepository(), RequestVisitorComment);
2745

2846
const response = await visitor.createComment();
2947

30-
if (response)
48+
if (response) {
3149
return res.status(201).json({
3250
statusCode: 201,
3351
commentId: response,
3452
msg: 'Successful visitor comment creation',
3553
});
54+
}
55+
throw new ServerError('Interver Server Error')
3656
} catch (err) {
3757
return errorResposne(err, res);
3858
}
3959
};
4060

61+
/**
62+
* API for editing visited comments
63+
* @url /apis/visitor/comment/:id
64+
* @method patch
65+
* @reqParams `{ id: number }` Unique number of edit comment
66+
* @reqBody `{ password: string, description: string }`
67+
* @resBody `{ statusCode: number, msg: string }` success or fail response body
68+
*/
4169
const updateVisitCommentById = async (req: Request, res: Response) => {
4270
const { id: visitorCommentId } = req.params;
4371

44-
const requestVisitorComment = Object.assign(req.body);
72+
const requestVisitorComment: VisitorCmtDto = Object.assign(req.body);
4573

4674
try {
4775
const visitor = new Visitor(new VisitorRepository(), requestVisitorComment);
4876

4977
const response = await visitor.updateCommentById(Number(visitorCommentId));
5078

51-
if (!response.success)
79+
if (!response.success) {
5280
return res.status(401).json({ statusCode: 401, msg: response.msg });
81+
}
5382
return res.status(200).json({ statusCode: 200, msg: response.msg });
5483
} catch (err) {
5584
return errorResposne(err, res);
5685
}
5786
};
5887

88+
/**
89+
* All visit comment lookup APIs
90+
* @url /apis/visitor/comments
91+
* @method get
92+
* @resBody `{ statusCode: number, visitorComments: [{id: number, nickname: string,
93+
description: string, date: string }] }` success response body
94+
* @resBody `{ statusCode: number, mesg: string }` fail response body
95+
*/
5996
const getVisitorComments = async (req: Request, res: Response) => {
6097
try {
6198
const visitor = new Visitor(new VisitorRepository());
6299

63-
const response = await visitor.getVisitorComments();
100+
const { visitorComments } = await visitor.getVisitorComments();
64101

65-
return res.status(200).json({ statusCode: 200, ...response });
102+
return res.status(200).json({ statusCode: 200, visitorComments });
66103
} catch (err) {
67104
return errorResposne(err, res);
68105
}
69106
};
70107

108+
/**
109+
* @typedef {Object} ResBody
110+
* @property {number} statusCode
111+
* @property {string} msg
112+
*/
113+
114+
/**
115+
* Visit comment delete API
116+
* @url /apis/visitor/comment/:id
117+
* @method delete
118+
* @reqParams `{ id: number }` Unique ID of the target to be deleted
119+
* @resBody `{ statusCode: number, msg: string }` success response body
120+
* @resBody `{ statusCode: number, msg: string }` fail response body
121+
*/
71122
const deleteVisitorCommentById = async (req: Request, res: Response) => {
72123
try {
73124
const visitorCommentId = req.params.id;
74125

75-
if (!visitorCommentId) throw new BadRequestError('id params is undefined');
76-
126+
if (!visitorCommentId) {
127+
throw new BadRequestError('id params is undefined');
128+
}
77129
const visitor = new Visitor(new VisitorRepository());
78130

79131
const response = await visitor.deleteVisitorCommentById(
80132
Number(visitorCommentId)
81133
);
82134

83-
if (response)
135+
if (response) {
84136
return res.status(200).json({
85137
statusCode: 200,
86138
msg: 'Successful deletion of visitor comment',
87139
});
140+
}
88141
} catch (err) {
89142
return errorResposne(err, res);
90143
}

server/app/src/apis/visitor/visitor.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { RowDataPacket } from 'mysql2';
33
export interface VisitorDto extends RowDataPacket {
44
todayCount: number;
55
totalCount: number;
6-
todayDate: string;
6+
todayDate?: string;
77
}
88

99
export interface VisitorCmtDto {
10-
nickname: string;
10+
nickname?: string;
1111
password: string;
1212
description: string;
1313
}

server/app/src/model/visitorRepository.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ import {
77
import db from '../config/db';
88
import { ServerError } from '../service/error';
99

10+
/**
11+
* Visitor-related data processing class
12+
*/
1013
class VisitorRepository {
14+
/**
15+
* Today number of visitors and total number of visitors inquiry method
16+
* @returns `{ todayCount: number, totalCount: number }`
17+
*/
1118
async getVisitorCnt(): Promise<VisitorDto> {
1219
let conn;
1320
try {
@@ -28,6 +35,10 @@ class VisitorRepository {
2835
}
2936
}
3037

38+
/**
39+
* Today's visits and total visits increase method
40+
* @returns `boolean` Whether to update
41+
*/
3142
async updateTodayVisitorCnt(): Promise<number> {
3243
let conn;
3344
try {
@@ -48,6 +59,11 @@ class VisitorRepository {
4859
}
4960
}
5061

62+
/**
63+
* Inquery today's date for visitor count table
64+
* @returns `string` today's date
65+
* @example 2022-09-12 00:00:00
66+
*/
5167
async getVisitorTodayDate() {
5268
let conn;
5369
try {
@@ -66,6 +82,12 @@ class VisitorRepository {
6682
}
6783
}
6884

85+
/**
86+
* Request date and number of visitors today, total number of visitors update method
87+
* @params
88+
* @todayDate `string` today date
89+
* @returns `boolean` Whether to update
90+
*/
6991
async updateTodayAndToTalVisitorCnt(todayDate: string) {
7092
let conn;
7193
try {
@@ -86,6 +108,11 @@ class VisitorRepository {
86108
}
87109
}
88110

111+
/**
112+
* Visit comment generation method
113+
* @params `{ nickname: string, password: string, description: string }`
114+
* @returns `number` Unique ID of the updated visit comment
115+
*/
89116
async createComment({
90117
nickname,
91118
password,
@@ -113,6 +140,11 @@ class VisitorRepository {
113140
}
114141
}
115142

143+
/**
144+
* Visit comment inquery method for ID
145+
* @params `number` Unique ID of the inquery target
146+
* @returns `{ id: number, nickname: string, description: string, date: string }`
147+
*/
116148
async getVisitorCommentById(
117149
visitorCommentId: number
118150
): Promise<VisitorCmtEntity> {
@@ -132,6 +164,13 @@ class VisitorRepository {
132164
}
133165
}
134166

167+
/**
168+
* Save visit comment modification method
169+
* @params
170+
* @visitorCommentId `number` Unique ID to be modified
171+
* @description `string` Modified comments
172+
* @returns `boolean` Whether to update
173+
*/
135174
async updateVisitorComment(
136175
visitorCommentId: number,
137176
description: string
@@ -153,6 +192,10 @@ class VisitorRepository {
153192
}
154193
}
155194

195+
/**
196+
* All visit comment inquery method
197+
* @returns `[{ id: number, nickname: string, description: string, date: string }]`
198+
*/
156199
async getVisitorComments(): Promise<VisitorCmtEntity[]> {
157200
let conn;
158201
try {
@@ -170,6 +213,12 @@ class VisitorRepository {
170213
}
171214
}
172215

216+
/**
217+
* Delete visiting comments with unique ID method
218+
* @params
219+
* @id `number` Unique ID for deletion
220+
* @returns `boolean` Whether to update
221+
*/
173222
async deleteVisitorCommentById(id: number): Promise<number> {
174223
let conn;
175224
try {

0 commit comments

Comments
 (0)