💩 (user) i dont know what im commited
This commit is contained in:
@ -201,7 +201,7 @@ model User {
|
||||
gender UserGender?
|
||||
phoneCC Int?
|
||||
phoneNumber Int?
|
||||
roles UserRoleAssignment[]
|
||||
assignedRoles UserRoleAssignment[]
|
||||
bioProfile String? @db.Text
|
||||
avatar String? @db.Text
|
||||
commentBackground String? @db.Text
|
||||
@ -284,7 +284,7 @@ model UserRole {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
|
||||
users UserRoleAssignment[]
|
||||
assignedUser UserRoleAssignment[]
|
||||
@@map("user_roles")
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,12 @@
|
||||
import { Context } from "elysia";
|
||||
import { findUserByEmailService } from "../services/findUserByEmail.service";
|
||||
import { mainErrorHandler } from "../../../helpers/error/handler";
|
||||
|
||||
export const findUserByEmailController = async (ctx: Context) => {
|
||||
return `Your email ${ctx.params.email}`;
|
||||
try {
|
||||
const findUserByEmail = await findUserByEmailService(ctx.params.email);
|
||||
return findUserByEmail;
|
||||
} catch (error) {
|
||||
return mainErrorHandler(ctx.set, error);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,37 +1,27 @@
|
||||
import { FindUserByEmailOrUsernameOptions } from "../services/findUserByEmailOrUsername.service";
|
||||
import { userModel } from "../user.model";
|
||||
import { FindUserByEmailOrUsernameOptions } from "../user.types";
|
||||
|
||||
export const findUserByEmailOrUsernameRepo = async (
|
||||
export const findUserByEmailOrUsernameRepository = async (
|
||||
identifier: string,
|
||||
options: FindUserByEmailOrUsernameOptions
|
||||
) => {
|
||||
const userData =
|
||||
(await userModel.findUnique({
|
||||
const userData = await userModel.findUnique({
|
||||
where: { email: identifier },
|
||||
include: {
|
||||
roles: {
|
||||
assignedRoles: {
|
||||
select: {
|
||||
role: {
|
||||
omit: {
|
||||
createdBy: !options.verbose,
|
||||
createdAt: !options.verbose,
|
||||
updatedAt: !options.verbose,
|
||||
deletedAt: !options.verbose,
|
||||
createdBy: true,
|
||||
updatedAt: true,
|
||||
createdAt: true,
|
||||
deletedAt: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})) ||
|
||||
(await userModel.findUnique({
|
||||
where: { username: identifier },
|
||||
include: {
|
||||
roles: {
|
||||
omit: {
|
||||
createdBy: !options.verbose,
|
||||
createdAt: !options.verbose,
|
||||
updatedAt: !options.verbose,
|
||||
deletedAt: !options.verbose,
|
||||
},
|
||||
},
|
||||
},
|
||||
}));
|
||||
});
|
||||
|
||||
if (!userData) return false;
|
||||
return userData;
|
||||
|
||||
13
src/modules/user/services/findUserByEmail.service.ts
Normal file
13
src/modules/user/services/findUserByEmail.service.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { ErrorForwarder } from "../../../helpers/error/instances/forwarder";
|
||||
import { findUserByEmailOrUsernameRepository } from "../repositories/findUserByEmailOrUsername.repository";
|
||||
|
||||
export const findUserByEmailService = async (email: string) => {
|
||||
try {
|
||||
const findUserByEmail = findUserByEmailOrUsernameRepository(email, {
|
||||
queryTarget: "email",
|
||||
});
|
||||
return findUserByEmail;
|
||||
} catch (error) {
|
||||
ErrorForwarder(error);
|
||||
}
|
||||
};
|
||||
@ -1,17 +1,17 @@
|
||||
import { AppError } from "../../../helpers/error/instances/app";
|
||||
import { ErrorForwarder } from "../../../helpers/error/instances/forwarder";
|
||||
import { findUserByEmailOrUsernameRepo } from "../repositories/findUserByEmailOrUsername.repository";
|
||||
|
||||
export interface FindUserByEmailOrUsernameOptions {
|
||||
verbose?: boolean; // If true, returns the user with all details including sensitive information
|
||||
}
|
||||
import { findUserByEmailOrUsernameRepository } from "../repositories/findUserByEmailOrUsername.repository";
|
||||
import { FindUserByEmailOrUsernameOptions } from "../user.types";
|
||||
|
||||
export const findUserByEmailOrUsernameService = async (
|
||||
identifier: string,
|
||||
options: FindUserByEmailOrUsernameOptions = {}
|
||||
options: FindUserByEmailOrUsernameOptions
|
||||
) => {
|
||||
try {
|
||||
const userData = await findUserByEmailOrUsernameRepo(identifier, options);
|
||||
const userData = await findUserByEmailOrUsernameRepository(
|
||||
identifier,
|
||||
options
|
||||
);
|
||||
if (!userData) throw new AppError(404, "User not found");
|
||||
|
||||
return userData;
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
export interface FindUserByEmailOrUsernameOptions {
|
||||
queryTarget: "email" | "username" | "both";
|
||||
verbosity?: FindUserByEmailOrUsernameVerbosity; // If true, returns the user with all details including sensitive information
|
||||
}
|
||||
enum FindUserByEmailOrUsernameVerbosity {
|
||||
"exists",
|
||||
"basic",
|
||||
"extended",
|
||||
"full",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user