@forgetman505/ttwashcar-order 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/order.js +59 -0
  2. package/package.json +15 -0
package/order.js ADDED
@@ -0,0 +1,59 @@
1
+ const OrderStatus = {
2
+ PENDING: '待接单',
3
+ ACCEPTED: '已接单',
4
+ PROGRESSING: '进行中',
5
+ FINISHED: '已完成'
6
+ }
7
+
8
+ const CarType = {
9
+ NONE: '通用',
10
+ SUV: 'SUV',
11
+ SEDAN: '轿车',
12
+ MPV: 'MPV'
13
+ }
14
+
15
+ // ======================================
16
+ // 【创建】工厂函数(新建订单时用)
17
+ // ======================================
18
+ function createOrder(data = {}) {
19
+ return {
20
+ car_number: "", // 车牌号
21
+ car_type: CarType.NONE,
22
+ address: "", // 地址
23
+ amount: 0,
24
+ status: OrderStatus.PENDING,
25
+ employee_id: "",
26
+ images: [],
27
+ create_time: new Date(),
28
+ ...data // 覆盖传入的字段
29
+ }
30
+ }
31
+
32
+ // ======================================
33
+ // 【接收】格式化函数(从数据库取数据时用)
34
+ // ======================================
35
+ function formatOrder(order = {}) {
36
+ return {
37
+ // 用 createOrder() 兜底所有字段,防止 undefined
38
+ ...createOrder(),
39
+ // 用真实数据覆盖
40
+ ...order,
41
+
42
+ // 安全处理日期:有值用原值,没有则为 null
43
+ create_time: order.create_time || null,
44
+ request_time: order.request_time || null,
45
+
46
+ // 安全处理数组:防止后端/数据库没有 images 字段
47
+ images: Array.isArray(order.images) ? order.images : [],
48
+ }
49
+ }
50
+
51
+ // 批量格式化订单数组
52
+ function formatOrders(orders = []) {
53
+ if (!Array.isArray(orders)) {
54
+ return formatOrder(orders)
55
+ }
56
+ return orders.map(order => formatOrder(order))
57
+ }
58
+
59
+ module.exports = { createOrder, formatOrder, formatOrders, OrderStatus, CarType }
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@forgetman505/ttwashcar-order",
3
+ "version": "1.0.0",
4
+ "description": "WashCar order models",
5
+ "main": "order.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [
10
+ "washcar",
11
+ "order"
12
+ ],
13
+ "author": "",
14
+ "license": "ISC"
15
+ }