mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
113 lines
2.9 KiB
TypeScript
113 lines
2.9 KiB
TypeScript
import { BaseApiService } from '@/services/api/base';
|
|
import { httpClient } from '@/services/http/client';
|
|
import { BaseApiResponse } from '@/types/api/api-general';
|
|
import {
|
|
Marketing,
|
|
CreateSalesOrderPayload,
|
|
UpdateSalesOrderPayload,
|
|
CreateDeliveryOrderPayload,
|
|
UpdateDeliveryOrderPayload,
|
|
} from '@/types/api/marketing/marketing';
|
|
|
|
/**
|
|
* 💡 Helper untuk membuat respons dummy
|
|
* @param data Data yang akan dimasukkan ke dalam body respons
|
|
*/
|
|
const createDummyResponse = <T>(data: T): BaseApiResponse<T> => ({
|
|
code: 200,
|
|
status: 'success',
|
|
message: 'Data retrieved successfully (MOCK)',
|
|
data: data,
|
|
});
|
|
|
|
export class SalesOrderService extends BaseApiService<
|
|
Marketing,
|
|
CreateSalesOrderPayload,
|
|
UpdateSalesOrderPayload
|
|
> {
|
|
constructor(basePath: string = '/marketing') {
|
|
super(basePath);
|
|
}
|
|
|
|
/**
|
|
* Approve single marketing data
|
|
*/
|
|
async singleApproval(
|
|
id: number,
|
|
action: 'APPROVED' | 'REJECTED',
|
|
notes?: string
|
|
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
|
try {
|
|
const path = `${this.basePath}/approvals`;
|
|
return await httpClient<BaseApiResponse<{ message: string }>>(path, {
|
|
method: 'POST',
|
|
body: {
|
|
action: action,
|
|
approvable_ids: [id],
|
|
notes: notes || `${action} marketing ${id}`,
|
|
},
|
|
});
|
|
} catch (error) {
|
|
console.error('Error approve marketing:', error);
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Bulk approve
|
|
*/
|
|
async bulkApprovals(
|
|
ids: number[],
|
|
action: 'APPROVED' | 'REJECTED',
|
|
notes?: string
|
|
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
|
try {
|
|
const path = `${this.basePath}/approvals`;
|
|
return await httpClient<BaseApiResponse<{ message: string }>>(path, {
|
|
method: 'POST',
|
|
body: {
|
|
action: action,
|
|
approvable_ids: ids,
|
|
notes: notes || `${action} marketing ${ids.join(', ')}`,
|
|
},
|
|
});
|
|
} catch (error) {
|
|
console.error('Error bulk approve marketing:', error);
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Delivery
|
|
*/
|
|
async delivery(
|
|
id: number,
|
|
notes?: string
|
|
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
|
try {
|
|
const path = `${this.basePath}/approvals`;
|
|
return await httpClient<BaseApiResponse<{ message: string }>>(path, {
|
|
method: 'POST',
|
|
body: {
|
|
action: 'APPROVED',
|
|
approvable_ids: [id],
|
|
notes: notes || `Delivery marketing ${id}`,
|
|
},
|
|
});
|
|
} catch (error) {
|
|
console.error('Error delivery marketing:', error);
|
|
return undefined;
|
|
}
|
|
}
|
|
}
|
|
|
|
export const SalesOrderApi = new SalesOrderService('/marketing/sales-orders');
|
|
export const DeliveryOrderApi = new BaseApiService<
|
|
Marketing,
|
|
CreateDeliveryOrderPayload,
|
|
UpdateDeliveryOrderPayload
|
|
>('/marketing/delivery-orders');
|
|
export const MarketingApi = new BaseApiService<Marketing, unknown, unknown>(
|
|
'/marketing'
|
|
);
|