@stacksjs/commerce 0.70.53 → 0.70.55

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 (165) hide show
  1. package/package.json +3 -2
  2. package/src/carts/destroy.ts +54 -0
  3. package/src/carts/fetch.ts +20 -0
  4. package/src/carts/index.ts +13 -0
  5. package/src/carts/store.ts +75 -0
  6. package/src/carts/update.ts +78 -0
  7. package/src/coupons/destroy.ts +49 -0
  8. package/src/coupons/fetch.ts +510 -0
  9. package/src/coupons/index.ts +30 -0
  10. package/src/coupons/store.ts +46 -0
  11. package/src/coupons/update.ts +147 -0
  12. package/src/customers/destroy.ts +62 -0
  13. package/src/customers/fetch.ts +20 -0
  14. package/src/customers/index.ts +17 -0
  15. package/src/customers/store.ts +45 -0
  16. package/src/customers/update.ts +44 -0
  17. package/src/devices/destroy.ts +54 -0
  18. package/src/devices/export.ts +98 -0
  19. package/src/devices/fetch.ts +125 -0
  20. package/src/devices/index.ts +31 -0
  21. package/src/devices/store.ts +82 -0
  22. package/src/devices/update.ts +125 -0
  23. package/src/errors/destroy.ts +54 -0
  24. package/src/errors/fetch.ts +197 -0
  25. package/src/errors/index.ts +28 -0
  26. package/src/errors/update.ts +116 -0
  27. package/src/gift-cards/destroy.ts +87 -0
  28. package/src/gift-cards/fetch.ts +431 -0
  29. package/src/gift-cards/index.ts +26 -0
  30. package/src/gift-cards/store.ts +56 -0
  31. package/src/gift-cards/update.ts +102 -0
  32. package/src/index.ts +78 -0
  33. package/src/orders/destroy.ts +111 -0
  34. package/src/orders/events.ts +121 -0
  35. package/src/orders/export.ts +158 -0
  36. package/src/orders/fetch.ts +379 -0
  37. package/src/orders/guards.ts +261 -0
  38. package/src/orders/index.ts +91 -0
  39. package/src/orders/place-order.ts +274 -0
  40. package/src/orders/store.ts +51 -0
  41. package/src/orders/totals.ts +190 -0
  42. package/src/orders/update.ts +164 -0
  43. package/src/orders/webhook.ts +312 -0
  44. package/src/payments/destroy.ts +56 -0
  45. package/src/payments/fetch.ts +288 -0
  46. package/src/payments/index.ts +16 -0
  47. package/src/payments/store.ts +63 -0
  48. package/src/payments/update.ts +52 -0
  49. package/src/product.ts +0 -0
  50. package/src/products/categories/destroy.ts +103 -0
  51. package/src/products/categories/fetch.ts +285 -0
  52. package/src/products/categories/index.ts +36 -0
  53. package/src/products/categories/store.ts +87 -0
  54. package/src/products/categories/update.ts +251 -0
  55. package/src/products/index.ts +35 -0
  56. package/src/products/items/destroy.ts +54 -0
  57. package/src/products/items/fetch.ts +282 -0
  58. package/src/products/items/index.ts +26 -0
  59. package/src/products/items/store.ts +84 -0
  60. package/src/products/items/update.ts +324 -0
  61. package/src/products/manufacturers/destroy.ts +56 -0
  62. package/src/products/manufacturers/fetch.ts +117 -0
  63. package/src/products/manufacturers/index.ts +24 -0
  64. package/src/products/manufacturers/store.ts +82 -0
  65. package/src/products/manufacturers/update.ts +113 -0
  66. package/src/products/reviews/destroy.ts +56 -0
  67. package/src/products/reviews/fetch.ts +63 -0
  68. package/src/products/reviews/index.ts +25 -0
  69. package/src/products/reviews/store.ts +46 -0
  70. package/src/products/reviews/update.ts +82 -0
  71. package/src/products/units/destroy.ts +56 -0
  72. package/src/products/units/fetch.ts +20 -0
  73. package/src/products/units/index.ts +13 -0
  74. package/src/products/units/store.ts +162 -0
  75. package/src/products/units/update.ts +159 -0
  76. package/src/products/variants/destroy.ts +56 -0
  77. package/src/products/variants/fetch.ts +20 -0
  78. package/src/products/variants/index.ts +21 -0
  79. package/src/products/variants/store.ts +136 -0
  80. package/src/products/variants/update.ts +104 -0
  81. package/src/receipts/destroy.ts +54 -0
  82. package/src/receipts/export.ts +0 -0
  83. package/src/receipts/fetch.ts +222 -0
  84. package/src/receipts/index.ts +24 -0
  85. package/src/receipts/printer.ts +69 -0
  86. package/src/receipts/store.ts +69 -0
  87. package/src/receipts/update.ts +124 -0
  88. package/src/shippings/delivery-routes/destroy.ts +54 -0
  89. package/src/shippings/delivery-routes/fetch.ts +42 -0
  90. package/src/shippings/delivery-routes/index.ts +26 -0
  91. package/src/shippings/delivery-routes/store.ts +69 -0
  92. package/src/shippings/delivery-routes/update.ts +120 -0
  93. package/src/shippings/digital-deliveries/destroy.ts +111 -0
  94. package/src/shippings/digital-deliveries/fetch.ts +20 -0
  95. package/src/shippings/digital-deliveries/index.ts +26 -0
  96. package/src/shippings/digital-deliveries/store.ts +76 -0
  97. package/src/shippings/digital-deliveries/update.ts +129 -0
  98. package/src/shippings/drivers/destroy.ts +78 -0
  99. package/src/shippings/drivers/fetch.ts +20 -0
  100. package/src/shippings/drivers/index.ts +24 -0
  101. package/src/shippings/drivers/store.ts +69 -0
  102. package/src/shippings/drivers/update.ts +117 -0
  103. package/src/shippings/index.ts +39 -0
  104. package/src/shippings/license-keys/destroy.ts +111 -0
  105. package/src/shippings/license-keys/fetch.ts +20 -0
  106. package/src/shippings/license-keys/index.ts +26 -0
  107. package/src/shippings/license-keys/store.ts +77 -0
  108. package/src/shippings/license-keys/update.ts +117 -0
  109. package/src/shippings/shipping-methods/destroy.ts +111 -0
  110. package/src/shippings/shipping-methods/fetch.ts +62 -0
  111. package/src/shippings/shipping-methods/index.ts +28 -0
  112. package/src/shippings/shipping-methods/store.ts +123 -0
  113. package/src/shippings/shipping-methods/update.ts +120 -0
  114. package/src/shippings/shipping-rates/destroy.ts +102 -0
  115. package/src/shippings/shipping-rates/fetch.ts +320 -0
  116. package/src/shippings/shipping-rates/index.ts +36 -0
  117. package/src/shippings/shipping-rates/store.ts +102 -0
  118. package/src/shippings/shipping-rates/update.ts +139 -0
  119. package/src/shippings/shipping-zones/destroy.ts +111 -0
  120. package/src/shippings/shipping-zones/fetch.ts +96 -0
  121. package/src/shippings/shipping-zones/index.ts +26 -0
  122. package/src/shippings/shipping-zones/store.ts +74 -0
  123. package/src/shippings/shipping-zones/update.ts +156 -0
  124. package/src/tax/destroy.ts +54 -0
  125. package/src/tax/fetch.ts +20 -0
  126. package/src/tax/index.ts +24 -0
  127. package/src/tax/store.ts +69 -0
  128. package/src/tax/update.ts +119 -0
  129. package/src/tests/coupons.test.ts +90 -0
  130. package/src/tests/customers.test.ts +39 -0
  131. package/src/tests/device.test.ts +111 -0
  132. package/src/tests/digitals.test.ts +31 -0
  133. package/src/tests/drivers.test.ts +25 -0
  134. package/src/tests/gift-cards.test.ts +36 -0
  135. package/src/tests/license.test.ts +31 -0
  136. package/src/tests/manufacturers.test.ts +80 -0
  137. package/src/tests/orders.test.ts +25 -0
  138. package/src/tests/payments.test.ts +75 -0
  139. package/src/tests/rates.test.ts +367 -0
  140. package/src/tests/receipts.test.ts +287 -0
  141. package/src/tests/restaurant.test.ts +522 -0
  142. package/src/tests/reviews.test.ts +165 -0
  143. package/src/tests/routes.test.ts +51 -0
  144. package/src/tests/setup.ts +149 -0
  145. package/src/tests/shipping.test.ts +88 -0
  146. package/src/tests/tax.test.ts +25 -0
  147. package/src/tests/units.test.ts +110 -0
  148. package/src/tests/variants.test.ts +133 -0
  149. package/src/tests/waitlist.test.ts +303 -0
  150. package/src/tests/zones.test.ts +86 -0
  151. package/src/types.ts +312 -0
  152. package/src/utils/typed-stats.ts +67 -0
  153. package/src/waitlists/index.ts +19 -0
  154. package/src/waitlists/products/destroy.ts +65 -0
  155. package/src/waitlists/products/export.ts +113 -0
  156. package/src/waitlists/products/fetch.ts +362 -0
  157. package/src/waitlists/products/index.ts +33 -0
  158. package/src/waitlists/products/store.ts +112 -0
  159. package/src/waitlists/products/update.ts +125 -0
  160. package/src/waitlists/restaurant/destroy.ts +65 -0
  161. package/src/waitlists/restaurant/export.ts +107 -0
  162. package/src/waitlists/restaurant/fetch.ts +538 -0
  163. package/src/waitlists/restaurant/index.ts +43 -0
  164. package/src/waitlists/restaurant/store.ts +109 -0
  165. package/src/waitlists/restaurant/update.ts +198 -0
