-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchatroom.controller.js
More file actions
60 lines (49 loc) · 1.79 KB
/
chatroom.controller.js
File metadata and controls
60 lines (49 loc) · 1.79 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { StatusCodes } from "http-status-codes";
import { ChatroomService } from "../service/chatroom.service.js";
import { CreateChatroomDto } from "../dto/chatroom.dto.js";
import { GetChatroomDto } from "../dto/chatroom.dto.js";
import { DeleteChatroomDto } from "../dto/chatroom.dto.js";
import { parseWithBigInt, stringifyWithBigInt } from "../../bigintJson.js";
export const createChatroom = async (req, res, next) => {
try {
const consumerId = BigInt(req.user.userId);
const dto = new CreateChatroomDto({
consumerId: consumerId,
artistId: BigInt(req.body.artistId),
requestId: BigInt(req.body.requestId),
});
const chatroom = await ChatroomService.createChatroom(dto);
const responseData = parseWithBigInt(stringifyWithBigInt(chatroom));
res.status(StatusCodes.CREATED).success(responseData);
} catch (err) {
next(err);
}
};
export const getChatroom = async (req, res, next) => {
try {
const dto = new GetChatroomDto({
consumerId: BigInt(req.user.userId),
accountId: BigInt(req.user.accountId),
});
const chatrooms = await ChatroomService.getChatroomsByUserId(dto);
const responseData = parseWithBigInt(stringifyWithBigInt(chatrooms));
res.status(StatusCodes.OK).success(responseData);
} catch (err) {
next(err)
}
};
export const deleteChatrooms = async (req, res, next) => {
try {
const userId = BigInt(req.user.userId);
const dto = new DeleteChatroomDto({
chatroomIds: req.body.chatroomIds,
userType: req.body.userType,
userId: userId,
});
const chatrooms = await ChatroomService.softDeleteChatroomsByUser(dto);
const responseData = parseWithBigInt(stringifyWithBigInt(chatrooms));
res.status(StatusCodes.NO_CONTENT).success(responseData);
} catch (err) {
next(err)
}
};