mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
84 lines
1.9 KiB
TypeScript
84 lines
1.9 KiB
TypeScript
import { Prisma, Permission } from '@prisma/client';
|
|
import prisma from 'lib/prisma';
|
|
|
|
export async function createPermission(data: Prisma.PermissionCreateInput): Promise<Permission> {
|
|
return prisma.client.permission.create({
|
|
data,
|
|
});
|
|
}
|
|
|
|
export async function getPermission(where: Prisma.PermissionWhereUniqueInput): Promise<Permission> {
|
|
return prisma.client.permission.findUnique({
|
|
where,
|
|
});
|
|
}
|
|
|
|
export async function getPermissions(where: Prisma.PermissionWhereInput): Promise<Permission[]> {
|
|
return prisma.client.permission.findMany({
|
|
where,
|
|
});
|
|
}
|
|
|
|
export async function getPermissionsByUserId(userId, name?: string): Promise<Permission[]> {
|
|
return prisma.client.permission.findMany({
|
|
where: {
|
|
...(name ? { name } : {}),
|
|
RolePermission: {
|
|
every: {
|
|
role: {
|
|
is: {
|
|
userRoles: {
|
|
every: {
|
|
userId,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function getPermissionsByTeamId(teamId, name?: string): Promise<Permission[]> {
|
|
return prisma.client.permission.findMany({
|
|
where: {
|
|
...(name ? { name } : {}),
|
|
RolePermission: {
|
|
every: {
|
|
role: {
|
|
is: {
|
|
TeamUser: {
|
|
every: {
|
|
teamId,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function updatePermission(
|
|
data: Prisma.PermissionUpdateInput,
|
|
where: Prisma.PermissionWhereUniqueInput,
|
|
): Promise<Permission> {
|
|
return prisma.client.permission.update({
|
|
data,
|
|
where,
|
|
});
|
|
}
|
|
|
|
export async function deletePermission(permissionId: string): Promise<Permission> {
|
|
return prisma.client.permission.update({
|
|
data: {
|
|
isDeleted: true,
|
|
},
|
|
where: {
|
|
id: permissionId,
|
|
},
|
|
});
|
|
}
|