Skip to content

Commit

Permalink
feat(type): enhance com types
Browse files Browse the repository at this point in the history
  • Loading branch information
AliMD committed Feb 10, 2023
1 parent 7c591bb commit ed91385
Showing 1 changed file with 68 additions and 40 deletions.
108 changes: 68 additions & 40 deletions core/type/src/customer-order-management.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import {MultiLangStringObj} from './i18n.js';
import {Photo} from './photo.js';

import type {MultiLangStringObj} from './i18n.js';
import type {Photo} from './photo.js';
import type {AlwatrDocumentObject} from './storage.js';
import type {StringifyableRecord} from './type-helper.js';

// -- Const value --

export type Product = AlwatrDocumentObject & {
export const shipmentTypeCS = ['x', 'y'] as const;
export const carTypeCS = ['x', 'y'] as const;
export const timePeriodCS = ['1-2w', '2-3w', '3-4w'] as const;
export const discountTypeCS = ['number', 'percent'] as const;
export const orderStatusCS = [
'draft',
'registered',
'processing',
'payment-pending',
'preparing',
'shipping',
'delayed',
'on-hold',
'canceled',
'refunded',
] as const;

// -- Document object --

export interface Product extends AlwatrDocumentObject {
/**
* Product global ID
*
* like product unique code
* Product global unique id.
*/
id: string;

Expand All @@ -20,30 +39,21 @@ export type Product = AlwatrDocumentObject & {
* Product image
*/
image: Photo;
};
}

export type ProductPrice = AlwatrDocumentObject & {
export interface Order extends AlwatrDocumentObject {
/**
* Displayed price before discount
* Order auto incremental unique id.
*/
price: number;

/**
* Final price after any discount
*/
finalPrice: number;
};
id: string;

export type Order = AlwatrDocumentObject & {
/**
* Order unique code
*
* customerId-orderId
* Order Status
*/
id: `${number}-${number}`;
status: (typeof orderStatusCS)[number];

/**
* Products list with price and qty
* Order cart list.
*/
itemList: Array<OrderItem>;

Expand All @@ -53,30 +63,48 @@ export type Order = AlwatrDocumentObject & {
delivery: OrderDelivery;

discount: number;
discountType: typeof discountTypeCS[number];
discountType: (typeof discountTypeCS)[number];

totalPrice: number;
shippingPrice: number;
finalPrice: number;
};

// FIXME: name and values
export const shipmentTypeCS = ['x', 'y'] as const;
export const carTypeCS = ['x', 'y'] as const;
export const timePeriodCS = ['1-2w', '2-3w', '3-4w'] as const;
export const discountTypeCS = ['number', 'percent'] as const;
/**
* Customer device uuid.
*/
clientId: string;

export type OrderDelivery = {
recipientName: string;
recipientNationalCode: string;
address: string;
shipmentType: typeof shipmentTypeCS[number];
carType: typeof carTypeCS[number];
timePeriod: typeof timePeriodCS[number];
};
/**
* Customer device ip address.
*/
remoteAddress: string;
}

export type OrderItem = {
// -- child types --

export interface ProductPrice extends StringifyableRecord {
/**
* Displayed price before discount
*/
price: number;

/**
* Final price after any discount
*/
finalPrice: number;
}

export interface OrderItem extends StringifyableRecord {
productId: string;
price: ProductPrice;
qty: number;
};
}

export interface OrderDelivery extends StringifyableRecord {
recipientName: string;
recipientNationalCode: string;
address: string;
shipmentType: (typeof shipmentTypeCS)[number];
carType: (typeof carTypeCS)[number];
timePeriod: (typeof timePeriodCS)[number];
}

0 comments on commit ed91385

Please sign in to comment.