mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 21:41:57 +00:00
fix(resolve): fix resolve MR
This commit is contained in:
@@ -5,82 +5,74 @@ import { httpClient } from '@/services/http/client';
|
||||
import { BaseApiResponse } from '@/types/api/api-general';
|
||||
import {
|
||||
Marketing,
|
||||
CreateMarketingPayload,
|
||||
UpdateMarketingPayload,
|
||||
CreateSalesOrderPayload,
|
||||
UpdateSalesOrderPayload,
|
||||
CreateDeliveryOrderPayload,
|
||||
UpdateDeliveryOrderPayload,
|
||||
} from '@/types/api/marketing/marketing';
|
||||
|
||||
export class MarketingService extends BaseApiService<
|
||||
/**
|
||||
* 💡 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,
|
||||
CreateMarketingPayload,
|
||||
UpdateMarketingPayload
|
||||
CreateSalesOrderPayload,
|
||||
UpdateSalesOrderPayload
|
||||
> {
|
||||
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);
|
||||
// /**
|
||||
// * Override: Mengambil semua data Marketing dari dummyMarketings
|
||||
// */
|
||||
// async getAllFetcher(endpoint: string): Promise<BaseApiResponse<Marketing[]>> {
|
||||
// // Simulasi delay jaringan
|
||||
// await sleep(500);
|
||||
|
||||
// data dummy sementara
|
||||
const DUMMY_MARKETING_DATA: BaseApiResponse<Marketing[]> = {
|
||||
code: 200,
|
||||
status: 'success',
|
||||
message: 'Berhasil mengambil data marketing (dummy)',
|
||||
data: dummyMarketings,
|
||||
};
|
||||
// // Filter data marketing yang valid (jika menggunakan BaseMarketing[])
|
||||
// const data = dummyMarketings as Marketing[];
|
||||
|
||||
return DUMMY_MARKETING_DATA;
|
||||
}
|
||||
// return createDummyResponse<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));
|
||||
// /**
|
||||
// * Override: Mengambil satu data Marketing berdasarkan ID dari dummyMarketings
|
||||
// */
|
||||
// async getSingle(id: number): Promise<BaseApiResponse<Marketing> | undefined> {
|
||||
// // Simulasi delay jaringan
|
||||
// await sleep(300);
|
||||
|
||||
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);
|
||||
// const foundData = dummyMarketings.find((m) => m.id == id);
|
||||
|
||||
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.',
|
||||
};
|
||||
}
|
||||
}
|
||||
// if (foundData) {
|
||||
// // Data ditemukan, kembalikan respons sukses
|
||||
// return createDummyResponse<Marketing>(foundData as Marketing);
|
||||
// } else {
|
||||
// // Data tidak ditemukan, simulasi respons error
|
||||
// return {
|
||||
// code: 404,
|
||||
// status: 'error',
|
||||
// message: 'Marketing data not found (MOCK)',
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* Approve single marketing data
|
||||
*/
|
||||
async singleApproval(
|
||||
id: number,
|
||||
action: 'approve' | 'reject'
|
||||
action: 'APPROVED' | 'REJECTED',
|
||||
notes?: string
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||
try {
|
||||
const path = `${this.basePath}/approvals`;
|
||||
@@ -88,8 +80,8 @@ export class MarketingService extends BaseApiService<
|
||||
method: 'POST',
|
||||
body: {
|
||||
action: action,
|
||||
approval_ids: [id],
|
||||
notes: `${action} marketing ${id}`,
|
||||
approvable_ids: [id],
|
||||
notes: notes || `${action} marketing ${id}`,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -103,7 +95,8 @@ export class MarketingService extends BaseApiService<
|
||||
*/
|
||||
async bulkApprovals(
|
||||
ids: number[],
|
||||
action: 'approve' | 'reject'
|
||||
action: 'APPROVED' | 'REJECTED',
|
||||
notes?: string
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||
try {
|
||||
const path = `${this.basePath}/approvals`;
|
||||
@@ -111,8 +104,8 @@ export class MarketingService extends BaseApiService<
|
||||
method: 'POST',
|
||||
body: {
|
||||
action: action,
|
||||
approval_ids: ids,
|
||||
notes: `${action} marketing ${ids.join(', ')}`,
|
||||
approvable_ids: ids,
|
||||
notes: notes || `${action} marketing ${ids.join(', ')}`,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -120,6 +113,37 @@ export class MarketingService extends BaseApiService<
|
||||
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 MarketingApi = new MarketingService('/marketing');
|
||||
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'
|
||||
);
|
||||
|
||||
@@ -21,7 +21,8 @@ export class ChickinService extends BaseApiService<
|
||||
*/
|
||||
async singleApproval(
|
||||
id: number,
|
||||
action: 'APPROVED' | 'REJECTED'
|
||||
action: 'APPROVED' | 'REJECTED',
|
||||
notes?: string
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||
try {
|
||||
const path = `${this.basePath}/approvals`;
|
||||
@@ -30,7 +31,7 @@ export class ChickinService extends BaseApiService<
|
||||
body: {
|
||||
action: action,
|
||||
approvable_ids: [id],
|
||||
notes: `${action} chickin ${id}`,
|
||||
notes: notes ?? `${action} chickin ${id}`,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
@@ -8,13 +8,10 @@ import {
|
||||
BaseApiResponse,
|
||||
BaseGroupedApproval,
|
||||
ErrorApiResponse,
|
||||
GroupedApprovals,
|
||||
SuccessApiResponse,
|
||||
} from '@/types/api/api-general';
|
||||
import { sleep } from '@/lib/helper';
|
||||
import { httpClient } from '@/services/http/client';
|
||||
import axios from 'axios';
|
||||
import { Flock } from '@/types/api/master-data/flock';
|
||||
import { Kandang } from '@/types/api/master-data/kandang';
|
||||
import { RequestOptions } from '@/services/http/base';
|
||||
|
||||
@@ -104,25 +101,34 @@ export class ProjectFlockService extends BaseApiService<
|
||||
/**
|
||||
* Get Next Period of Project Flock
|
||||
*/
|
||||
async getNextPeriod(id: string): Promise<
|
||||
| BaseApiResponse<{
|
||||
flock: Flock;
|
||||
next_period: number;
|
||||
}>
|
||||
async getNextPeriod(locationId: number): Promise<
|
||||
| BaseApiResponse<
|
||||
{
|
||||
id: number;
|
||||
name: string;
|
||||
period: number;
|
||||
}[]
|
||||
>
|
||||
| ErrorApiResponse
|
||||
| SuccessApiResponse<{
|
||||
flock: Flock;
|
||||
next_period: number;
|
||||
}>
|
||||
| SuccessApiResponse<
|
||||
{
|
||||
id: number;
|
||||
name: string;
|
||||
period: number;
|
||||
}[]
|
||||
>
|
||||
| undefined
|
||||
> {
|
||||
try {
|
||||
const path = `${this.basePath}/kandangs/${id}`;
|
||||
const path = `${this.basePath}/location/${locationId.toString()}/periods`;
|
||||
return await httpClient<
|
||||
SuccessApiResponse<{
|
||||
flock: Flock;
|
||||
next_period: number;
|
||||
}>
|
||||
SuccessApiResponse<
|
||||
{
|
||||
id: number;
|
||||
name: string;
|
||||
period: number;
|
||||
}[]
|
||||
>
|
||||
>(path, {
|
||||
method: 'GET',
|
||||
});
|
||||
@@ -139,36 +145,40 @@ export class ProjectFlockService extends BaseApiService<
|
||||
* Approve single Project Flock
|
||||
*/
|
||||
async approve(
|
||||
id: number
|
||||
id: number,
|
||||
notes?: string
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||
return await this.bulkApprovalAction([id], 'APPROVED');
|
||||
return await this.bulkApprovalAction([id], 'APPROVED', notes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reject single Project Flock
|
||||
*/
|
||||
async reject(
|
||||
id: number
|
||||
id: number,
|
||||
notes?: string
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||
return await this.bulkApprovalAction([id], 'REJECTED');
|
||||
return await this.bulkApprovalAction([id], 'REJECTED', notes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Approve Bulk Project Flock
|
||||
*/
|
||||
async bulkApprove(
|
||||
ids: number[]
|
||||
ids: number[],
|
||||
notes?: string
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||
return await this.bulkApprovalAction(ids, 'APPROVED');
|
||||
return await this.bulkApprovalAction(ids, 'APPROVED', notes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reject Bulk Project Flock
|
||||
*/
|
||||
async bulkReject(
|
||||
ids: number[]
|
||||
ids: number[],
|
||||
notes?: string
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||
return await this.bulkApprovalAction(ids, 'REJECTED');
|
||||
return await this.bulkApprovalAction(ids, 'REJECTED', notes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,7 +186,8 @@ export class ProjectFlockService extends BaseApiService<
|
||||
*/
|
||||
async bulkApprovalAction(
|
||||
ids: number[],
|
||||
action: 'APPROVED' | 'REJECTED'
|
||||
action: 'APPROVED' | 'REJECTED',
|
||||
notes?: string
|
||||
): Promise<BaseApiResponse<{ message: string }> | undefined> {
|
||||
try {
|
||||
const path = `${this.basePath}/approvals`;
|
||||
@@ -185,7 +196,7 @@ export class ProjectFlockService extends BaseApiService<
|
||||
body: {
|
||||
action: action,
|
||||
approvable_ids: ids,
|
||||
notes: `Bulk ${action} Project Flock ${ids.join(', ')}`,
|
||||
notes: notes ?? `Bulk ${action} Project Flock ${ids.join(', ')}`,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user