🏗️ reconstruct all system in user module

This commit is contained in:
Rafi Arrafif
2025-07-16 23:42:13 +07:00
parent 558891ade7
commit 29b76fb91a
25 changed files with 85 additions and 548 deletions

View File

@ -1,17 +0,0 @@
import { userModel } from "../user.model";
export const checkUserEmailAndUsernameAvailabillityRepo = async (
id: string,
username: string,
email: string
) => {
const checkUsernameAndEmailAvailabillity = await userModel.findFirst({
where: {
OR: [{ username: username ?? undefined }, { email: email ?? undefined }],
NOT: {
id: id,
},
},
});
return checkUsernameAndEmailAvailabillity;
};

View File

@ -0,0 +1,10 @@
import { userModel } from "../../user.model";
import { createUserViaRegisterInput } from "../../user.types";
export const createUserViaRegisterRepository = async (
payload: createUserViaRegisterInput
) => {
return await userModel.create({
data: payload,
});
};

View File

@ -1,13 +0,0 @@
import { Prisma } from "@prisma/client";
import { userModel } from "../user.model";
export const createUserRepo = async (data: Prisma.UserCreateInput) => {
const userData = await userModel.create({
data,
omit: {
password: true,
},
});
return userData;
};

View File

@ -1,28 +0,0 @@
import { userModel } from "../user.model";
import { FindUserByEmailOrUsernameOptions } from "../user.types";
export const findUserByEmailOrUsernameRepository = async (
identifier: string,
options: FindUserByEmailOrUsernameOptions
) => {
const userData = await userModel.findUnique({
where: { email: identifier },
include: {
assignedRoles: {
select: {
role: {
omit: {
createdBy: true,
updatedAt: true,
createdAt: true,
deletedAt: true,
},
},
},
},
},
});
if (!userData) return false;
return userData;
};

View File

@ -1,11 +0,0 @@
import { userModel } from "../user.model";
export const getAllUserRepo = async () => {
const data = await userModel.findMany({
where: {
deletedAt: null,
},
});
return data;
};

View File

@ -1,16 +0,0 @@
import { Prisma } from "@prisma/client";
import { userModel } from "../user.model";
export const updateUserRepository = async (
username: string,
payload: Prisma.UserUpdateInput
) => {
const userData = await userModel.update({
where: {
username,
},
data: payload,
});
return userData;
};