💥 add basic fetch user via email
This commit is contained in:
@ -0,0 +1,18 @@
|
||||
import { Context } from "elysia";
|
||||
import { getUserByIdSchema } from "../schemas/getUserById.schema";
|
||||
import { mainErrorHandler } from "../../../helpers/error/handler";
|
||||
import { getUserByEmailService } from "../services/http/getUserByEmail.service";
|
||||
import { returnReadResponse } from "../../../helpers/callback/httpResponse";
|
||||
import { getUserOptionsSchema } from "../schemas/getUserOptions.schema";
|
||||
|
||||
export const getUserByEmailController = async (ctx: Context) => {
|
||||
try {
|
||||
const params = getUserByIdSchema.parse(ctx.params);
|
||||
const options = getUserOptionsSchema.parse(ctx.query);
|
||||
const getUserByEmail = await getUserByEmailService(params.email, options);
|
||||
|
||||
return returnReadResponse(ctx.set, 200, "User data found", getUserByEmail);
|
||||
} catch (error) {
|
||||
return mainErrorHandler(ctx.set, error);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import Elysia from "elysia";
|
||||
import { createUserViaRegisterController } from "./controller/createUserViaRegister.controller";
|
||||
import { getUserByEmailController } from "./controller/getUserByEmail.controller";
|
||||
|
||||
export const userModule = new Elysia({ prefix: "/users" }).post(
|
||||
"/",
|
||||
createUserViaRegisterController
|
||||
);
|
||||
export const userModule = new Elysia({ prefix: "/users" })
|
||||
.post("/", createUserViaRegisterController)
|
||||
.get("/e/:email", getUserByEmailController);
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
import { userModel } from "../../user.model";
|
||||
import { getUserDataOptions } from "../../user.types";
|
||||
|
||||
export const findUserByEmailRepository = async (
|
||||
email: string,
|
||||
options: getUserDataOptions
|
||||
) => {
|
||||
return await userModel.findUnique({
|
||||
where: {
|
||||
email,
|
||||
},
|
||||
omit: {},
|
||||
});
|
||||
};
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
import Joi from "joi";
|
||||
|
||||
export const editUserSchema = Joi.object({
|
||||
name: Joi.string()
|
||||
.min(4)
|
||||
.max(255),
|
||||
username: Joi.string()
|
||||
.min(4)
|
||||
.max(255),
|
||||
birthdate: Joi.date(),
|
||||
gender: Joi.string().valid("male", "female"),
|
||||
phoneCC: Joi.string()
|
||||
.min(2)
|
||||
.max(2),
|
||||
phoneNumber: Joi.string()
|
||||
.min(7)
|
||||
.max(15),
|
||||
bioProfile: Joi.string().max(300),
|
||||
deletedAt: Joi.date(),
|
||||
|
||||
// validate in helper
|
||||
avatar: Joi.any(),
|
||||
commentBackground: Joi.any(),
|
||||
});
|
||||
5
src/modules/user/schemas/getUserById.schema.ts
Normal file
5
src/modules/user/schemas/getUserById.schema.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import z from "zod";
|
||||
|
||||
export const getUserByIdSchema = z.object({
|
||||
email: z.email(),
|
||||
});
|
||||
20
src/modules/user/schemas/getUserOptions.schema.ts
Normal file
20
src/modules/user/schemas/getUserOptions.schema.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import z from "zod";
|
||||
|
||||
const includeEnum = z.enum(
|
||||
["preference", "roles"],
|
||||
"option: include value didn't match with enum types"
|
||||
);
|
||||
|
||||
export const getUserOptionsSchema = z.object({
|
||||
verbosity: z
|
||||
.enum(
|
||||
["exists", "basic", "full"],
|
||||
"option: verbosity value didn't match with enum types"
|
||||
)
|
||||
.optional(),
|
||||
include: z.preprocess((val) => {
|
||||
if (Array.isArray(val)) return val;
|
||||
if (typeof val === "string") return [val];
|
||||
return [];
|
||||
}, z.array(includeEnum).optional()),
|
||||
});
|
||||
@ -1,7 +1,7 @@
|
||||
import { ErrorForwarder } from "../../../helpers/error/instances/forwarder";
|
||||
import { hashPassword } from "../../../helpers/security/password/hash";
|
||||
import { createUserViaRegisterRepository } from "../repositories/create/createUserViaRegister.repository";
|
||||
import { createUserViaRegisterInput } from "../user.types";
|
||||
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
||||
import { hashPassword } from "../../../../helpers/security/password/hash";
|
||||
import { createUserViaRegisterRepository } from "../../repositories/create/createUserViaRegister.repository";
|
||||
import { createUserViaRegisterInput } from "../../user.types";
|
||||
|
||||
export const createUserViaRegisterService = async (
|
||||
payload: createUserViaRegisterInput
|
||||
|
||||
8
src/modules/user/services/http/getUserByEmail.service.ts
Normal file
8
src/modules/user/services/http/getUserByEmail.service.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { getUserDataOptions } from "../../user.types";
|
||||
|
||||
export const getUserByEmailService = async (
|
||||
email: string,
|
||||
options: getUserDataOptions
|
||||
) => {
|
||||
return email;
|
||||
};
|
||||
@ -5,7 +5,7 @@ export interface getUserDataService {
|
||||
}
|
||||
export interface getUserDataOptions {
|
||||
verbosity?: "exists" | "basic" | "full";
|
||||
include?: ("preference" | "role")[];
|
||||
include?: ("preference" | "roles")[];
|
||||
}
|
||||
|
||||
export interface createUserViaRegisterInput {
|
||||
|
||||
Reference in New Issue
Block a user