|
3 | 3 | */ |
4 | 4 |
|
5 | 5 | const migrate = (db, helpers) => { |
6 | | - const { createOrModify, ensureIndex } = helpers; |
| 6 | + const { createOrModify } = helpers; |
7 | 7 |
|
8 | 8 | const invoiceOptionSchema = { |
9 | 9 | bsonType: "object", |
10 | 10 | required: ["name", "item"], |
11 | 11 | description: "An option slot for a product", |
12 | 12 | properties: { |
13 | 13 | name: { |
14 | | - bsonType: "string", |
15 | | - description: "Name of the current option slot" |
| 14 | + bsonType: "string" |
16 | 15 | }, |
17 | 16 | item: { |
18 | 17 | bsonType: "object", |
19 | 18 | required: ["name", "delta", "quantity"], |
20 | | - description: "The chosen option", |
21 | 19 | properties: { |
22 | | - name: { |
23 | | - bsonType: "string", |
24 | | - description: "Name of product" |
25 | | - }, |
26 | | - delta: { |
27 | | - bsonType: "double", |
28 | | - description: "Price increase or decrease on the product" |
29 | | - }, |
30 | | - quantity: { |
31 | | - bsonType: "int", |
32 | | - description: "Number of options selected (between min_select and max_select)", |
33 | | - minimum: 0 |
34 | | - }, |
| 20 | + name: { bsonType: "string" }, |
| 21 | + delta: { bsonType: "double" }, |
| 22 | + quantity: { bsonType: "int", minimum: 0 } |
35 | 23 | } |
36 | 24 | } |
37 | 25 | } |
38 | 26 | }; |
39 | 27 |
|
40 | | - const invoiceOptionsSchema = { |
41 | | - bsonType: "array", |
42 | | - description: "Array of options on a given product (optional)", |
43 | | - items: invoiceOptionSchema |
44 | | - }; |
45 | | - |
46 | | - const invoiceMenuSlotSchema = { |
47 | | - bsonType: "object", |
48 | | - required: ["name", "item"], |
49 | | - description: "A menu slot", |
50 | | - properties: { |
51 | | - name: { |
52 | | - bsonType: "string", |
53 | | - description: "Name of the current slot in the menu" |
54 | | - }, |
55 | | - item: { |
56 | | - bsonType: "object", |
57 | | - required: ["name", "delta", "quantity"], |
58 | | - description: "What product has been chosen for this slot", |
59 | | - properties: { |
60 | | - name: { |
61 | | - bsonType: "string", |
62 | | - description: "Name of product" |
63 | | - }, |
64 | | - delta: { |
65 | | - bsonType: "double", |
66 | | - description: "Price increase or decrease on the product" |
67 | | - }, |
68 | | - quantity: { |
69 | | - bsonType: "int", |
70 | | - description: "Number of products selected (between min_select and max_select)", |
71 | | - minimum: 0 // For instance, a dessert can be optional whence the threshold |
72 | | - }, |
73 | | - |
74 | | - // Selected options if any (optional) |
75 | | - options: invoiceOptionsSchema |
76 | | - } |
77 | | - } |
78 | | - } |
79 | | - }; |
80 | | - |
81 | | - const invoiceMenuSlotsSchema = { |
82 | | - bsonType: "array", |
83 | | - description: "Used when the item is a menu. Array of menu slots (optional)", |
84 | | - items: invoiceMenuSlotSchema |
85 | | - }; |
86 | | - |
87 | 28 | const invoiceItemSchema = { |
88 | 29 | bsonType: "object", |
89 | 30 | required: ["type", "name", "price", "quantity"], |
90 | | - description: "A given line in the invoice which corresponds to a given item", |
91 | 31 | properties: { |
92 | 32 | type: { |
93 | | - bsonType: "string", |
94 | | - enum: ["product", "menu"], |
95 | | - description: "Current item is either a product or a menu" |
96 | | - }, |
97 | | - name: { |
98 | | - bsonType: "string", |
99 | | - description: "This is the name of the item" |
| 33 | + enum: ["product"], // Restreint au type "product" uniquement |
| 34 | + bsonType: "string" |
100 | 35 | }, |
101 | | - price: { |
102 | | - bsonType: "double", |
103 | | - description: "The unit price, must be non negative", // For a menu, the prices of products within are not taken into account |
104 | | - minimum: 0 |
105 | | - }, |
106 | | - quantity: { |
107 | | - bsonType: "int", |
108 | | - description: "Quantity of the ordered item, at least 1", |
109 | | - minimum: 1 |
110 | | - }, |
111 | | - |
112 | | - // Present when type=product |
113 | | - options: invoiceOptionsSchema, |
114 | | - |
115 | | - // Present when type=menu |
116 | | - slots: invoiceMenuSlotsSchema |
| 36 | + name: { bsonType: "string" }, |
| 37 | + price: { bsonType: "double", minimum: 0 }, |
| 38 | + quantity: { bsonType: "int", minimum: 1 }, |
| 39 | + options: { |
| 40 | + bsonType: "array", |
| 41 | + items: invoiceOptionSchema |
| 42 | + } |
117 | 43 | } |
118 | 44 | }; |
119 | 45 |
|
120 | 46 | const invoiceSchema = { |
121 | 47 | bsonType: "object", |
122 | 48 | required: ["_id", "items"], |
123 | 49 | properties: { |
124 | | - _id: { |
125 | | - bsonType: "int", |
126 | | - description: "Mirrors the Postgres invoice.id" |
127 | | - }, |
| 50 | + _id: { bsonType: "int" }, |
128 | 51 | items: { |
129 | 52 | bsonType: "array", |
130 | | - description: "An array of invoices items (at least one line)", |
131 | 53 | minItems: 1, |
132 | 54 | items: invoiceItemSchema |
133 | 55 | } |
|
0 commit comments