add 1 step find user
This commit is contained in:
@ -11,6 +11,10 @@ export const loginWithPassword = async (
|
|||||||
if (error || !ctx.body)
|
if (error || !ctx.body)
|
||||||
return returnErrorResponse(ctx.set, 400, "Invalid user input", error);
|
return returnErrorResponse(ctx.set, 400, "Invalid user input", error);
|
||||||
|
|
||||||
const result = await loginWithPasswordService(ctx.body);
|
try {
|
||||||
return result;
|
const result = await loginWithPasswordService(ctx.body);
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,9 +1,13 @@
|
|||||||
|
import { findUserByEmailOrUsernameService } from "../../user/services/findUserByEmailOrUsername.service";
|
||||||
import { LoginWithPasswordRequest } from "../auth.types";
|
import { LoginWithPasswordRequest } from "../auth.types";
|
||||||
|
|
||||||
export const loginWithPasswordService = async (
|
export const loginWithPasswordService = async (
|
||||||
data: LoginWithPasswordRequest
|
data: LoginWithPasswordRequest
|
||||||
) => {
|
) => {
|
||||||
return `Login with password service called with data: ${JSON.stringify(
|
try {
|
||||||
data
|
const userData = await findUserByEmailOrUsernameService(data.identifier);
|
||||||
)}`;
|
return userData;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -0,0 +1,35 @@
|
|||||||
|
import { userModel } from "../user.model";
|
||||||
|
|
||||||
|
export const findUserByEmailOrUsernameRepo = async (identifier: string) => {
|
||||||
|
const userData =
|
||||||
|
(await userModel.findUnique({
|
||||||
|
where: { email: identifier },
|
||||||
|
include: {
|
||||||
|
roles: {
|
||||||
|
omit: {
|
||||||
|
createdBy: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
deletedAt: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})) ||
|
||||||
|
(await userModel.findUnique({
|
||||||
|
where: { username: identifier },
|
||||||
|
include: {
|
||||||
|
roles: {
|
||||||
|
omit: {
|
||||||
|
createdBy: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
deletedAt: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (!userData) throw "User not found";
|
||||||
|
|
||||||
|
return userData;
|
||||||
|
};
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
import { findUserByEmailOrUsernameRepo } from "../repositories/findUserByEmailOrUsername.repository";
|
||||||
|
|
||||||
|
export const findUserByEmailOrUsernameService = async (identifier: string) => {
|
||||||
|
try {
|
||||||
|
const userData = await findUserByEmailOrUsernameRepo(identifier);
|
||||||
|
return userData;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user