refactor(FE-212): simplify PurchaseRequestService to a constant API instance

This commit is contained in:
rstubryan
2025-11-17 09:39:16 +07:00
parent 9f41768e54
commit 69a8899cac
+2 -38
View File
@@ -9,45 +9,11 @@ import {
import { BaseApiService } from '@/services/api/base';
import { BaseApiResponse } from '@/types/api/api-general';
export class PurchaseRequestService extends BaseApiService<
export const PurchaseRequestApi = new BaseApiService<
Purchase,
CreatePurchaseRequestPayload,
UpdatePurchaseRequestPayload
> {
constructor(basePath: string = '/purchases') {
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,
},
});
}
}
>('/purchases');
export class StaffApprovalService extends BaseApiService<
Purchase,
@@ -118,8 +84,6 @@ export class AcceptApprovalService extends BaseApiService<
}
}
export const PurchaseRequestApi = new PurchaseRequestService();
export const StaffApprovalApi = new StaffApprovalService('/purchases');
export const ManagerApprovalApi = new ManagerApprovalService('/purchases');