Skip to content

Commit

Permalink
[Fix] 버전 정보 내려줄 때, nullable 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
yeseul106 committed Nov 27, 2023
1 parent 441c69b commit c63ace4
Showing 1 changed file with 98 additions and 84 deletions.
182 changes: 98 additions & 84 deletions src/service/userService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,105 +2,119 @@ import { PrismaClient } from "@prisma/client";
import { IntroDTO } from "../interfaces/user/IntroDTO";
import { UserDTO } from "../interfaces/user/UserDTO";
import { UserDuplicateDTO } from "../interfaces/user/UserDuplicateDTO";
import { UserVersionDTO } from "../interfaces/user/UserVersionDTO";

const prisma = new PrismaClient();

//* 사용자 조회
const getUser = async (userId: number): Promise<UserDTO> => {
const userData = await prisma.user.findFirst({
where: {
id: userId
},
select: {
id: true,
nickname: true,
profileImage: true
}
});
if (!userData) throw new Error('no user!');

return userData;
}
const userData = await prisma.user.findFirst({
where: {
id: userId,
},
select: {
id: true,
nickname: true,
profileImage: true,
},
});
if (!userData) throw new Error("no user!");

return userData;
};

//* 사용자 정보 조회
const getUserIntro = async (userId: number) => {
const userIntro: IntroDTO | null = await prisma.user.findUnique({
where: {
id: userId
},
select: {
id: true,
nickname: true,
profileImage: true,
intro: true
}
});
if (!userIntro) throw new Error('no userIntro!');

return userIntro;
}
const userIntro: IntroDTO | null = await prisma.user.findUnique({
where: {
id: userId,
},
select: {
id: true,
nickname: true,
profileImage: true,
intro: true,
},
});
if (!userIntro) throw new Error("no userIntro!");

return userIntro;
};

//* 유저닉네임 중복 검사
const postDuplicateNickname = async (userId: number, nickname: string) => {
let isExisted = 1;

const lowercaseNickname: string = nickname.toLowerCase();

const userCheck = await prisma.user.findFirst({
where: {
nickname: {
equals: lowercaseNickname,
mode: "insensitive"
}
},
select: {
nickname: true
}
});

if (!userCheck) {
isExisted = 0;
};

const data = {
check: isExisted
}
return data;
}
let isExisted = 1;

const lowercaseNickname: string = nickname.toLowerCase();

const userCheck = await prisma.user.findFirst({
where: {
nickname: {
equals: lowercaseNickname,
mode: "insensitive",
},
},
select: {
nickname: true,
},
});

if (!userCheck) {
isExisted = 0;
}

const data = {
check: isExisted,
};
return data;
};

//* refreshToken으로 유저 검색
const getUserByRfToken = async (refreshToken: string) => {
const user = prisma.user.findFirst({
where: {
refresh_token: refreshToken
}
});

return user;
}

const getUserVersion = async (userId: number) => {
const versionData = await prisma.version.findUnique({
where: {
id: 1
},
select: {
imageUrl: true,
iosForceVersion: true,
androidForceVersion: true,
text: true
}
});

return versionData;
}
const user = prisma.user.findFirst({
where: {
refresh_token: refreshToken,
},
});

return user;
};

const getUserVersion = async (
userId: number
): Promise<UserVersionDTO | null> => {
const versionData = await prisma.version.findUnique({
where: {
id: 1,
},
select: {
imageUrl: true,
iosForceVersion: true,
androidForceVersion: true,
text: true,
},
});

if (!versionData) {
return null;
}

const userVersionDTO: UserVersionDTO = {
androidForceVersion: versionData.androidForceVersion || "",
imageUrl: versionData.imageUrl || "",
text: versionData.text || "",
iosForceVersion: versionData.iosForceVersion || "",
};

return userVersionDTO;
};

const userService = {
getUser,
getUserIntro,
postDuplicateNickname,
getUserByRfToken,
getUserVersion
getUser,
getUserIntro,
postDuplicateNickname,
getUserByRfToken,
getUserVersion,
};

export default userService;
export default userService;

0 comments on commit c63ace4

Please sign in to comment.