mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-23 23:05:46 +00:00
refactor(FE-212,213): unify purchase API service references in Purchase components
This commit is contained in:
+64
-100
@@ -11,123 +11,87 @@ import {
|
||||
import { BaseApiService } from '@/services/api/base';
|
||||
import { BaseApiResponse } from '@/types/api/api-general';
|
||||
|
||||
export const PurchaseRequestApi = new BaseApiService<
|
||||
const basePurchaseApi = new BaseApiService<
|
||||
Purchase,
|
||||
CreatePurchaseRequestPayload,
|
||||
UpdatePurchaseRequestPayload
|
||||
>('/purchases');
|
||||
|
||||
export class StaffApprovalService extends BaseApiService<
|
||||
Purchase,
|
||||
CreateStaffApprovalRequestPayload,
|
||||
UpdateStaffApprovalRequestPayload
|
||||
> {
|
||||
constructor(basePath: string = '') {
|
||||
super(basePath);
|
||||
}
|
||||
export const PurchaseApi = {
|
||||
basePath: basePurchaseApi.basePath,
|
||||
header: basePurchaseApi.header,
|
||||
getAllFetcher: basePurchaseApi.getAllFetcher.bind(basePurchaseApi),
|
||||
getSingle: basePurchaseApi.getSingle.bind(basePurchaseApi),
|
||||
create: basePurchaseApi.create.bind(basePurchaseApi),
|
||||
update: basePurchaseApi.update.bind(basePurchaseApi),
|
||||
delete: basePurchaseApi.delete.bind(basePurchaseApi),
|
||||
customRequest: basePurchaseApi.customRequest.bind(basePurchaseApi),
|
||||
|
||||
async createStaffApproval(
|
||||
purchaseRequestId: number,
|
||||
payload: CreateStaffApprovalRequestPayload
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||
return await this.customRequest<BaseApiResponse<{ message: string }>>(
|
||||
`${purchaseRequestId}/approvals/staff`,
|
||||
{
|
||||
staffApproval: {
|
||||
create: async (
|
||||
purchaseRequestId: number,
|
||||
payload: CreateStaffApprovalRequestPayload
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> => {
|
||||
return await basePurchaseApi.customRequest<
|
||||
BaseApiResponse<{ message: string }>
|
||||
>(`${purchaseRequestId}/approvals/staff`, {
|
||||
method: 'POST',
|
||||
payload,
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
async updateStaffApproval(
|
||||
purchaseRequestId: number,
|
||||
payload: UpdateStaffApprovalRequestPayload
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||
return await this.customRequest<BaseApiResponse<{ message: string }>>(
|
||||
`${purchaseRequestId}/approvals/staff`,
|
||||
{
|
||||
update: async (
|
||||
purchaseRequestId: number,
|
||||
payload: UpdateStaffApprovalRequestPayload
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> => {
|
||||
return await basePurchaseApi.customRequest<
|
||||
BaseApiResponse<{ message: string }>
|
||||
>(`${purchaseRequestId}/approvals/staff`, {
|
||||
method: 'POST',
|
||||
payload,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
export class ManagerApprovalService extends BaseApiService<
|
||||
Purchase,
|
||||
CreateManagerApprovalRequestPayload,
|
||||
CreateManagerApprovalRequestPayload
|
||||
> {
|
||||
constructor(basePath: string = '') {
|
||||
super(basePath);
|
||||
}
|
||||
|
||||
async createManagerApproval(
|
||||
purchaseRequestId: number,
|
||||
payload: CreateManagerApprovalRequestPayload
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||
return await this.customRequest<BaseApiResponse<{ message: string }>>(
|
||||
`${purchaseRequestId}/approvals/manager`,
|
||||
{
|
||||
managerApproval: {
|
||||
create: async (
|
||||
purchaseRequestId: number,
|
||||
payload: CreateManagerApprovalRequestPayload
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> => {
|
||||
return await basePurchaseApi.customRequest<
|
||||
BaseApiResponse<{ message: string }>
|
||||
>(`${purchaseRequestId}/approvals/manager`, {
|
||||
method: 'POST',
|
||||
payload,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
export class AcceptApprovalService extends BaseApiService<
|
||||
Purchase,
|
||||
CreateAcceptApprovalRequestPayload,
|
||||
unknown
|
||||
> {
|
||||
constructor(basePath: string = '') {
|
||||
super(basePath);
|
||||
}
|
||||
|
||||
async acceptApproval(
|
||||
purchaseRequestId: number,
|
||||
payload: CreateAcceptApprovalRequestPayload
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||
return await this.customRequest<BaseApiResponse<{ message: string }>>(
|
||||
`${purchaseRequestId}/receipts`,
|
||||
{
|
||||
acceptApproval: {
|
||||
create: async (
|
||||
purchaseRequestId: number,
|
||||
payload: CreateAcceptApprovalRequestPayload
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> => {
|
||||
return await basePurchaseApi.customRequest<
|
||||
BaseApiResponse<{ message: string }>
|
||||
>(`${purchaseRequestId}/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`,
|
||||
{
|
||||
items: {
|
||||
delete: async (
|
||||
purchaseRequestId: number,
|
||||
payload: DeletePurchaseRequestItemPayload
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> => {
|
||||
return await basePurchaseApi.customRequest<
|
||||
BaseApiResponse<{ message: string }>
|
||||
>(`${purchaseRequestId}/items`, {
|
||||
method: 'DELETE',
|
||||
payload,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const StaffApprovalApi = new StaffApprovalService('/purchases');
|
||||
|
||||
export const ManagerApprovalApi = new ManagerApprovalService('/purchases');
|
||||
|
||||
export const AcceptApprovalApi = new AcceptApprovalService('/purchases');
|
||||
|
||||
export const PurchaseDeleteItemsApi = new PurchaseDeleteItemsService(
|
||||
'/purchases'
|
||||
);
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user