リファクタリング

This commit is contained in:
ろむねこ 2024-06-18 14:35:07 +09:00
parent 920c6a9eb6
commit 916ceaf085
Signed by: Fujimatsu
GPG Key ID: FA1F39A1BA37D168

View File

@ -2,15 +2,31 @@ import prisma from "@src/prisma";
import bcrypt from "bcrypt";
import { issueTokenByUserId } from "@src/utils/tokenUtils";
import { createHomeGroup } from "@src/services/homeGroupService";
import Logger from "@src/logger";
const logger = new Logger();
logger.setTag('authService');
async function registUser(email: string, password: string, homeGroupId?: string): Promise<String> {
const hashedPassword = bcrypt.hashSync(password, 10);
if (!homeGroupId) { // TODO: 作成失敗したときにHomeGroupだけ残るのを防ぐ
homeGroupId = await createHomeGroup(email).then((homeGroup) => { return homeGroup.id });
createHomeGroup(email).then((homeGroup) => { return homeGroup.id })
.then((id) => {
if (!id) {
logger.error("Create HomeGroup failed, id is undefined")
throw new Error("Create HomeGroup failed");
}
homeGroupId = id;
}).catch((e) => {
logger.error("Create HomeGroup failed");
logger.debug(e.message);
});
}
homeGroupId = homeGroupId as string; // ここに到達している時点でundefinedにはならないため
const registUser = prisma.user.create({ // TODO: emailバリデーション
data: {
email,