refactor(FE-212): add DeletePurchaseRequestItemPayload and implement PurchaseDeleteItemsService

This commit is contained in:
rstubryan
2025-11-17 10:13:30 +07:00
parent 69a8899cac
commit 30ed70b669
6 changed files with 82 additions and 20 deletions
+36 -8
View File
@@ -5,6 +5,7 @@ import {
CreateStaffApprovalRequestPayload,
CreateManagerApprovalRequestPayload,
CreateAcceptApprovalRequestPayload,
DeletePurchaseRequestItemPayload,
} from '@/types/api/purchase/purchase';
import { BaseApiService } from '@/services/api/base';
import { BaseApiResponse } from '@/types/api/api-general';
@@ -18,18 +19,18 @@ export const PurchaseRequestApi = new BaseApiService<
export class StaffApprovalService extends BaseApiService<
Purchase,
CreateStaffApprovalRequestPayload,
CreateAcceptApprovalRequestPayload
unknown
> {
constructor(basePath: string = '') {
super(basePath);
}
async createStaffApproval(
purchaseRequisitionId: number,
purchaseRequestId: number,
payload: CreateStaffApprovalRequestPayload
): Promise<BaseApiResponse<{ message: string }> | undefined> {
return await this.customRequest<BaseApiResponse<{ message: string }>>(
`${purchaseRequisitionId}/approvals/staff`,
`${purchaseRequestId}/approvals/staff`,
{
method: 'POST',
payload,
@@ -48,11 +49,11 @@ export class ManagerApprovalService extends BaseApiService<
}
async createManagerApproval(
purchaseRequisitionId: number,
purchaseRequestId: number,
payload: CreateManagerApprovalRequestPayload
): Promise<BaseApiResponse<{ message: string }> | undefined> {
return await this.customRequest<BaseApiResponse<{ message: string }>>(
`${purchaseRequisitionId}/approvals/manager`,
`${purchaseRequestId}/approvals/manager`,
{
method: 'POST',
payload,
@@ -64,18 +65,41 @@ export class ManagerApprovalService extends BaseApiService<
export class AcceptApprovalService extends BaseApiService<
Purchase,
CreateAcceptApprovalRequestPayload,
CreateAcceptApprovalRequestPayload
unknown
> {
constructor(basePath: string = '') {
super(basePath);
}
async acceptApproval(
purchaseRequisitionId: number,
purchaseRequestId: number,
payload: CreateAcceptApprovalRequestPayload
): Promise<BaseApiResponse<{ message: string }> | undefined> {
return await this.customRequest<BaseApiResponse<{ message: string }>>(
`${purchaseRequisitionId}/approvals/receipts`,
`${purchaseRequestId}/approvals/receipts`,
{
method: 'POST',
payload,
}
);
}
}
export class PurchaseDeleteItemsService extends BaseApiService<
Purchase,
DeletePurchaseRequestItemPayload,
unknown
> {
constructor(basePath: string = '') {
super(basePath);
}
async deleteItems(
purchaseRequestId: number,
payload: DeletePurchaseRequestItemPayload
): Promise<BaseApiResponse<{ message: string }> | undefined> {
return await this.customRequest<BaseApiResponse<{ message: string }>>(
`${purchaseRequestId}/items`,
{
method: 'POST',
payload,
@@ -89,3 +113,7 @@ export const StaffApprovalApi = new StaffApprovalService('/purchases');
export const ManagerApprovalApi = new ManagerApprovalService('/purchases');
export const AcceptApprovalApi = new AcceptApprovalService('/purchases');
export const PurchaseDeleteItemsApi = new PurchaseDeleteItemsService(
'/purchases'
);