mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-23 23:05:46 +00:00
refactor(FE-327): remove dummy sales data and update ClosingApiService to fetch real sales data from API
This commit is contained in:
+7
-142
@@ -1,123 +1,13 @@
|
|||||||
import { BaseApiService } from './base';
|
import { BaseApiService } from './base';
|
||||||
import { BaseApiResponse, CreatedUser } from '@/types/api/api-general';
|
import { BaseApiResponse } from '@/types/api/api-general';
|
||||||
import { ClosingSales } from '@/types/api/closing/closing';
|
import { ClosingSales } from '@/types/api/closing/closing';
|
||||||
import { sleep } from '@/lib/helper';
|
|
||||||
|
|
||||||
const adminUser: CreatedUser = {
|
|
||||||
id: 1,
|
|
||||||
id_user: 1,
|
|
||||||
email: 'admin@example.com',
|
|
||||||
name: 'Admin User',
|
|
||||||
};
|
|
||||||
|
|
||||||
const DUMMY_SALES: ClosingSales[] = [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
realization_date: '2025-01-15',
|
|
||||||
week_age: 4,
|
|
||||||
age_label: 'Week 4',
|
|
||||||
delivery_order_number: 'DO-2025-001',
|
|
||||||
product: {
|
|
||||||
id: 1,
|
|
||||||
name: 'Ayam Broiler',
|
|
||||||
brand: 'Brand A',
|
|
||||||
sku: 'AYM-001',
|
|
||||||
product_price: 20000,
|
|
||||||
selling_price: 25000,
|
|
||||||
tax: 10,
|
|
||||||
expiry_period: 30,
|
|
||||||
uom: {
|
|
||||||
id: 1,
|
|
||||||
name: 'Kg',
|
|
||||||
created_user: adminUser,
|
|
||||||
created_at: '2025-01-01T00:00:00Z',
|
|
||||||
updated_at: '2025-01-01T00:00:00Z',
|
|
||||||
},
|
|
||||||
product_category: {
|
|
||||||
id: 1,
|
|
||||||
code: 'LC001',
|
|
||||||
name: 'Live Chicken',
|
|
||||||
created_user: adminUser,
|
|
||||||
created_at: '2025-01-01T00:00:00Z',
|
|
||||||
updated_at: '2025-01-01T00:00:00Z',
|
|
||||||
},
|
|
||||||
suppliers: [],
|
|
||||||
flags: [],
|
|
||||||
created_user: adminUser,
|
|
||||||
created_at: '2025-01-01T00:00:00Z',
|
|
||||||
updated_at: '2025-01-01T00:00:00Z',
|
|
||||||
},
|
|
||||||
product_category: {
|
|
||||||
id: 1,
|
|
||||||
code: 'LC001',
|
|
||||||
name: 'Live Chicken',
|
|
||||||
created_user: adminUser,
|
|
||||||
created_at: '2025-01-01T00:00:00Z',
|
|
||||||
updated_at: '2025-01-01T00:00:00Z',
|
|
||||||
},
|
|
||||||
customer: {
|
|
||||||
id: 1,
|
|
||||||
name: 'PT. Bumi Mandiri',
|
|
||||||
pic_id: 1,
|
|
||||||
pic: adminUser,
|
|
||||||
type: 'COMPANY',
|
|
||||||
address: 'Jl. Industri No. 123',
|
|
||||||
phone: '+62-21-1234567',
|
|
||||||
email: 'info@bumimandiri.com',
|
|
||||||
account_number: '1234567890',
|
|
||||||
created_user: adminUser,
|
|
||||||
created_at: '2025-01-01T00:00:00Z',
|
|
||||||
updated_at: '2025-01-01T00:00:00Z',
|
|
||||||
},
|
|
||||||
quantity: 1000,
|
|
||||||
weight: 1850,
|
|
||||||
average: 1.85,
|
|
||||||
price: 25000,
|
|
||||||
total: 25000000,
|
|
||||||
kandang: {
|
|
||||||
id: 1,
|
|
||||||
name: 'Singaparna 1',
|
|
||||||
status: 'ACTIVE',
|
|
||||||
location: {
|
|
||||||
id: 1,
|
|
||||||
name: 'Singaparna',
|
|
||||||
address: 'Jl. Singaparna No. 1',
|
|
||||||
area: {
|
|
||||||
id: 1,
|
|
||||||
name: 'Tasikmalaya',
|
|
||||||
created_user: adminUser,
|
|
||||||
created_at: '2025-01-01T00:00:00Z',
|
|
||||||
updated_at: '2025-01-01T00:00:00Z',
|
|
||||||
},
|
|
||||||
created_user: adminUser,
|
|
||||||
created_at: '2025-01-01T00:00:00Z',
|
|
||||||
updated_at: '2025-01-01T00:00:00Z',
|
|
||||||
},
|
|
||||||
capacity: 1000,
|
|
||||||
pic: {
|
|
||||||
id: 1,
|
|
||||||
id_user: 1,
|
|
||||||
email: 'admin@example.com',
|
|
||||||
name: 'Admin User',
|
|
||||||
},
|
|
||||||
created_user: adminUser,
|
|
||||||
created_at: '2025-01-01T00:00:00Z',
|
|
||||||
updated_at: '2025-01-01T00:00:00Z',
|
|
||||||
},
|
|
||||||
kandang_id: 1,
|
|
||||||
payment_status: 'PAID',
|
|
||||||
created_user: adminUser,
|
|
||||||
created_at: '2025-01-15T10:00:00Z',
|
|
||||||
updated_at: '2025-01-15T10:00:00Z',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export class ClosingApiService extends BaseApiService<
|
export class ClosingApiService extends BaseApiService<
|
||||||
ClosingSales,
|
ClosingSales,
|
||||||
unknown,
|
unknown,
|
||||||
unknown
|
unknown
|
||||||
> {
|
> {
|
||||||
constructor(basePath: string = '') {
|
constructor(basePath: string) {
|
||||||
super(basePath);
|
super(basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,36 +15,11 @@ export class ClosingApiService extends BaseApiService<
|
|||||||
id: number
|
id: number
|
||||||
): Promise<BaseApiResponse<ClosingSales> | undefined> {
|
): Promise<BaseApiResponse<ClosingSales> | undefined> {
|
||||||
try {
|
try {
|
||||||
// TODO: Remove dummy data when real API is ready
|
const getPenjualanPath = `http://localhost:4010/api/closing/${id}/penjualan`;
|
||||||
await sleep(750);
|
return await this.customRequest<BaseApiResponse<ClosingSales>>(
|
||||||
|
getPenjualanPath
|
||||||
const saleData = DUMMY_SALES.find((sale) => sale.id === id);
|
);
|
||||||
|
} catch {
|
||||||
if (!saleData) {
|
|
||||||
return {
|
|
||||||
code: 404,
|
|
||||||
status: 'error',
|
|
||||||
message: 'Sales data not found!',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
code: 200,
|
|
||||||
status: 'success',
|
|
||||||
message: 'Successfully get sales data!',
|
|
||||||
meta: {
|
|
||||||
page: 1,
|
|
||||||
limit: 10,
|
|
||||||
total_pages: 1,
|
|
||||||
total_results: 1,
|
|
||||||
},
|
|
||||||
data: saleData,
|
|
||||||
};
|
|
||||||
|
|
||||||
// const getPenjualanPath = `${this.basePath}/${id}/penjualan`;
|
|
||||||
// return await this.customRequest<BaseApiResponse<ClosingSales>>(getPenjualanPath);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching penjualan:', error);
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user