MCPcopy Create free account
hub / github.com/coderwhy/coderhub / CommentService

Class CommentService

src/service/comment.service.js:4–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2const commentRouter = require('../router/comment.router');
3
4class CommentService {
5 async create(momentId, content, userId) {
6 const statement = `INSERT INTO comment (content, moment_id, user_id) VALUES (?, ?, ?);`;
7 `INSERT INTO comment SET ?`
8 const [result] = await connection.execute(statement, [content, momentId, userId]);
9 return result;
10 }
11
12 async reply(momentId, content, userId, commentId) {
13 const statement = `INSERT INTO comment (content, moment_id, user_id, comment_id) VALUES (?, ?, ?, ?);`;
14 const [result] = await connection.execute(statement, [content, momentId, userId, commentId]);
15 return result;
16 }
17
18 async update(commentId, content) {
19 const statement = `UPDATE comment SET content = ? WHERE id = ?`;
20 const [result] = await connection.execute(statement, [content, commentId]);
21 return result;
22 }
23
24 async remove(commentId) {
25 const statement = `DELETE FROM comment WHERE id = ?`;
26 const [result] = await connection.execute(statement, [commentId]);
27 return result;
28 }
29
30 async getCommentsByMomentId(momentId) {
31 const statement = `
32 SELECT
33 m.id, m.content, m.comment_id commendId, m.createAt createTime,
34 JSON_OBJECT('id', u.id, 'name', u.name) user
35 FROM comment m
36 LEFT JOIN user u ON u.id = m.user_id
37 WHERE moment_id = ?;
38 `;
39 const [result] = await connection.execute(statement, [momentId]);
40 return result;
41 }
42}
43
44module.exports = new CommentService();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected