Skip to content

Commit

Permalink
Merge pull request #235 from team-peekabook/feat/#234-version-get-api
Browse files Browse the repository at this point in the history
[feat] #234 강제 업데이트 버전 확인 시, 토큰 검증 로직 제거
  • Loading branch information
yeseul106 authored Dec 8, 2023
2 parents 638625c + cd22912 commit b553b94
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 60 deletions.
123 changes: 69 additions & 54 deletions src/controller/userController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,64 +8,79 @@ import { userTokenCheck } from "../constants/userTokenCheck";

//* 유저닉네임 중복 검사
const postDuplicateNickname = async (req: Request, res: Response) => {
const userId = req.body.userId;
const { nickname } = req.body;

if (!nickname) {
return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NULL_NICKNAME));
}

const refinedNickname = nickname.replace(/ /g,"");

try {

const data = await userService.postDuplicateNickname(+userId, refinedNickname);
if (!data) {
return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.FAIL_CHECK_NICKNAME))
}

return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_CHECK_NICKNAME, data));

} catch (error) {
const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode);

sendWebhookMessage(errorMessage);

res.status(sc.INTERNAL_SERVER_ERROR)
.send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR));
const userId = req.body.userId;
const { nickname } = req.body;

if (!nickname) {
return res
.status(sc.BAD_REQUEST)
.send(fail(sc.BAD_REQUEST, rm.NULL_NICKNAME));
}

const refinedNickname = nickname.replace(/ /g, "");

try {
const data = await userService.postDuplicateNickname(
+userId,
refinedNickname
);
if (!data) {
return res
.status(sc.BAD_REQUEST)
.send(fail(sc.BAD_REQUEST, rm.FAIL_CHECK_NICKNAME));
}

}

const getUserVersion = async (req: Request, res:Response) => {
const userId = req.body.userId;
if (!userId) {
return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST));
}

try {
const data = await userService.getUserVersion(+userId);

if(!data) {
return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST))
}

return res.status(sc.OK).send(success(sc.OK, rm.GET_USER_VERSION_SUCCESS, data));

} catch (error) {
const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode);

sendWebhookMessage(errorMessage);

res.status(sc.INTERNAL_SERVER_ERROR)
.send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR));
return res
.status(sc.OK)
.send(success(sc.OK, rm.SUCCESS_CHECK_NICKNAME, data));
} catch (error) {
const errorMessage = slackErrorMessage(
req.method.toUpperCase(),
req.originalUrl,
error,
req.statusCode
);

sendWebhookMessage(errorMessage);

res
.status(sc.INTERNAL_SERVER_ERROR)
.send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR));
}
};

const getUserVersion = async (req: Request, res: Response) => {
try {
const data = await userService.getUserVersion();

if (!data) {
return res
.status(sc.BAD_REQUEST)
.send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST));
}

}
return res
.status(sc.OK)
.send(success(sc.OK, rm.GET_USER_VERSION_SUCCESS, data));
} catch (error) {
const errorMessage = slackErrorMessage(
req.method.toUpperCase(),
req.originalUrl,
error,
req.statusCode
);

sendWebhookMessage(errorMessage);

res
.status(sc.INTERNAL_SERVER_ERROR)
.send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR));
}
};

const userController = {
postDuplicateNickname,
getUserVersion
}
postDuplicateNickname,
getUserVersion,
};

export default userController;
export default userController;
6 changes: 3 additions & 3 deletions src/router/userRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { auth } from "../middlewares";
const router: Router = Router();

//* 닉네임 중복 검사 POST /user/duplicate
router.post("/duplicate", userController.postDuplicateNickname);
router.post("/duplicate", auth, userController.postDuplicateNickname);
//* 유저 업데이트 버전 확인하기 GET /user/version
router.get("/v1/version", auth, userController.getUserVersion)
router.get("/v1/version", userController.getUserVersion);

export default router;
export default router;
4 changes: 1 addition & 3 deletions src/service/userService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ const getUserByRfToken = async (refreshToken: string) => {
return user;
};

const getUserVersion = async (
userId: number
): Promise<UserVersionDTO | null> => {
const getUserVersion = async (): Promise<UserVersionDTO | null> => {
const versionData = await prisma.version.findUnique({
where: {
id: 1,
Expand Down

0 comments on commit b553b94

Please sign in to comment.