mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-22 14:25:47 +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'
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user