-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchat.controller.js
More file actions
43 lines (35 loc) · 1.26 KB
/
chat.controller.js
File metadata and controls
43 lines (35 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { StatusCodes } from "http-status-codes";
import { parseWithBigInt, stringifyWithBigInt } from "../../bigintJson.js";
import { GetMessagesDto } from "../dto/chat.dto.js";
import { ChatService } from "../service/chat.service.js";
import { FindChatroomByMessageDto } from "../dto/chat.dto.js";
export const getMessages = async (req, res, next) => {
try {
const userId = BigInt(req.user.userId);
const dto = new GetMessagesDto ({
chatroomId: BigInt(req.params.chatroomId),
limit: req.query.limit,
cursor: req.query.cursor,
userId: userId,
});
const messages = await ChatService.getMessagesByChatroomId(dto);
const responseData = parseWithBigInt(stringifyWithBigInt(messages));
res.status(StatusCodes.OK).success(responseData);
} catch (err) {
next(err);
}
};
export const getMessageByKeyword = async (req, res, next) => {
try {
const userId = BigInt(req.user.userId);
const dto = new FindChatroomByMessageDto({
keyword: req.query.keyword,
userId: userId,
});
const messages = await ChatService.searchMessagesByKeyword(dto);
const responseData = parseWithBigInt(stringifyWithBigInt(messages));
res.status(StatusCodes.OK).success(responseData);
} catch(err) {
next(err);
}
};