add:module:user:repository:checkUserEmailAndUsernameAvailabillity | add repository for check username and email availabillity

This commit is contained in:
rafiarrafif
2025-06-16 21:37:53 +07:00
parent ac10ae14f6
commit f0e1614709
13 changed files with 143 additions and 24 deletions

View File

@ -0,0 +1,23 @@
import { Prisma } from "@prisma/client";
import { userModel } from "../user.model";
export const checkUserEmailAndUsernameAvailabillity = async (
payload: Partial<Prisma.UserGetPayload<Record<string, never>>>
) => {
try {
const checkUsernameAndEmailAvailabillity = await userModel.findFirst({
where: {
OR: [
{ username: payload.username ?? undefined },
{ email: payload.email ?? undefined },
],
NOT: {
id: payload.id,
},
},
});
return checkUsernameAndEmailAvailabillity;
} catch (error) {
throw error;
}
};

View File

@ -0,0 +1,23 @@
import { Prisma } from "@prisma/client";
import { userModel } from "../user.model";
export const updateUserRepo = async (
identifier: string,
payload: Prisma.UserUncheckedCreateInput
) => {
try {
const userData = await userModel.update({
where: {
username: identifier,
},
data: {
username: payload.username,
name: payload.name,
birthDate: payload.name,
},
});
return userData;
} catch (error) {
throw error;
}
};