💩 (user) i dont know what im commited
This commit is contained in:
@ -201,7 +201,7 @@ model User {
|
|||||||
gender UserGender?
|
gender UserGender?
|
||||||
phoneCC Int?
|
phoneCC Int?
|
||||||
phoneNumber Int?
|
phoneNumber Int?
|
||||||
roles UserRoleAssignment[]
|
assignedRoles UserRoleAssignment[]
|
||||||
bioProfile String? @db.Text
|
bioProfile String? @db.Text
|
||||||
avatar String? @db.Text
|
avatar String? @db.Text
|
||||||
commentBackground String? @db.Text
|
commentBackground String? @db.Text
|
||||||
@ -284,7 +284,7 @@ model UserRole {
|
|||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @default(now()) @updatedAt
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
|
|
||||||
users UserRoleAssignment[]
|
assignedUser UserRoleAssignment[]
|
||||||
@@map("user_roles")
|
@@map("user_roles")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,12 @@
|
|||||||
import { Context } from "elysia";
|
import { Context } from "elysia";
|
||||||
|
import { findUserByEmailService } from "../services/findUserByEmail.service";
|
||||||
|
import { mainErrorHandler } from "../../../helpers/error/handler";
|
||||||
|
|
||||||
export const findUserByEmailController = async (ctx: Context) => {
|
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 { userModel } from "../user.model";
|
||||||
|
import { FindUserByEmailOrUsernameOptions } from "../user.types";
|
||||||
|
|
||||||
export const findUserByEmailOrUsernameRepo = async (
|
export const findUserByEmailOrUsernameRepository = async (
|
||||||
identifier: string,
|
identifier: string,
|
||||||
options: FindUserByEmailOrUsernameOptions
|
options: FindUserByEmailOrUsernameOptions
|
||||||
) => {
|
) => {
|
||||||
const userData =
|
const userData = await userModel.findUnique({
|
||||||
(await userModel.findUnique({
|
where: { email: identifier },
|
||||||
where: { email: identifier },
|
include: {
|
||||||
include: {
|
assignedRoles: {
|
||||||
roles: {
|
select: {
|
||||||
omit: {
|
role: {
|
||||||
createdBy: !options.verbose,
|
omit: {
|
||||||
createdAt: !options.verbose,
|
createdBy: true,
|
||||||
updatedAt: !options.verbose,
|
updatedAt: true,
|
||||||
deletedAt: !options.verbose,
|
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;
|
if (!userData) return false;
|
||||||
return userData;
|
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 { AppError } from "../../../helpers/error/instances/app";
|
||||||
import { ErrorForwarder } from "../../../helpers/error/instances/forwarder";
|
import { ErrorForwarder } from "../../../helpers/error/instances/forwarder";
|
||||||
import { findUserByEmailOrUsernameRepo } from "../repositories/findUserByEmailOrUsername.repository";
|
import { findUserByEmailOrUsernameRepository } from "../repositories/findUserByEmailOrUsername.repository";
|
||||||
|
import { FindUserByEmailOrUsernameOptions } from "../user.types";
|
||||||
export interface FindUserByEmailOrUsernameOptions {
|
|
||||||
verbose?: boolean; // If true, returns the user with all details including sensitive information
|
|
||||||
}
|
|
||||||
|
|
||||||
export const findUserByEmailOrUsernameService = async (
|
export const findUserByEmailOrUsernameService = async (
|
||||||
identifier: string,
|
identifier: string,
|
||||||
options: FindUserByEmailOrUsernameOptions = {}
|
options: FindUserByEmailOrUsernameOptions
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const userData = await findUserByEmailOrUsernameRepo(identifier, options);
|
const userData = await findUserByEmailOrUsernameRepository(
|
||||||
|
identifier,
|
||||||
|
options
|
||||||
|
);
|
||||||
if (!userData) throw new AppError(404, "User not found");
|
if (!userData) throw new AppError(404, "User not found");
|
||||||
|
|
||||||
return userData;
|
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