mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
126 lines
3.2 KiB
TypeScript
126 lines
3.2 KiB
TypeScript
import { dummyMarketings } from '@/dummy/marketing.dummy';
|
|
import { sleep } from '@/lib/helper';
|
|
import { BaseApiService } from '@/services/api/base';
|
|
import { httpClient } from '@/services/http/client';
|
|
import { BaseApiResponse } from '@/types/api/api-general';
|
|
import {
|
|
Marketing,
|
|
CreateMarketingPayload,
|
|
UpdateMarketingPayload,
|
|
} from '@/types/api/marketing/marketing';
|
|
|
|
export class MarketingService extends BaseApiService<
|
|
Marketing,
|
|
CreateMarketingPayload,
|
|
UpdateMarketingPayload
|
|
> {
|
|
constructor(basePath: string = '/marketing') {
|
|
super(basePath);
|
|
}
|
|
|
|
/**
|
|
* Override: Get all marketing data (dummy mode)
|
|
*/
|
|
override async getAllFetcher(
|
|
endpoint: string
|
|
): Promise<BaseApiResponse<Marketing[]>> {
|
|
// simulasi loading
|
|
await sleep(750);
|
|
|
|
// data dummy sementara
|
|
const DUMMY_MARKETING_DATA: BaseApiResponse<Marketing[]> = {
|
|
code: 200,
|
|
status: 'success',
|
|
message: 'Berhasil mengambil data marketing (dummy)',
|
|
data: dummyMarketings,
|
|
};
|
|
|
|
return DUMMY_MARKETING_DATA;
|
|
}
|
|
|
|
/**
|
|
* Override: Get single marketing data (dummy mode)
|
|
*/
|
|
override async getSingle(
|
|
id: number
|
|
): Promise<BaseApiResponse<Marketing> | undefined> {
|
|
// simulasi delay
|
|
await new Promise((res) => setTimeout(res, 500));
|
|
|
|
const marketing = dummyMarketings.find((marketing) => {
|
|
console.log('marketing', marketing);
|
|
console.log('id-m', marketing.id);
|
|
console.log('id-p', id);
|
|
console.log('id', marketing.id == id);
|
|
return marketing.id == id;
|
|
});
|
|
console.log('marketings', dummyMarketings);
|
|
console.log('marketing', marketing);
|
|
|
|
if (marketing) {
|
|
// misalnya fetch dari dummy
|
|
return {
|
|
code: 200,
|
|
status: 'success',
|
|
message: 'Data marketing berhasil diambil.',
|
|
data: marketing,
|
|
};
|
|
} else {
|
|
// jika tidak ditemukan
|
|
throw {
|
|
code: 404,
|
|
status: 'error',
|
|
message: 'Data marketing tidak ditemukan.',
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Approve single marketing data
|
|
*/
|
|
async singleApproval(
|
|
id: number,
|
|
action: 'approve' | 'reject'
|
|
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
|
try {
|
|
const path = `${this.basePath}/approvals`;
|
|
return await httpClient<BaseApiResponse<{ message: string }>>(path, {
|
|
method: 'POST',
|
|
body: {
|
|
action: action,
|
|
approval_ids: [id],
|
|
notes: `${action} marketing ${id}`,
|
|
},
|
|
});
|
|
} catch (error) {
|
|
console.error('Error approve marketing:', error);
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Bulk approve
|
|
*/
|
|
async bulkApprovals(
|
|
ids: number[],
|
|
action: 'approve' | 'reject'
|
|
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
|
try {
|
|
const path = `${this.basePath}/approvals`;
|
|
return await httpClient<BaseApiResponse<{ message: string }>>(path, {
|
|
method: 'POST',
|
|
body: {
|
|
action: action,
|
|
approval_ids: ids,
|
|
notes: `${action} marketing ${ids.join(', ')}`,
|
|
},
|
|
});
|
|
} catch (error) {
|
|
console.error('Error bulk approve marketing:', error);
|
|
return undefined;
|
|
}
|
|
}
|
|
}
|
|
|
|
export const MarketingApi = new MarketingService('/marketing');
|