From aa67cc903efb074cb9194138762a1659b53e1c1a Mon Sep 17 00:00:00 2001 From: nusuy Date: Sun, 29 Jan 2023 01:17:52 +0900 Subject: [PATCH] refactor: Modularize NicknameCheck (#36) Co-authored-by: nusuy Co-authored-by: jiyunBae007 <63540652+jiyunBae007@users.noreply.github.com> --- util/NicknameCheck.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 util/NicknameCheck.js diff --git a/util/NicknameCheck.js b/util/NicknameCheck.js new file mode 100644 index 0000000..85352d9 --- /dev/null +++ b/util/NicknameCheck.js @@ -0,0 +1,19 @@ +const { PrismaClient } = require("@prisma/client"); +const prisma = new PrismaClient(); + +// 닉네임 중복확인 함수 +async function nicknameOverlapCheck(nickname) { + const result = await prisma.users.findFirst({ + where: { + nickname: nickname, + }, + select: { + nickname: true, + }, + }); + + // result === null가 true이면 사용 가능, false면 사용 불가 + return result === null; +} + +module.exports = { nicknameOverlapCheck };