From 41b6807a36be5cd2464904de054e0d1c2ae3b863 Mon Sep 17 00:00:00 2001 From: Rafi Arrafif Date: Sat, 11 Oct 2025 02:00:19 +0700 Subject: [PATCH] :technologist: (dev) change register flow Change the user creation flow in the register so that it must go through the main create user service first instead of directly accessing the create user repo. --- .../createUserViaRegister.controller.ts | 7 ++++++- .../http/createUserViaRegister.service.ts | 16 +++++++--------- src/modules/userSession/index.ts | 6 ++++++ 3 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 src/modules/userSession/index.ts diff --git a/src/modules/user/controllers/createUserViaRegister.controller.ts b/src/modules/user/controllers/createUserViaRegister.controller.ts index 623928a..c909432 100644 --- a/src/modules/user/controllers/createUserViaRegister.controller.ts +++ b/src/modules/user/controllers/createUserViaRegister.controller.ts @@ -3,12 +3,17 @@ import { createUserViaRegisterSchema } from "../schemas/createUserViaRegister.sc import { mainErrorHandler } from "../../../helpers/error/handler"; import { returnWriteResponse } from "../../../helpers/callback/httpResponse"; import { createUserViaRegisterService } from "../services/http/createUserViaRegister.service"; +import { getUserHeaderInformation } from "../../../helpers/http/userHeader/getUserHeaderInformation"; export const createUserViaRegisterController = async (ctx: Context) => { try { const validate = createUserViaRegisterSchema.parse(ctx.body); - const createUser = await createUserViaRegisterService(validate); + const userHeaderInfo = getUserHeaderInformation(ctx); + const createUser = await createUserViaRegisterService( + validate, + userHeaderInfo + ); return returnWriteResponse( ctx.set, 201, diff --git a/src/modules/user/services/http/createUserViaRegister.service.ts b/src/modules/user/services/http/createUserViaRegister.service.ts index 3687e33..3be79b8 100644 --- a/src/modules/user/services/http/createUserViaRegister.service.ts +++ b/src/modules/user/services/http/createUserViaRegister.service.ts @@ -1,18 +1,16 @@ import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder"; -import { hashPassword } from "../../../../helpers/security/password/hash"; -import { createUserViaRegisterRepository } from "../../repositories/create/createUserViaRegister.repository"; +import { UserHeaderInformation } from "../../../../helpers/http/userHeader/getUserHeaderInformation/types"; +import { createUserSessionService } from "../../../userSession/services/createUserSession.service"; import { createUserViaRegisterInput } from "../../user.types"; +import { createUserService } from "../internal/createUser.service"; export const createUserViaRegisterService = async ( - payload: createUserViaRegisterInput + payload: createUserViaRegisterInput, + userHeaderInfo: UserHeaderInformation ) => { try { - const hashedPassword = await hashPassword(payload.password); - - return createUserViaRegisterRepository({ - ...payload, - password: hashedPassword, - }); + const createdUser = await createUserService(payload); + return createUserSessionService(createdUser.id, userHeaderInfo); } catch (error) { ErrorForwarder(error); } diff --git a/src/modules/userSession/index.ts b/src/modules/userSession/index.ts new file mode 100644 index 0000000..3393614 --- /dev/null +++ b/src/modules/userSession/index.ts @@ -0,0 +1,6 @@ +import Elysia from "elysia"; + +export const userSessionModule = new Elysia({ prefix: "/sessions" }).get( + "/", + () => "User Session Module is working!" +);