Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: snake to camel #60

Merged
merged 1 commit into from
Jan 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/service/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const getEmailService = async (email: string) => {
const emailExist = await User.findAll({
where: {
email,
isDeleted: false,
},
});
if (emailExist.length > 0) {
Expand Down Expand Up @@ -86,6 +87,7 @@ const postSignupService = async (
const emailExist = await User.findAll({
where: {
email,
isDeleted: false,
},
});
if (emailExist.length > 0) {
Expand All @@ -96,6 +98,7 @@ const postSignupService = async (
const nicknameExist = await User.findAll({
where: {
nickname,
isDeleted: false,
},
});

Expand Down Expand Up @@ -137,7 +140,7 @@ const postLoginService = async (email: string, password: string) => {
}

// 존재하지 않는 이메일
const user = await User.findOne({ where: { email: email } });
const user = await User.findOne({ where: { email, isDeleted: false } });
if (!user) {
return -100;
}
Expand Down Expand Up @@ -186,6 +189,7 @@ const getNicknameService = async (nickname: string) => {
const nicknameExist = await User.findAll({
where: {
nickname,
isDeleted: false,
},
});

Expand Down
21 changes: 12 additions & 9 deletions src/service/book.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,25 @@ import { Book, Review } from "../models";
const getBookService = async (userId: number) => {
let books = [];
await Review.findAll({
attributes: ["review_st"],
attributes: ["reviewSt"],
include: [
{
model: Book,
attributes: ["title", "author", "thumbnail"],
},
],
where: {
user_id: userId,
userId,
isDeleted: false,
},
order: [["updated_at", "DESC"]],
order: [["updatedAt", "DESC"]],
}).then((reviews) =>
reviews.forEach((review) => {
books.push({
thumbnail: review.book.thumbnail,
title: review.book.title,
author: review.book.author,
state: review.review_st,
state: review.reviewSt,
});
})
);
Expand Down Expand Up @@ -69,25 +70,27 @@ const postBookService = async (
[Op.or]: [
{ isbn: isbnOne },
{ isbn: isbnTwo },
{ isbn_sub: isbnOne },
{ isbn_sub: isbnTwo },
{ isbnSub: isbnOne },
{ isbnSub: isbnTwo },
],
isDeleted: false,
},
});
} else {
// isbn 1개
isbnOne = isbn;
exist = await Book.findOne({
where: {
[Op.or]: [{ isbn: isbnOne }, { isbn_sub: isbnOne }],
[Op.or]: [{ isbn: isbnOne }, { isbnSub: isbnOne }],
isDeleted: false,
},
});
}

if (!exist) {
Book.create({
await Book.create({
isbn: isbnOne,
...(isbnTwo && { isbn_sub: isbnTwo }),
...(isbnTwo && { isbnSub: isbnTwo }),
title,
author,
...(thumbnail && { thumbnail }),
Expand Down
90 changes: 42 additions & 48 deletions src/service/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const getQuestionService = async (userId: number, reviewId: number) => {
const review = await Review.findOne({
where: {
id: reviewId,
user_id: userId,
is_deleted: false,
userId,
isDeleted: false,
},
});

Expand All @@ -36,7 +36,7 @@ const getQuestionService = async (userId: number, reviewId: number) => {
return constant.WRONG_REQUEST_VALUE;
}

return { question_list: review.question_list };
return { questionList: review.questionList };
};

/**
Expand Down Expand Up @@ -68,7 +68,7 @@ const postReviewBeforeService = async (
}

// user 확인
const user = await User.findOne({ where: { id: userId } });
const user = await User.findOne({ where: { id: userId, isDeleted: false } });

// isbn 체킹
let mainIsbn: string, subIsbn: string;
Expand All @@ -83,8 +83,8 @@ const postReviewBeforeService = async (
[Op.or]: [
{ isbn: mainIsbn },
{ isbn: subIsbn },
{ isbn_sub: mainIsbn },
{ isbn_sub: subIsbn },
{ isbnSub: mainIsbn },
{ isbnSub: subIsbn },
],
},
});
Expand All @@ -96,11 +96,9 @@ const postReviewBeforeService = async (
// 중복 review 확인
const exist = await Review.findOne({
where: {
[Op.and]: [
{ book_id: book.id },
{ user_id: user.id },
{ is_deleted: false },
],
bookId: book.id,
userId: user.id,
isDeleted: false,
},
});

Expand All @@ -110,13 +108,13 @@ const postReviewBeforeService = async (

// review 확인 - 기존의 독서 전 단계가 완료된 리뷰
const review = await Review.create({
user_id: user.id,
book_id: book.id,
question_list: questionList,
answer_one: answerOne,
answer_two: answerTwo,
review_st: progress,
finish_st: false,
userId: user.id,
bookId: book.id,
questionList,
answerOne,
answerTwo,
reviewSt: progress,
finishSt: false,
});

return { reviewId: review.id };
Expand All @@ -142,13 +140,11 @@ const postReviewNowService = async (
}

// user 확인
const user = await User.findOne({ where: { id: userId } });
const user = await User.findOne({ where: { id: userId, isDeleted: false } });

// 해당 review 조회
const review = await Review.findOne({
where: {
[Op.and]: [{ id: reviewId }, { user_id: user.id }, { is_deleted: false }],
},
where: { id: reviewId, userId: user.id, isDeleted: false },
});

// 2. 존재하지 않는 review
Expand All @@ -157,13 +153,13 @@ const postReviewNowService = async (
}

// 3. review update
review.update({
answer_three: answerThree,
progress: progress,
await review.update({
answerThree,
reviewSt: progress,
});

// 변경 리뷰 저장
review.save();
await review.save();

return { reviewId: review.id };
};
Expand All @@ -187,20 +183,20 @@ const patchReviewService = async (
}

const reviewToChange = await Review.findOne({
where: { id: reviewId, is_deleted: false },
where: { id: reviewId, isDeleted: false },
});
if (!reviewToChange) {
return constant.WRONG_REQUEST_VALUE;
}

await Review.update(
{
answer_one: answerOne,
answer_two: answerTwo,
answer_three: answerThree,
answerOne,
answerTwo,
answerThree,
},
{
where: { id: reviewId },
where: { id: reviewId, isDeleted: false },
}
);

Expand All @@ -224,8 +220,8 @@ const getReviewService = async (userId: number, reviewId: number) => {
const reviewToShow = await Review.findOne({
where: {
id: reviewId,
user_id: userId,
is_deleted: false,
userId,
isDeleted: false,
},
});

Expand All @@ -235,17 +231,17 @@ const getReviewService = async (userId: number, reviewId: number) => {
}

const bookToShow = await Book.findOne({
where: { id: reviewToShow.book_id },
where: { id: reviewToShow.bookId },
});

return {
bookTitle: bookToShow.title,
answerOne: reviewToShow.answer_one,
answerTwo: reviewToShow.answer_two,
questionList: reviewToShow.question_list,
answerThree: reviewToShow.answer_three,
reviewState: reviewToShow.review_st,
finishState: reviewToShow.finish_st,
answerOne: reviewToShow.answerOne,
answerTwo: reviewToShow.answerTwo,
questionList: reviewToShow.questionList,
answerThree: reviewToShow.answerThree,
reviewState: reviewToShow.reviewSt,
finishState: reviewToShow.finishSt,
};
};

Expand All @@ -265,13 +261,11 @@ const deleteReviewService = async (userId: number, reviewId: number) => {
}

// user 확인
const user = await User.findOne({ where: { id: userId } });
const user = await User.findOne({ where: { id: userId, isDeleted: false } });

// 해당 review 조회
const review = await Review.findOne({
where: {
[Op.and]: [{ id: reviewId }, { user_id: user.id }],
},
where: { id: reviewId, userId: user.id, isDeleted: false },
});

// 2. 존재하지 않는 review
Expand All @@ -280,17 +274,17 @@ const deleteReviewService = async (userId: number, reviewId: number) => {
}

// 3. 이미 삭제된 Review 입니다.
if (review.is_deleted) {
if (review.isDeleted) {
return constant.VALUE_ALREADY_DELETED;
}

// 독후감 삭제
review.update({
is_deleted: true,
await review.update({
isDeleted: true,
});

// 삭제 리뷰 저장
review.save();
await review.save();

return constant.SUCCESS;
};
Expand Down
11 changes: 6 additions & 5 deletions src/service/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ import { User, Review } from "../models";
*/
const getMyInfoService = async (userId: number) => {
// TODO: - user isDeleted 상태 확인
const user = await User.findOne({ where: { id: userId } });
const user = await User.findOne({ where: { id: userId, isDeleted: false } });
const img = user.img;
const nickname = user.nickname;
const email = user.email;

const review = await Review.findAll({
where: {
user_id: userId,
is_deleted: false,
userId,
isDeleted: false,
},
});
const reviewCount = review.length;
Expand All @@ -41,7 +42,7 @@ const getMyInfoService = async (userId: number) => {
const patchImgService = async (userId: number, img: string) => {
// 폼데이터 맞는지 체크 -> 아니면 return statusCode.WRONG_IMG_FORM
if (!img) {
return constant.NULL_VALUE
return constant.NULL_VALUE;
} else if (img === undefined) {
return constant.WRONG_IMG_FORM;
}
Expand All @@ -52,7 +53,7 @@ const patchImgService = async (userId: number, img: string) => {
img: img,
},
{
where: { id: userId },
where: { id: userId, isDeleted: false },
}
);
};
Expand Down