first commit
This commit is contained in:
85
frontend/app/utils/api/productsResourceAllocation/index.tsx
Normal file
85
frontend/app/utils/api/productsResourceAllocation/index.tsx
Normal file
@@ -0,0 +1,85 @@
|
||||
|
||||
import { UUID } from "crypto";
|
||||
import { baseApiRequest } from "../apiRequests/baseApiRequest";
|
||||
|
||||
const PRODUCT_API = `${process.env.NEXT_PUBLIC_PROJECT_MANAGEMENT_API_URL}/api/v1/products`;
|
||||
|
||||
// Allocation payload shape
|
||||
export interface ProductAllocation {
|
||||
id?: string;
|
||||
allocation: Record<string, number>;
|
||||
detailedAllocation: Record<string, Record<string, any>>;
|
||||
resourceType: string;
|
||||
role: string;
|
||||
gradeId: number;
|
||||
employeeName: string;
|
||||
taskName: string;
|
||||
resourceId: string;
|
||||
taskId: number;
|
||||
}
|
||||
|
||||
// List allocations for a product
|
||||
export const getResourceAllocations = async (productIdentifier: UUID) => {
|
||||
return baseApiRequest(
|
||||
`${PRODUCT_API}/${productIdentifier}/resource-allocations`,
|
||||
{
|
||||
method: "GET",
|
||||
cache: "no-store",
|
||||
},
|
||||
{ isAccessTokenRequird: true }
|
||||
);
|
||||
};
|
||||
|
||||
// Get a single allocation
|
||||
export const getAllocation = async (productIdentifier: UUID, allocationIdentifier: UUID) => {
|
||||
return baseApiRequest(
|
||||
`${PRODUCT_API}/${productIdentifier}/resource-allocations/${allocationIdentifier}`,
|
||||
{
|
||||
method: "GET",
|
||||
cache: "no-store",
|
||||
},
|
||||
{ isAccessTokenRequird: true }
|
||||
);
|
||||
};
|
||||
|
||||
// Create allocation
|
||||
export const createAllocation = async (productIdentifier: UUID, allocation: ProductAllocation) => {
|
||||
return baseApiRequest(
|
||||
`${PRODUCT_API}/${productIdentifier}/resource-allocations`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify(allocation),
|
||||
},
|
||||
{ isAccessTokenRequird: true }
|
||||
);
|
||||
};
|
||||
|
||||
// Update allocation
|
||||
export const updateAllocation = async (
|
||||
productIdentifier: UUID,
|
||||
allocationIdentifier: UUID,
|
||||
updatedAllocation: ProductAllocation
|
||||
) => {
|
||||
return baseApiRequest(
|
||||
`${PRODUCT_API}/${productIdentifier}/resource-allocations/${allocationIdentifier}`,
|
||||
{
|
||||
method: "PUT",
|
||||
body: JSON.stringify(updatedAllocation),
|
||||
},
|
||||
{ isAccessTokenRequird: true }
|
||||
);
|
||||
};
|
||||
|
||||
// Delete allocation
|
||||
export const deleteAllocation = async (productIdentifier: UUID, allocationIdentifier: UUID) => {
|
||||
return baseApiRequest(
|
||||
`${PRODUCT_API}/${productIdentifier}/resource-allocations/${allocationIdentifier}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
},
|
||||
{ isAccessTokenRequird: true }
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user