mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat(FE-212): add staff approval service and payload types for purchase requisitions
This commit is contained in:
@@ -2,8 +2,11 @@ import {
|
||||
CreatePurchaseRequisitionsPayload,
|
||||
Purchase,
|
||||
UpdatePurchaseRequisitionsPayload,
|
||||
CreateStaffApprovalRequisitionsPayload,
|
||||
CreateAcceptApprovalRequisitionsPayload,
|
||||
} from '@/types/api/purchase/purchase';
|
||||
import { BaseApiService } from '@/services/api/base';
|
||||
import { BaseApiResponse } from '@/types/api/api-general';
|
||||
|
||||
export const PurchaseRequisitionsApi = new BaseApiService<
|
||||
Purchase,
|
||||
@@ -11,6 +14,72 @@ export const PurchaseRequisitionsApi = new BaseApiService<
|
||||
UpdatePurchaseRequisitionsPayload
|
||||
>('/purchases/requisitions');
|
||||
|
||||
export const PurchaseOrderApi = new BaseApiService<Purchase, unknown, unknown>(
|
||||
'/purchases/orders'
|
||||
export class StaffApprovalService extends BaseApiService<
|
||||
Purchase,
|
||||
CreateStaffApprovalRequisitionsPayload,
|
||||
CreateAcceptApprovalRequisitionsPayload
|
||||
> {
|
||||
constructor(basePath: string = '') {
|
||||
super(basePath);
|
||||
}
|
||||
|
||||
async approve(
|
||||
idOrIds: number | number[],
|
||||
notes?: string
|
||||
): Promise<BaseApiResponse<Purchase[]> | undefined> {
|
||||
const approvable_ids = Array.isArray(idOrIds) ? idOrIds : [idOrIds];
|
||||
return await this.customRequest<BaseApiResponse<Purchase[]>>('approvals', {
|
||||
method: 'POST',
|
||||
payload: {
|
||||
action: 'APPROVED',
|
||||
approvable_ids,
|
||||
notes,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async reject(
|
||||
idOrIds: number | number[],
|
||||
notes: string = 'Rejected via Form'
|
||||
): Promise<BaseApiResponse<Purchase[]> | undefined> {
|
||||
const approvable_ids = Array.isArray(idOrIds) ? idOrIds : [idOrIds];
|
||||
return await this.customRequest<BaseApiResponse<Purchase[]>>('approvals', {
|
||||
method: 'POST',
|
||||
payload: {
|
||||
action: 'REJECTED',
|
||||
approvable_ids,
|
||||
notes,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async createStaffApproval(
|
||||
purchaseRequisitionId: number,
|
||||
payload: CreateStaffApprovalRequisitionsPayload
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||
return await this.customRequest<BaseApiResponse<{ message: string }>>(
|
||||
`${purchaseRequisitionId}/approvals/staff`,
|
||||
{
|
||||
method: 'POST',
|
||||
payload,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async acceptApproval(
|
||||
purchaseRequisitionId: number,
|
||||
payload: CreateAcceptApprovalRequisitionsPayload
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||
return await this.customRequest<BaseApiResponse<{ message: string }>>(
|
||||
`${purchaseRequisitionId}/approvals/accept`,
|
||||
{
|
||||
method: 'POST',
|
||||
payload,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const StaffApprovalApi = new StaffApprovalService(
|
||||
'/purchases/requisitions'
|
||||
);
|
||||
|
||||
Vendored
+25
@@ -47,5 +47,30 @@ export type CreatePurchaseRequisitionsPayload = {
|
||||
}[];
|
||||
};
|
||||
|
||||
export type CreateStaffApprovalRequisitionsPayload = {
|
||||
notes: string;
|
||||
items: {
|
||||
purchase_item_id: number;
|
||||
price: number;
|
||||
total_price: number;
|
||||
}[];
|
||||
};
|
||||
|
||||
export type CreateAcceptApprovalRequisitionsPayload = {
|
||||
notes?: string;
|
||||
items: {
|
||||
purchase_item_id: number;
|
||||
accepted_date: string;
|
||||
destination_warehouse_id: number;
|
||||
delivery_document_number: string;
|
||||
delivery_vehicle_plate: string;
|
||||
document_index?: number;
|
||||
received_quantity: number;
|
||||
expedition_id: number;
|
||||
transport_cost: number;
|
||||
transport_cost_per_item: number;
|
||||
}[];
|
||||
};
|
||||
|
||||
export type UpdatePurchaseRequisitionsPayload =
|
||||
CreatePurchaseRequisitionsPayload;
|
||||
|
||||
Reference in New Issue
Block a user