From 3f4226f8e1a08645b88e08e9e1d6d3444bf73ae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Wed, 19 Jun 2024 16:03:58 +0900 Subject: [PATCH] =?UTF-8?q?code=E3=81=8B=E3=82=89=E3=83=AD=E3=82=B0?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=81=99=E3=82=8B=E3=83=AD=E3=82=B8=E3=83=83?= =?UTF-8?q?=E3=82=AF=E3=82=92=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/child/authService.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/services/child/authService.ts diff --git a/src/services/child/authService.ts b/src/services/child/authService.ts new file mode 100644 index 0000000..ad37f8e --- /dev/null +++ b/src/services/child/authService.ts @@ -0,0 +1,26 @@ +import prisma from '@src/prisma'; +import { issueTokenByChildId } from '@src/utils/tokenUtils'; + +async function login(loginCode: number): Promise { + const childId: string | null = await prisma.activeLoginCode.findUnique({ + where: { + code: loginCode + } + }).then((activeLoginCode) => { + if (!activeLoginCode) { + return null; + } + return activeLoginCode.child_id; + }); + if (!childId) { + return null; + } + await prisma.activeLoginCode.delete({ + where: { + code: loginCode + } + }); + return await issueTokenByChildId(childId); +} + +export { login };