Skip to content

Commit

Permalink
feat(type/com): rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed May 24, 2023
1 parent aae880f commit 1829673
Showing 1 changed file with 52 additions and 27 deletions.
79 changes: 52 additions & 27 deletions core/type/src/customer-order-management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,26 @@ import type {User} from './user.js';
// -- Const value --

export const ladingTypeCS = ['hand', 'pallet'] as const;
export const carTypeCS = ['nissan', 'one', 'ten_wheel', 'trolley'] as const;
export const carTypePriceCS = [110_000, 140_000, 170_000, 200_000] as const;
export type LadingType = (typeof ladingTypeCS)[number];

export const carTypeCS = [
'trailer_truck',
'camion_dual',
'camion_solo',
'camion_911',
'camion_800',
'camion_600',
'camion_mini',
'nissan',
] as const;
export type CarType = (typeof carTypeCS)[number];

export const timePeriodCS = ['auto', '1_2w', '2_3w', '3_4w'] as const;
export type TimePeriod = (typeof timePeriodCS)[number];

export const discountTypeCS = ['number', 'percent'] as const;
export type DiscountType = (typeof discountTypeCS)[number];

export const orderStatusCS = [
'draft',
'registered',
Expand All @@ -23,8 +39,10 @@ export const orderStatusCS = [
'canceled',
'refunded',
] as const;
export type OrderStatus = (typeof orderStatusCS)[number];

export const tileQtyStep = 3.6;
export const userPermissionsCS = ['user/patch', 'price/patch', 'product/patch', 'user-list/read'] as const;
export type UserPermission = (typeof userPermissionsCS)[number];

// -- Document object --

Expand Down Expand Up @@ -66,7 +84,7 @@ export interface Order extends AlwatrDocumentObject {
/**
* Order Status
*/
status: (typeof orderStatusCS)[number];
status: OrderStatus;

/**
* Order cart list.
Expand All @@ -78,23 +96,35 @@ export interface Order extends AlwatrDocumentObject {
*/
shippingInfo: Partial<OrderShippingInfo>;

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

/**
* The total price of this order exclude lading and discounts.
* The total price of this order exclude shippings.
*/
totalPrice: number;
subTotalMarket: number;

subTotalAgency: number;

/**
* The cost of lading the order.
*/
ladingPrice: number;
ladingFee: number;

/**
* The cost of pallet.
*/
palletCost: number;

/**
* The cost of shipping price.
*/
shippingFee: number;

/**
* The final total price of this order include lading and discounts.
* Total shipping const.
*/
finalTotalPrice: number;
totalShippingFee: number;

/**
* Customer device uuid.
Expand All @@ -120,12 +150,12 @@ export interface OrderItem extends StringifyableRecord {
/**
* The selling price of single product in the market.
*/
price: number;
marketPrice: number;

/**
* The selling price of a product after any discounts to this buyer.
*/
finalPrice: number;
agencyPrice: number;

/**
* Quantity of this item.
Expand All @@ -138,19 +168,11 @@ export interface OrderShippingInfo extends StringifyableRecord {
recipientNationalCode: string;
address: string;
description: string;
ladingType: (typeof ladingTypeCS)[number];
carType: (typeof carTypeCS)[number];
timePeriod: (typeof timePeriodCS)[number];
ladingType: LadingType;
carType: CarType;
timePeriod: TimePeriod;
}

export const userPermissionsCS = [
'user/patch',
'price/patch',
'product/patch',
'user-list/read',
] as const;
export type UserPermission = (typeof userPermissionsCS)[number];

export interface ComUser extends User {
permissions?: Array<UserPermission> | 'root';
shopName?: string;
Expand Down Expand Up @@ -181,9 +203,12 @@ export const orderInfoSchema = {
},
// discount: Number,
// discountType: String,
totalPrice: Number,
// ladingPrice: Number,
finalTotalPrice: Number,
subTotalMarket: Number,
subTotalAgency: Number,
ladingFee: Number,
palletCost: Number,
shippingFee: Number,
totalShippingFee: Number,
};

export const orderShippingInfoSchema = orderInfoSchema.shippingInfo;

0 comments on commit 1829673

Please sign in to comment.