Skip to content

Commit 27ed1e8

Browse files
committed
[Update] Add Visitor class typedoc #15
1 parent 26a516a commit 27ed1e8

File tree

1 file changed

+54
-11
lines changed

1 file changed

+54
-11
lines changed

server/app/src/service/visitor.ts

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { VisitorCmtDto, VisitorCmtEntity } from '../apis/visitor/visitor';
1+
import { VisitorCmtDto, VisitorCmtEntity, VisitorDto } from '../apis/visitor/visitor';
22
import VisitorRepository from '../model/visitorRepository';
33
import bcrypt from 'bcrypt';
44
import { NotFoundError, ServerError } from './error';
@@ -9,24 +9,32 @@ interface Response {
99
msg: string;
1010
}
1111

12-
/**
13-
* @constructor
14-
* @param {VisitorRepository} visitorRepository
15-
* @param {any=} body
16-
*/
12+
1713
class Visitor {
14+
/**
15+
* @param {VisitorRepository} visitorRepository
16+
* @param {any=} body
17+
*/
1818
private readonly visitorRepository: VisitorRepository;
1919
readonly body;
2020
constructor(visitorRepository: VisitorRepository, body?: any) {
2121
this.visitorRepository = visitorRepository;
2222
this.body = body;
2323
}
2424

25+
/**
26+
* @description Method for retrieving number of visitors
27+
* @returns {VisitorDto} visitorCnt
28+
*/
2529
async getVisitorCnt() {
2630
const visitorCnt = await this.visitorRepository.getVisitorCnt();
2731
return visitorCnt;
2832
}
2933

34+
/**
35+
* @description Update the number of visitors every time they visit your portfolio web
36+
* @returns {VisitorDto} visitorCnt
37+
*/
3038
async updateAndGetVisitorCnt() {
3139
const todayDate = await this.visitorRepository.getVisitorTodayDate();
3240
const formatTodayDate = moment(todayDate, 'YYYY-MM-DD');
@@ -50,6 +58,9 @@ class Visitor {
5058
throw new ServerError('Interval server error');
5159
}
5260

61+
/**
62+
* @description Create visitor comment information
63+
*/
5364
async createComment(): Promise<number> {
5465
const { body } = this;
5566
const encryptedPassword = await this.encryptPassword(body.password);
@@ -64,10 +75,17 @@ class Visitor {
6475
visitorComment
6576
);
6677

67-
if (commentId) return commentId;
78+
if (commentId) {
79+
return commentId;
80+
}
6881
throw new ServerError('Interver Server Error');
6982
}
7083

84+
/**
85+
* @description Method for password encryption
86+
* @param {string} password
87+
* @returns {Promise<string>}
88+
*/
7189
private async encryptPassword(password: string): Promise<string> {
7290
const saltRounds = 10;
7391

@@ -80,22 +98,29 @@ class Visitor {
8098
return encryptedPassword;
8199
}
82100

101+
/**
102+
* @param {number} visitorCommentId update target id
103+
* @returns {Promise<Response>}
104+
*/
83105
async updateCommentById(visitorCommentId: number): Promise<Response> {
84106
const { password, description }: VisitorCmtDto = this.body;
85107

86108
const visitorComment = await this.visitorRepository.getVisitorCommentById(
87109
visitorCommentId
88110
);
89111

90-
if (!visitorComment) throw new NotFoundError('No data exists');
112+
if (!visitorComment) {
113+
throw new NotFoundError('No data exists');
114+
}
91115

92116
const isSamePassword = await this.comparePassword(
93117
password,
94118
visitorComment.password
95119
);
96120

97-
if (!isSamePassword)
121+
if (!isSamePassword) {
98122
return { success: false, msg: 'Passwords do not match' };
123+
}
99124

100125
await this.visitorRepository.updateVisitorComment(
101126
visitorCommentId,
@@ -105,28 +130,46 @@ class Visitor {
105130
return { success: true, msg: 'Visitor comment update complete' };
106131
}
107132

133+
/**
134+
* @param {string} password
135+
* @param {string} encryptedPassword
136+
* @returns {Promise<boolean>} password Verification
137+
*/
108138
private async comparePassword(password: string, encryptedPassword: string) {
109139
return await bcrypt.compare(password, encryptedPassword);
110140
}
111141

142+
/**
143+
* @description All visitor comment list retrieval methods
144+
* @returns {Promise<{ visitorComments: VisitorCmtEntity[] }>}
145+
*/
112146
async getVisitorComments(): Promise<{ visitorComments: VisitorCmtEntity[] }> {
113147
const visitorComments = await this.visitorRepository.getVisitorComments();
114148

115149
return { visitorComments };
116150
}
117151

152+
/**
153+
* @param {number} visitorCommentId visitor comment id you want to delete
154+
* @returns {Promise<boolean>}
155+
*/
118156
async deleteVisitorCommentById(visitorCommentId: number): Promise<boolean> {
119157
const visitorComment = await this.visitorRepository.getVisitorCommentById(
120158
visitorCommentId
121159
);
122160

123-
if (!visitorComment) throw new NotFoundError('No data exists');
161+
if (!visitorComment) {
162+
throw new NotFoundError('No data exists');
163+
}
124164

125165
const isDelete = await this.visitorRepository.deleteVisitorCommentById(
126166
visitorCommentId
127167
);
128168

129-
if (isDelete) return true;
169+
if (isDelete) {
170+
return true;
171+
}
172+
130173
throw new ServerError('Interver Server Error');
131174
}
132175
}

0 commit comments

Comments
 (0)