mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 07:15:44 +00:00
refactor(FE-212): simplify PurchaseRequestService to a constant API instance
This commit is contained in:
@@ -9,45 +9,11 @@ import {
|
|||||||
import { BaseApiService } from '@/services/api/base';
|
import { BaseApiService } from '@/services/api/base';
|
||||||
import { BaseApiResponse } from '@/types/api/api-general';
|
import { BaseApiResponse } from '@/types/api/api-general';
|
||||||
|
|
||||||
export class PurchaseRequestService extends BaseApiService<
|
export const PurchaseRequestApi = new BaseApiService<
|
||||||
Purchase,
|
Purchase,
|
||||||
CreatePurchaseRequestPayload,
|
CreatePurchaseRequestPayload,
|
||||||
UpdatePurchaseRequestPayload
|
UpdatePurchaseRequestPayload
|
||||||
> {
|
>('/purchases');
|
||||||
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,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class StaffApprovalService extends BaseApiService<
|
export class StaffApprovalService extends BaseApiService<
|
||||||
Purchase,
|
Purchase,
|
||||||
@@ -118,8 +84,6 @@ export class AcceptApprovalService extends BaseApiService<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PurchaseRequestApi = new PurchaseRequestService();
|
|
||||||
|
|
||||||
export const StaffApprovalApi = new StaffApprovalService('/purchases');
|
export const StaffApprovalApi = new StaffApprovalService('/purchases');
|
||||||
|
|
||||||
export const ManagerApprovalApi = new ManagerApprovalService('/purchases');
|
export const ManagerApprovalApi = new ManagerApprovalService('/purchases');
|
||||||
|
|||||||
Reference in New Issue
Block a user