🧑💻 (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.
This commit is contained in:
@ -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,
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user