Skip to content

Commit b0ce626

Browse files
authored
Merge pull request #135 from codeit-moving/release
Release -> Main 20250107 16:35
2 parents aeb5d02 + dc9acb0 commit b0ce626

File tree

12 files changed

+49
-121
lines changed

12 files changed

+49
-121
lines changed

src/controllers/customerController.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import customerService from "../services/customerService";
22
import { Router } from "express";
33
import { asyncHandle } from "../utils/asyncHandler";
44
import passport from "passport";
5-
import { Payload } from "../utils/token.utils";
5+
import createToken, { Payload } from "../utils/token.utils";
66
import upload from "../utils/multer";
77
import { uploadFiles, uploadOptionalFiles } from "../middlewares/uploadFile";
8+
import cookieConfig from "../config/cookie.config";
89

910
const router = Router();
1011

@@ -22,7 +23,12 @@ router.post(
2223
regions: JSON.parse(req.body.regions).map(Number),
2324
services: JSON.parse(req.body.services).map(Number),
2425
};
25-
await customerService.createCustomerProfile(profile);
26+
const { id } = await customerService.createCustomerProfile(profile);
27+
28+
const payload = { id: userId, customer: { id: id } };
29+
30+
const accessToken = createToken(payload, "access");
31+
res.cookie("accessToken", accessToken, cookieConfig.accessTokenOption);
2632
res.status(204).send();
2733
} catch (error) {
2834
next(error);

src/controllers/moverController.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import {
99
optionalJwtAuth,
1010
} from "../middlewares/authMiddleware";
1111
import upload from "../utils/multer";
12-
import { Payload } from "../utils/token.utils";
12+
import createToken, { Payload } from "../utils/token.utils";
1313
import { uploadFiles, uploadOptionalFiles } from "../middlewares/uploadFile";
14+
import cookieConfig from "../config/cookie.config";
1415

1516
interface queryString {
1617
nextCursorId: string;
@@ -209,7 +210,12 @@ router.post(
209210
regions: JSON.parse(req.body.regions).map(Number),
210211
services: JSON.parse(req.body.services).map(Number),
211212
};
212-
await moverService.createMoverProfile(profile);
213+
const { id } = await moverService.createMoverProfile(profile);
214+
215+
const payload = { id: userId, mover: { id: id } };
216+
217+
const accessToken = createToken(payload, "access");
218+
res.cookie("accessToken", accessToken, cookieConfig.accessTokenOption);
213219
res.status(204).send();
214220
} catch (error) {
215221
next(error);

src/controllers/quoteController.ts

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import passport from "passport";
55
import customError from "../utils/interfaces/customError";
66
import quoteValidation from "../middlewares/validations/quote";
77
import { isCustomer } from "../middlewares/authMiddleware";
8+
import { throwHttpError } from "../utils/constructors/httpError";
89

910
const router = express.Router();
1011

@@ -41,13 +42,7 @@ router.get(
4142
const moverId = user.moverId; // user.id를 먼저 확인
4243

4344
if (!moverId) {
44-
const error: customError = new Error("Unauthorized");
45-
error.status = 401;
46-
error.message = "Unauthorized";
47-
error.data = {
48-
message: "기사 정보를 찾을 수 없습니다.",
49-
};
50-
throw error;
45+
return throwHttpError(401, "기사 정보를 찾을 수 없습니다.");
5146
}
5247

5348
// 기본값 설정
@@ -75,13 +70,7 @@ router.get(
7570

7671
// moverId 유효성 검사
7772
if (!moverId) {
78-
const error: customError = new Error("Bad Request");
79-
error.status = 400;
80-
error.message = "Bad Request";
81-
error.data = {
82-
message: "기사 ID가 필요합니다.",
83-
};
84-
throw error;
73+
return throwHttpError(400, "기사 ID가 필요합니다.");
8574
}
8675

8776
// 쿼리 파라미터 처리 (페이지네이션)
@@ -112,10 +101,7 @@ router.post(
112101

113102
// 파라미터 검증
114103
if (!movingRequestId) {
115-
const error: customError = new Error("Bad Request");
116-
error.status = 400;
117-
error.message = "이사 요청 ID가 필요합니다.";
118-
throw error;
104+
return throwHttpError(400, "이사 요청 ID가 필요합니다.");
119105
}
120106

121107
const result = await quoteService.rejectRequest(moverId, movingRequestId);
@@ -133,25 +119,13 @@ router.get(
133119
const moverId = user.moverId;
134120

135121
if (!moverId) {
136-
const error: customError = new Error("Unauthorized");
137-
error.status = 401;
138-
error.message = "Unauthorized";
139-
error.data = {
140-
message: "기사 정보를 찾을 수 없습니다.",
141-
};
142-
throw error;
122+
return throwHttpError(401, "기사 정보를 찾을 수 없습니다.");
143123
}
144124

145125
const quoteId = parseInt(req.params.quoteId);
146126

147127
if (isNaN(quoteId)) {
148-
const error: customError = new Error("Bad Request");
149-
error.status = 400;
150-
error.message = "Bad Request";
151-
error.data = {
152-
message: "올바르지 않은 파라미터입니다.",
153-
};
154-
throw error;
128+
return throwHttpError(400, "올바르지 않은 파라미터입니다.");
155129
}
156130

157131
const quote = await quoteService.getQuoteDetail(moverId, quoteId);

src/controllers/reviewController.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ router.get(
3939
const customerId = user.customerId;
4040

4141
if (!customerId) {
42-
const error: customError = new Error("Bad Request");
43-
error.status = 400;
44-
error.message = "고객 ID가 필요합니다.";
45-
throw error;
42+
return throwHttpError(400, "고객 ID가 필요합니다.");
4643
}
4744

4845
const { pageSize, pageNum } = req.query;
@@ -96,10 +93,7 @@ router.get(
9693
const customerId = user.customerId;
9794

9895
if (!customerId) {
99-
const error: customError = new Error("Bad Request");
100-
error.status = 400;
101-
error.message = "고객 ID가 필요합니다.";
102-
throw error;
96+
return throwHttpError(400, "고객 ID가 필요합니다.");
10397
}
10498

10599
const { pageSize, pageNum } = req.query;

src/middlewares/uploadFile.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export const uploadFiles = asyncHandle(async (req, res, next) => {
4646
});
4747

4848
req.fileUrls = await Promise.all(uploadPromises);
49-
console.log(req.fileUrls);
5049
next();
5150
} catch (e) {
5251
throwHttpError(500, "이미지 업로드 실패");

src/middlewares/validations/quote.ts

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,20 @@
11
import { RequestHandler } from "express";
22
import customError from "../../utils/interfaces/customError";
3+
import { throwHttpError } from "../../utils/constructors/httpError";
34

45
const createQuoteValidation: RequestHandler = (req, res, next) => {
56
const { movingRequestId, cost, comment } = req.body;
67

78
if (!movingRequestId || typeof movingRequestId !== "number") {
8-
const error: customError = new Error("Bad Request");
9-
error.status = 400;
10-
error.message = "Bad Request";
11-
error.data = {
12-
message: "이사 요청 ID가 올바르지 않습니다.",
13-
};
14-
return next(error);
9+
return throwHttpError(400, "이사 요청 ID가 올바르지 않습니다.");
1510
}
1611

1712
if (!cost || typeof cost !== "number" || cost <= 0) {
18-
const error: customError = new Error("Bad Request");
19-
error.status = 400;
20-
error.message = "Bad Request";
21-
error.data = {
22-
message: "견적 금액이 올바르지 않습니다.",
23-
};
24-
return next(error);
13+
return throwHttpError(400, "견적 금액이 올바르지 않습니다.");
2514
}
2615

2716
if (!comment || typeof comment !== "string" || !comment.trim()) {
28-
const error: customError = new Error("Bad Request");
29-
error.status = 400;
30-
error.message = "Bad Request";
31-
error.data = {
32-
message: "견적 코멘트가 올바르지 않습니다.",
33-
};
34-
return next(error);
17+
return throwHttpError(400, "견적 코멘트가 올바르지 않습니다.");
3518
}
3619

3720
next();

src/repositorys/movingRequestRepository.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,16 @@ const getMovingRequestCountByServices = async (where: WhereCondition = {}) => {
6565

6666
const getMovingRequestCountByDesignated = async (
6767
moverId: number,
68+
isPastRequest: boolean,
6869
where: WhereCondition = {}
6970
) => {
7071
return prismaClient.movingRequest.count({
7172
where: {
7273
...where,
74+
...(!isPastRequest ? { movingDate: { gt: new Date() } } : {}),
75+
confirmedQuote: {
76+
is: null,
77+
},
7378
mover: {
7479
some: {
7580
id: moverId,

src/services/moverService.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ const updateMoverProfile = async (
220220
profile: UpdateProfile
221221
) => {
222222
const { imageUrl, ...rest } = profile;
223-
console.log(rest);
224223
try {
225224
return await imageRepository.updateMoverProfile(
226225
imageUrl ? imageUrl[0] : undefined,

src/services/movingRequestService.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const setWhereCondition = (query: queryString, moverId: number) => {
4343
houseMove,
4444
officeMove,
4545
isDesignated,
46-
isQuoted,
46+
isQuoted = false,
4747
isPastRequest,
4848
} = query;
4949
const where: WhereCondition = {};
@@ -93,10 +93,7 @@ const setWhereCondition = (query: queryString, moverId: number) => {
9393
};
9494
}
9595

96-
if (isQuoted === undefined) {
97-
where.quote = {};
98-
where.isRejected = {};
99-
} else if (isQuoted) {
96+
if (isQuoted) {
10097
where.OR = [
10198
{
10299
quote: {
@@ -164,7 +161,7 @@ const getMovingRequestListByMover = async (
164161
moverId: number,
165162
query: queryString
166163
) => {
167-
const { limit, cursor, orderBy, isQuoted, isPastRequest } = query;
164+
const { limit, cursor, orderBy, isQuoted = false, isPastRequest } = query;
168165
const whereCondition: WhereCondition = setWhereCondition(query, moverId);
169166
const orderByQuery = setOrderBy(orderBy);
170167

@@ -225,7 +222,10 @@ const getMovingRequestListByMover = async (
225222
const totalCountPromise =
226223
movingRequestRepository.getTotalCount(countCondition);
227224
const designatedCountPromise =
228-
movingRequestRepository.getMovingRequestCountByDesignated(moverId);
225+
movingRequestRepository.getMovingRequestCountByDesignated(
226+
moverId,
227+
isPastRequest
228+
);
229229

230230
const movingRequestListPromise =
231231
movingRequestRepository.getMovingRequestListByMover(

src/services/quoteService.ts

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,7 @@ const createQuote = async (
3535
movingRequestId
3636
);
3737
if (!movingRequest) {
38-
const error: customError = new Error("Not Found");
39-
error.status = 404;
40-
error.message = "Not Found";
41-
error.data = {
42-
message: "존재하지 않는 이사 요청입니다.",
43-
};
44-
throw error;
38+
return throwHttpError(404, "존재하지 않는 이사 요청입니다.");
4539
}
4640

4741
// 견적서 생성
@@ -68,13 +62,7 @@ const createQuote = async (
6862
const getQuoteList = async (moverId: number, query: QuoteQueryString) => {
6963
// moverId 유효성 검사
7064
if (!moverId) {
71-
const error: customError = new Error("Bad Request");
72-
error.status = 400;
73-
error.message = "Bad Request";
74-
error.data = {
75-
message: "기사 ID가 필요합니다.",
76-
};
77-
throw error;
65+
return throwHttpError(400, "기사 ID가 필요합니다.");
7866
}
7967

8068
const { limit, cursor } = query;
@@ -120,13 +108,7 @@ const getQuoteDetail = async (moverId: number, quoteId: number) => {
120108
const quote = await quoteRepository.getQuoteDetailByMoverId(moverId, quoteId);
121109

122110
if (!quote) {
123-
const error: customError = new Error("Not Found");
124-
error.status = 404;
125-
error.message = "Not Found";
126-
error.data = {
127-
message: "견적서를 찾을 수 없습니다.",
128-
};
129-
throw error;
111+
return throwHttpError(404, "견적서를 찾을 수 없습니다.");
130112
}
131113

132114
// 2. 응답 데이터를 가공하여 반환합니다.
@@ -151,13 +133,7 @@ const rejectRequest = async (moverId: number, movingRequestId: number) => {
151133
movingRequestId
152134
);
153135
if (!movingRequest) {
154-
const error: customError = new Error("Not Found");
155-
error.status = 404;
156-
error.message = "Not Found";
157-
error.data = {
158-
message: "존재하지 않는 이사 요청입니다.",
159-
};
160-
throw error;
136+
return throwHttpError(404, "존재하지 않는 이사 요청입니다.");
161137
}
162138

163139
// 2. 반려 처리
@@ -179,13 +155,7 @@ const getRejectedRequestList = async (
179155
) => {
180156
// moverId 유효성 검사
181157
if (!moverId) {
182-
const error: customError = new Error("Bad Request");
183-
error.status = 400;
184-
error.message = "Bad Request";
185-
error.data = {
186-
message: "기사 ID가 필요합니다.",
187-
};
188-
throw error;
158+
return throwHttpError(400, "기사 ID가 필요합니다.");
189159
}
190160

191161
const { limit, cursor } = query;

0 commit comments

Comments
 (0)