Skip to content

Commit 41d99f0

Browse files
authored
Merge pull request #49 from codeit-moving/dev
Dev -> main 20241220 프론트요청 반영 & 유조기능 수정
2 parents dec8e0f + 23916a9 commit 41d99f0

File tree

12 files changed

+183
-46
lines changed

12 files changed

+183
-46
lines changed

package-lock.json

Lines changed: 87 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prisma/ERD.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ erDiagram
5656
Int id PK
5757
Int service
5858
DateTime movingDate
59+
Int region
5960
String pickupAddress
6061
String dropOffAddress
6162
Int requestCount
@@ -212,6 +213,7 @@ erDiagram
212213
- `id`:
213214
- `service`:
214215
- `movingDate`:
216+
- `region`:
215217
- `pickupAddress`:
216218
- `dropOffAddress`:
217219
- `requestCount`:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "MovingRequest" ADD COLUMN "region" INTEGER NOT NULL DEFAULT 0;

src/config/cookie.config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,20 @@ const accessTokenOption: CookieOptions = {
55
secure: true,
66
sameSite: "none",
77
maxAge: 1000 * 60 * 60, // 1시간
8-
path: "/",
98
};
109

1110
const refreshTokenOption: CookieOptions = {
1211
httpOnly: true,
1312
secure: true,
1413
sameSite: "none",
1514
maxAge: 1000 * 60 * 60 * 24 * 7, // 7일
16-
path: "/auth/refresh",
1715
};
1816

1917
const clearCookieOption: CookieOptions = {
2018
httpOnly: true,
2119
secure: true,
2220
sameSite: "none",
2321
maxAge: 0,
24-
path: "/",
2522
};
2623

