mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE-212): update purchase types and payloads for requisition handling
This commit is contained in:
@@ -1,88 +1,12 @@
|
||||
import { sleep } from '@/lib/helper';
|
||||
import { BaseApiService } from './base';
|
||||
import { BaseApiResponse } from '@/types/api/api-general';
|
||||
import {
|
||||
CreatePurchaseRequestPayload,
|
||||
CreatePurchaseRequisitionsPayload,
|
||||
Purchase,
|
||||
UpdatePurchaseRequestPayload,
|
||||
UpdatePurchaseRequisitionsPayload,
|
||||
} from '@/types/api/purchase/purchase';
|
||||
import { BaseApiService } from '@/services/api/base';
|
||||
|
||||
const GET_ALL_PURCHASE_DUMMY_DATA: BaseApiResponse<Purchase[]> = {
|
||||
code: 200,
|
||||
status: 'success',
|
||||
message: 'Successfully get all purchase data!',
|
||||
meta: {
|
||||
page: 1,
|
||||
limit: 10,
|
||||
total_pages: 1,
|
||||
total_results: 1,
|
||||
},
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
pr_number: 'PR-001',
|
||||
po_number: 'PO-001',
|
||||
po_date: '2024-01-15',
|
||||
supplier: {
|
||||
id: 1,
|
||||
name: 'Supplier A',
|
||||
address: '123 Main St, Cityville',
|
||||
account_number: 'ACC-12345',
|
||||
alias: 'SupA',
|
||||
category: 'Electronics',
|
||||
type: 'Local',
|
||||
phone: '555-1234',
|
||||
email: 'email@.com',
|
||||
npwp: '12.345.678.9-012.345',
|
||||
pic: 'John Doe',
|
||||
balance: 1000000,
|
||||
hatchery: 'N/A',
|
||||
due_date: 30,
|
||||
created_at: '2024-01-10T10:00:00Z',
|
||||
updated_at: '2024-01-12T12:00:00Z',
|
||||
created_user: {
|
||||
id: 2,
|
||||
id_user: 2,
|
||||
email: 'a@email.com',
|
||||
name: 'Admin User',
|
||||
},
|
||||
},
|
||||
credit_term: 30,
|
||||
due_date: '2024-02-14',
|
||||
grand_total: 1500000,
|
||||
deleted_at: null,
|
||||
created_at: '2024-01-10T10:00:00Z',
|
||||
updated_at: '2024-01-12T12:00:00Z',
|
||||
created_by: 2,
|
||||
created_user: {
|
||||
id: 2,
|
||||
id_user: 2,
|
||||
email: 'a@email.com',
|
||||
name: 'Admin User',
|
||||
},
|
||||
notes: 'Urgent delivery required',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export class PurchaseService extends BaseApiService<
|
||||
export const PurchaseApi = new BaseApiService<
|
||||
Purchase,
|
||||
CreatePurchaseRequestPayload,
|
||||
UpdatePurchaseRequestPayload
|
||||
> {
|
||||
constructor(basePath: string = '') {
|
||||
super(basePath);
|
||||
}
|
||||
|
||||
override async getAllFetcher(
|
||||
endpoint: string
|
||||
): Promise<BaseApiResponse<Purchase[]>> {
|
||||
// return await httpClientFetcher<BaseApiResponse<T[]>>(endpoint);
|
||||
|
||||
await sleep(750);
|
||||
|
||||
return GET_ALL_PURCHASE_DUMMY_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
export const PurchaseApi = new PurchaseService('/purchase-requests');
|
||||
CreatePurchaseRequisitionsPayload,
|
||||
UpdatePurchaseRequisitionsPayload
|
||||
>('/purchases/requisitions');
|
||||
|
||||
Vendored
+16
-9
@@ -3,13 +3,15 @@ import { Supplier } from '@/types/api/master-data/supplier';
|
||||
import { Warehouse } from '@/types/api/master-data/warehouse';
|
||||
import { Product } from '@/types/api/master-data/product';
|
||||
import { ProductWarehouse } from '@/types/api/inventory/product-warehouse';
|
||||
import { Area } from '@/types/api/master-data/area';
|
||||
import { Location } from '@/types/api/master-data/location';
|
||||
|
||||
export type PurchaseItem = {
|
||||
id: number;
|
||||
warehouse: Warehouse;
|
||||
product: Product;
|
||||
product_warehouse: ProductWarehouse;
|
||||
sub_qty: number;
|
||||
quantity: number;
|
||||
};
|
||||
|
||||
export type BasePurchase = {
|
||||
@@ -24,21 +26,26 @@ export type BasePurchase = {
|
||||
notes?: string | null;
|
||||
deleted_at?: string | null;
|
||||
created_by: number;
|
||||
purchase_items?: PurchaseItem[];
|
||||
area?: Area;
|
||||
location?: Location;
|
||||
warehouse?: Warehouse;
|
||||
items?: PurchaseItem[];
|
||||
};
|
||||
|
||||
export type Purchase = BaseMetadata & BasePurchase;
|
||||
|
||||
export type CreatePurchaseRequestPayload = {
|
||||
export type CreatePurchaseRequisitionsPayload = {
|
||||
supplier_id: number;
|
||||
credit_term: number;
|
||||
area_id: number;
|
||||
location_id: number;
|
||||
warehouse_id: number;
|
||||
notes?: string | null;
|
||||
purchase_items: {
|
||||
warehouse_id: number;
|
||||
product_id: number;
|
||||
items: {
|
||||
product_warehouse_id: number;
|
||||
sub_qty: number;
|
||||
product_id: number;
|
||||
quantity: number;
|
||||
}[];
|
||||
};
|
||||
|
||||
export type UpdatePurchaseRequestPayload = CreatePurchaseRequestPayload;
|
||||
export type UpdatePurchaseRequisitionsPayload =
|
||||
CreatePurchaseRequisitionsPayload;
|
||||
|
||||
Reference in New Issue
Block a user