-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommission.controller.js
More file actions
117 lines (97 loc) · 3.36 KB
/
commission.controller.js
File metadata and controls
117 lines (97 loc) · 3.36 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { StatusCodes } from "http-status-codes";
import { CommissionService } from '../service/commission.service.js';
import
{ GetCommissionDetailDto,
GetCommissionArtistInfoDto,
GetCommissionFormDto,
SubmitCommissionRequestDto
} from "../dto/commission.dto.js";
import { parseWithBigInt, stringifyWithBigInt } from "../../bigintJson.js";
// 커미션 게시글 상세글 조회
export const getCommissionDetail = async (req, res, next) => {
try {
const userId = req.user?.userId ? BigInt(req.user.userId) : null;
const dto = new GetCommissionDetailDto({
commissionId: BigInt(req.params.commissionId)
});
const commission = await CommissionService.getCommissionDetail(userId, dto);
const responseData = parseWithBigInt(stringifyWithBigInt(commission));
res.status(StatusCodes.OK).success(responseData);
} catch (err) {
next(err);
}
};
// 커미션 게시글 작가 정보 조회
export const getCommissionArtistInfo = async (req, res, next) => {
try {
const userId = req.user.userId ? BigInt(req.user.userId) : null;
const dto = new GetCommissionArtistInfoDto({
commissionId: BigInt(req.params.commissionId),
page: req.query.page,
limit: req.query.limit
});
const result = await CommissionService.getCommissionArtistInfo(userId, dto);
const responseData = parseWithBigInt(stringifyWithBigInt(result));
res.status(StatusCodes.OK).success(responseData);
} catch (err) {
next(err);
}
};
// 커미션 신청폼 조회
export const getCommissionForm = async (req, res, next) => {
try {
const userId = req.user?.userId ? BigInt(req.user.userId) : null;
const dto = new GetCommissionFormDto({
commissionId: BigInt(req.params.commissionId)
});
const result = await CommissionService.getCommissionForm(userId, dto);
const responseData = parseWithBigInt(stringifyWithBigInt(result));
res.status(StatusCodes.OK).success(responseData);
} catch (err) {
next(err);
}
};
// 커미션 신청 이미지 업로드
export const uploadRequestImage = async (req, res, next) => {
// multer 미들웨어 적용
const upload = CommissionService.getUploadMiddleware();
upload(req, res, async (err) => {
try {
// multer 에러 처리
if (err) {
return next(err);
}
// 파일 업로드 처리
const result = await CommissionService.uploadRequestImage(req.file);
res.status(StatusCodes.OK).success(result);
} catch (error) {
next(error);
}
});
}
// 커미션 신청 제출
export const submitCommissionRequest = async (req, res, next) => {
try {
const userId = req.user.userId;
const dto = new SubmitCommissionRequestDto({
commissionId: BigInt(req.params.commissionId),
formAnswer: req.body.formAnswer
});
const result = await CommissionService.submitCommissionRequest(userId, dto);
const responseData = parseWithBigInt(stringifyWithBigInt(result));
res.status(StatusCodes.OK).success(responseData);
} catch (err) {
next(err);
}
};
// 커미션 리포트 조회
export const getCommissionReport = async (req, res, next) => {
try {
const userId = BigInt(req.user.userId);
const result = await CommissionService.getReport(userId);
const responseData = parseWithBigInt(stringifyWithBigInt(result));
res.status(StatusCodes.OK).success(responseData);
} catch (err) {
next(err);
}
};