umami/queries/admin/userRole.ts
2022-11-20 22:24:31 -08:00

53 lines
1.2 KiB
TypeScript

import { Prisma, UserRole } from '@prisma/client';
import prisma from 'lib/prisma';
export async function createUserRole(
data: Prisma.UserRoleCreateInput | Prisma.UserRoleUncheckedCreateInput,
): Promise<UserRole> {
return prisma.client.userRole.create({
data,
});
}
export async function getUserRole(where: Prisma.UserRoleWhereInput): Promise<UserRole> {
return prisma.client.userRole.findFirst({
where,
});
}
export async function getUserRoles(where: Prisma.UserRoleWhereInput): Promise<UserRole[]> {
return prisma.client.userRole.findMany({
where,
});
}
export async function getUserRolesByUserId(userId: string, teamId?: string): Promise<UserRole[]> {
return prisma.client.userRole.findMany({
where: {
userId,
teamId,
},
});
}
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,
},
});
}