@@ -0,0 +1,198 @@
1
+ import { db } from '@stacksjs/database'
2
+ import { formatDate } from '@stacksjs/orm'
3
+ type WaitlistRestaurantJsonResponse = ModelRow<typeof WaitlistRestaurant>
4
+ type WaitlistRestaurantUpdate = UpdateModelData<typeof WaitlistRestaurant>
5
+
6
+ /**
7
+ * Update a restaurant waitlist entry
8
+ *
9
+ * @param id The id of the restaurant waitlist entry to update
10
+ * @param data The restaurant waitlist data to update
11
+ * @returns The updated restaurant waitlist record
12
+ */
13
+ export async function update(id: number, data: WaitlistRestaurantUpdate): Promise<WaitlistRestaurantJsonResponse> {
14
+ try {
15
+ if (!id)
16
+ throw new Error('Restaurant waitlist entry ID is required for update')
17
+
18
+ const d = data as Record<string, unknown>
19
+ const result = await db
20
+ .updateTable('waitlist_restaurants')
21
+ .set({
22
+ name: data.name,
23
+ email: data.email,
24
+ phone: data.phone,
25
+ party_size: d.party_size,
26
+ check_in_time: d.check_in_time ? Math.floor(new Date(d.check_in_time as string).getTime() / 1000) : undefined,
27
+ table_preference: d.table_preference,
28
+ status: data.status,
29
+ quoted_wait_time: data.quoted_wait_time,
30
+ actual_wait_time: data.actual_wait_time,
31
+ queue_position: data.queue_position,
32
+ customer_id: data.customer_id,
33
+ updated_at: formatDate(new Date()),
34
+ })
35
+ .where('id', '=', id)
36
+ .returningAll()
37
+ .executeTakeFirst()
38
+
39
+ if (!result)
40
+ throw new Error('Failed to update restaurant waitlist entry')
41
+
42
+ return result as WaitlistRestaurantJsonResponse
43
+ }
44
+ catch (error) {
45
+ if (error instanceof Error) {
46
+ throw new TypeError(`Failed to update restaurant waitlist entry: ${error.message}`)
47
+ }
48
+
49
+ throw error
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Update a restaurant waitlist entry's status
55
+ *
56
+ * @param id The ID of the restaurant waitlist entry
57
+ * @param status The new status
58
+ * @returns The updated restaurant waitlist entry with the new status
59
+ */
60
+ export async function updateStatus(
61
+ id: number,
62
+ status: 'waiting' | 'seated',
63
+ ): Promise<WaitlistRestaurantJsonResponse> {
64
+ try {
65
+ const result = await db
66
+ .updateTable('waitlist_restaurants')
67
+ .set({
68
+ status,
69
+ updated_at: formatDate(new Date()),
70
+ })
71
+ .where('id', '=', id)
72
+ .returningAll()
73
+ .executeTakeFirst()
74
+
75
+ if (!result)
76
+ throw new Error('Failed to update restaurant waitlist entry status')
77
+
78
+ return result as WaitlistRestaurantJsonResponse
79
+ }
80
+ catch (error) {
81
+ if (error instanceof Error) {
82
+ throw new TypeError(`Failed to update restaurant waitlist entry status: ${error.message}`)
83
+ }
84
+
85
+ throw error
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Update party size for a restaurant waitlist entry
91
+ *
92
+ * @param id The ID of the restaurant waitlist entry
93
+ * @param partySize The updated party size
94
+ * @returns The updated restaurant waitlist entry
95
+ */
96
+ export async function updatePartySize(
97
+ id: number,
98
+ partySize: number,
99
+ ): Promise<WaitlistRestaurantJsonResponse> {
100
+ try {
101
+ const result = await db
102
+ .updateTable('waitlist_restaurants')
103
+ .set({
104
+ party_size: partySize,
105
+ updated_at: formatDate(new Date()),
106
+ })
107
+ .where('id', '=', id)
108
+ .returningAll()
109
+ .executeTakeFirst()
110
+
111
+ if (!result)
112
+ throw new Error('Failed to update party size')
113
+
114
+ return result as WaitlistRestaurantJsonResponse
115
+ }
116
+ catch (error) {
117
+ if (error instanceof Error) {
118
+ throw new TypeError(`Failed to update party size: ${error.message}`)
119
+ }
120
+
121
+ throw error
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Update wait times for a restaurant waitlist entry
127
+ *
128
+ * @param id The ID of the restaurant waitlist entry
129
+ * @param quotedWaitTime The quoted wait time in minutes
130
+ * @param actualWaitTime The actual wait time in minutes (optional)
131
+ * @returns The updated restaurant waitlist entry
132
+ */
133
+ export async function updateWaitTimes(
134
+ id: number,
135
+ quotedWaitTime: number,
136
+ actualWaitTime?: number,
137
+ ): Promise<WaitlistRestaurantJsonResponse> {
138
+ try {
139
+ const result = await db
140
+ .updateTable('waitlist_restaurants')
141
+ .set({
142
+ quoted_wait_time: quotedWaitTime,
143
+ actual_wait_time: actualWaitTime,
144
+ updated_at: formatDate(new Date()),
145
+ })
146
+ .where('id', '=', id)
147
+ .returningAll()
148
+ .executeTakeFirst()
149
+
150
+ if (!result)
151
+ throw new Error('Failed to update wait times')
152
+
153
+ return result as WaitlistRestaurantJsonResponse
154
+ }
155
+ catch (error) {
156
+ if (error instanceof Error) {
157
+ throw new TypeError(`Failed to update wait times: ${error.message}`)
158
+ }
159
+
160
+ throw error
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Update queue position for a restaurant waitlist entry
166
+ *
167
+ * @param id The ID of the restaurant waitlist entry
168
+ * @param queuePosition The updated queue position
169
+ * @returns The updated restaurant waitlist entry
170
+ */
171
+ export async function updateQueuePosition(
172
+ id: number,
173
+ queuePosition: number,
174
+ ): Promise<WaitlistRestaurantJsonResponse> {
175
+ try {
176
+ const result = await db
177
+ .updateTable('waitlist_restaurants')
178
+ .set({
179
+ queue_position: queuePosition,
180
+ updated_at: formatDate(new Date()),
181
+ })
182
+ .where('id', '=', id)
183
+ .returningAll()
184
+ .executeTakeFirst()
185
+
186
+ if (!result)
187
+ throw new Error('Failed to update queue position')
188
+
189
+ return result as WaitlistRestaurantJsonResponse
190
+ }
191
+ catch (error) {
192
+ if (error instanceof Error) {
193
+ throw new TypeError(`Failed to update queue position: ${error.message}`)
194
+ }
195
+
196
+ throw error
197
+ }
198
+ }