Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import type { Prisma } from "../generated/prisma/client/client.js";
|
||||
|
||||
export type AdminSalesAccessScope = {
|
||||
readonly adminUserId: string;
|
||||
readonly canReadAll: boolean;
|
||||
readonly canWriteAll: boolean;
|
||||
readonly canReadAllCommunication: boolean;
|
||||
};
|
||||
|
||||
export const UNRESTRICTED_ADMIN_SALES_ACCESS = Object.freeze({
|
||||
adminUserId: "",
|
||||
canReadAll: true,
|
||||
canWriteAll: true,
|
||||
canReadAllCommunication: true,
|
||||
}) satisfies AdminSalesAccessScope;
|
||||
|
||||
export function adminSalesLeadReadWhere(
|
||||
scope: AdminSalesAccessScope
|
||||
): Prisma.AdminLeadWhereInput {
|
||||
return scope.canReadAll
|
||||
? {}
|
||||
: { assignedToAdminUserId: scope.adminUserId };
|
||||
}
|
||||
|
||||
export function adminSalesDealReadWhere(
|
||||
scope: AdminSalesAccessScope
|
||||
): Prisma.AdminDealWhereInput {
|
||||
return scope.canReadAll ? {} : { ownerAdminUserId: scope.adminUserId };
|
||||
}
|
||||
|
||||
export function adminSalesTaskReadWhere(
|
||||
scope: AdminSalesAccessScope
|
||||
): Prisma.AdminTaskWhereInput {
|
||||
return scope.canReadAll
|
||||
? {}
|
||||
: { assignedToAdminUserId: scope.adminUserId };
|
||||
}
|
||||
|
||||
export function adminCommunicationReadWhere(
|
||||
scope: AdminSalesAccessScope
|
||||
): { readonly adminUserId?: string } {
|
||||
return scope.canReadAllCommunication ? {} : { adminUserId: scope.adminUserId };
|
||||
}
|
||||
|
||||
export function assertAdminSalesWriteOwner(
|
||||
ownerAdminUserId: string | null,
|
||||
scope: AdminSalesAccessScope
|
||||
): void {
|
||||
if (!scope.canWriteAll && ownerAdminUserId !== scope.adminUserId) {
|
||||
throw new AdminSalesScopeNotFoundError();
|
||||
}
|
||||
}
|
||||
|
||||
export class AdminSalesScopeNotFoundError extends Error {
|
||||
public override readonly name = "AdminSalesScopeNotFoundError";
|
||||
|
||||
public constructor() {
|
||||
super("Admin sales record was not found.");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user