umami/queries/admin/userRole.ts

52 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-11-18 07:27:33 +01:00
import { Prisma, UserRole } from '@prisma/client';
import prisma from 'lib/prisma';
2022-11-18 09:27:42 +01:00
export async function createUserRole(
data: Prisma.UserRoleCreateInput | Prisma.UserRoleUncheckedCreateInput,
): Promise<UserRole> {
2022-11-18 07:27:33 +01:00
return prisma.client.userRole.create({
data,
});
}
2022-11-20 09:48:13 +01:00
export async function getUserRole(where: Prisma.UserRoleWhereInput): Promise<UserRole> {
return prisma.client.userRole.findFirst({
2022-11-18 07:27:33 +01:00
where,
});
}
export async function getUserRoles(where: Prisma.UserRoleWhereInput): Promise<UserRole[]> {
return prisma.client.userRole.findMany({
where,
});
}
2022-11-28 22:08:48 +01:00
export async function getUserRolesByUserId(userId: string): Promise<UserRole[]> {
2022-11-21 07:24:31 +01:00
return prisma.client.userRole.findMany({
where: {
userId,
},
});
}
2022-11-18 07:27:33 +01:00
export async function updateUserRole(
data: Prisma.UserRoleUpdateInput,
where: Prisma.UserRoleWhereUniqueInput,
): Promise<UserRole> {
return prisma.client.userRole.update({
data,
where,
});
}
export async function deleteUserRole(userRoleId: string): Promise<UserRole> {
return prisma.client.userRole.update({
data: {
isDeleted: true,
},
where: {
id: userRoleId,
},
});
}