task-fix
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { AuthError } from '@/lib/auth/session';
|
||||
import { getActiveOptionsByCategory } from '@/features/foundation/master-options/service';
|
||||
import { AuthError } from '@/lib/auth/session';
|
||||
import type { FoundationBranch } from './types';
|
||||
|
||||
function mapBranchOption(
|
||||
@@ -13,14 +13,17 @@ function mapBranchOption(
|
||||
};
|
||||
}
|
||||
|
||||
export async function getUserBranches(): Promise<FoundationBranch[]> {
|
||||
const options = await getActiveOptionsByCategory('crm_branch');
|
||||
export async function getUserBranches(organizationId?: string): Promise<FoundationBranch[]> {
|
||||
const options = await getActiveOptionsByCategory(
|
||||
'crm_branch',
|
||||
organizationId ? { organizationId } : undefined
|
||||
);
|
||||
|
||||
return options.map(mapBranchOption);
|
||||
}
|
||||
|
||||
export async function getActiveBranch(): Promise<FoundationBranch | null> {
|
||||
const branches = await getUserBranches();
|
||||
export async function getActiveBranch(organizationId?: string): Promise<FoundationBranch | null> {
|
||||
const branches = await getUserBranches(organizationId);
|
||||
|
||||
if (branches.length === 1) {
|
||||
return branches[0];
|
||||
@@ -29,12 +32,12 @@ export async function getActiveBranch(): Promise<FoundationBranch | null> {
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function validateBranchAccess(branchId?: string | null) {
|
||||
export async function validateBranchAccess(branchId?: string | null, organizationId?: string) {
|
||||
if (!branchId) {
|
||||
return getActiveBranch();
|
||||
return getActiveBranch(organizationId);
|
||||
}
|
||||
|
||||
const branches = await getUserBranches();
|
||||
const branches = await getUserBranches(organizationId);
|
||||
const branch = branches.find((item) => item.id === branchId);
|
||||
|
||||
if (!branch) {
|
||||
|
||||
Reference in New Issue
Block a user