Skip to content

Commit

Permalink
[fix] #234 업데이트 버전 확인 통신 시, userId 사용 안하도록 코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
yeseul106 committed Dec 8, 2023
1 parent 41edda9 commit cd22912
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 57 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;
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 cd22912

Please sign in to comment.