2724
const sessionOption: CookieOptions = {

src/controllers/movingRequestController.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ router.get(
2525
officeMove = "false",
2626
orderBy = "resent",
2727
isQuoted = "false",
28+
isPastRequest = "false",
2829
} = req.query;
2930
const parseLimit = parseInt(limit as string);
3031
const parseCursor = parseInt(cursor as string);
@@ -33,6 +34,7 @@ router.get(
3334
const parseHouseMove = checkBoolean(houseMove as string);
3435
const parseOfficeMove = checkBoolean(officeMove as string);
3536
const parseIsQuoted = checkBoolean(isQuoted as string);
37+
const parsePastRequest = checkBoolean(isPastRequest as string);
3638

3739
const movingRequestList =
3840
await movingRequestService.getMovingRequestListByMover(moverId, {
@@ -45,6 +47,7 @@ router.get(
4547
officeMove: parseOfficeMove || false,
4648
orderBy: orderBy as string,
4749
isQuoted: parseIsQuoted || false,
50+
isPastRequest: parsePastRequest || false,
4851
});
4952
return res.status(200).send(movingRequestList);
5053
} catch (error) {
@@ -122,15 +125,18 @@ router.post(
122125
asyncHandle(async (req, res, next) => {
123126
try {
124127
const { customerId } = req.user as { customerId: number };
125-
const { service, movingDate, pickupAddress, dropOffAddress } = req.body;
128+
const { service, movingDate, pickupAddress, dropOffAddress, region } =
129+
req.body;
126130
const date = new Date(movingDate);
131+
const parseRegion = parseInt(region as string);
127132
const movingRequest = await movingRequestService.createMovingRequest(
128133
customerId,
129134
{
130135
service,
131136
movingDate: date,
132137
pickupAddress,
133138
dropOffAddress,
139+
region: parseRegion,
134140
}
135141
);
136142
return res.status(201).send(movingRequest);

src/middlewares/passport.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ passport.use(
2626
const token = req.cookies["accessToken"];
2727

2828
if (!token) {
29-
const error: CustomError = new Error("Unauthorized");
30-
error.status = 401;
29+
const error: CustomError = new Error("Token missing");
30+
error.status = 403;
3131
error.data = {
3232
message: "토큰이 존재하지 않습니다.",
3333
};
@@ -38,8 +38,8 @@ passport.use(
3838
const decoded = jwt.verify(token, JWT_SECRET);
3939
return done(null, decoded); // 토큰이 있고 유효하면 유저 정보 반환
4040
} catch (err) {
41-
const error: CustomError = new Error("Unauthorized");
42-
error.status = 401;
41+
const error: CustomError = new Error("Invalid token");
42+
error.status = 403;
4343
error.data = {
4444
message: "유효하지 않은 토큰입니다.",
4545
};
@@ -71,8 +71,8 @@ passport.use(
7171
const refreshToken = req.cookies["refreshToken"];
7272

7373
if (!refreshToken) {
74-
const error: CustomError = new Error("Unauthorized");
75-
error.status = 401;
74+
const error: CustomError = new Error("Token missing");
75+
error.status = 403;
7676
error.data = {
7777
message: "리프레시 토큰이 존재하지 않습니다.",
7878
};
@@ -83,8 +83,8 @@ passport.use(
8383
const decoded = jwt.verify(refreshToken, REFRESH_SECRET);
8484
return done(null, decoded);
8585
} catch (err) {
86-
const error: CustomError = new Error("Unauthorized");
87-
error.status = 401;
86+
const error: CustomError = new Error("Invalid token");
87+
error.status = 403;
8888
error.data = {
8989
message: "유효하지 않은 리프레시 토큰입니다.",
9090
};

src/middlewares/validations/movingRequest.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { RequestHandler } from "express";
22
import customError from "../../utils/interfaces/customError";
33

44
const createMovingRequestValidation: RequestHandler = (req, res, next) => {
5-
const { service, movingDate, pickupAddress, dropOffAddress } = req.body;
5+
const { service, movingDate, pickupAddress, dropOffAddress, region } =
6+
req.body;
67

78
if (!service || typeof service !== "number" || service < 1 || service > 3) {
89
const error: customError = new Error("Bad Request");
@@ -45,6 +46,16 @@ const createMovingRequestValidation: RequestHandler = (req, res, next) => {
4546
return next(error);
4647
}
4748

49+
if (!region || typeof region !== "number") {
50+
const error: customError = new Error("Bad Request");
51+
error.status = 400;
52+
error.message = "Bad Request";
53+
error.data = {
54+
message: "지역코드가 올바르지 않습니다.",
55+
};
56+
return next(error);
57+
}
58+
4859
next();
4960
};
5061

src/repositorys/movingRequestRepository.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const getMovingRequestCountByCustomer = (customerId: number) => {
2727
};
2828

2929
//이사요청 서비스별 카운트 조회
30-
const getMovingRequestCountByServices = async (where: WhereCondition) => {
30+
const getMovingRequestCountByServices = async (where: WhereCondition = {}) => {
3131
const counts = await prismaClient.movingRequest.groupBy({
3232
where,
3333
by: ["service"],
@@ -62,8 +62,8 @@ const getMovingRequestCountByServices = async (where: WhereCondition) => {
6262
};
6363

6464
const getMovingRequestCountByDesignated = async (
65-
where: WhereCondition,
66-
moverId: number
65+
moverId: number,
66+
where: WhereCondition = {}
6767
) => {
6868
return prismaClient.movingRequest.count({
6969
where: {
@@ -77,7 +77,7 @@ const getMovingRequestCountByDesignated = async (
7777
});
7878
};
7979

80-
const getTotalCount = async (where: WhereCondition) => {
80+
const getTotalCount = async (where: WhereCondition = {}) => {
8181
return prismaClient.movingRequest.count({
8282
where,
8383
});
@@ -93,7 +93,7 @@ const getMovingRequestListByMover = (
9393
return prismaClient.movingRequest.findMany({
9494
where,
9595
orderBy,
96-
take: limit,
96+
take: limit + 1, //커서 페이지 넘버 계산을 위해 1개 더 조회
9797
skip: cursor ? 1 : 0, //커서 자신을 스킵하기 위함
9898
cursor: cursor ? { id: cursor } : undefined,
9999
select: {
@@ -316,7 +316,7 @@ const getActiveRequest = (customerId: number) => {
316316
};
317317

318318
export default {
319-
getMovingRequestList: getMovingRequestListByMover,
319+
getMovingRequestListByMover,
320320
createMovingRequest,
321321
updateDesignated,
322322
updateDesignatedCancel,

src/services/authService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const signIn = async ({ email, password }: SignInData) => {
4747
const isPasswordValid = await bcrypt.compare(password, user.password!); //패스워드 검증
4848

4949
if (!isPasswordValid) {
50-
const error: CustomError = new Error("Unauthorized");
50+
const error: CustomError = new Error("Invalid password");
5151
error.status = 401;
5252
error.data = {
5353
message: "비밀번호가 일치하지 않습니다.",
@@ -181,7 +181,7 @@ const validatePassword = async (userId: number, password: string) => {
181181
}
182182

183183
if (!decodedPassword) {
184-
const error: CustomError = new Error("Unauthorized");
184+
const error: CustomError = new Error("Invalid password");
185185
error.status = 401;
186186
error.data = {
187187
message: "비밀번호가 일치하지 않습니다.",

0 commit comments

Comments
 (0)