@stacksjs/commerce 0.70.54 → 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,159 @@
1
+ import { db } from '@stacksjs/database'
2
+ import { formatDate } from '@stacksjs/orm'
3
+ type ProductUnitJsonResponse = ModelRow<typeof ProductUnit>
4
+ type ProductUnitUpdate = UpdateModelData<typeof ProductUnit>
5
+
6
+ /**
7
+ * Update a product unit
8
+ *
9
+ * @param id The ID of the product unit
10
+ * @param data The product unit data to update
11
+ * @returns The updated product unit record
12
+ */
13
+ export async function update(id: number, data: ProductUnitUpdate): Promise<ProductUnitJsonResponse> {
14
+ try {
15
+ if (!id)
16
+ throw new Error('Product unit ID is required for update')
17
+
18
+ const result = await db
19
+ .updateTable('product_units')
20
+ .set({
21
+ ...data,
22
+ updated_at: formatDate(new Date()),
23
+ })
24
+ .where('id', '=', id)
25
+ .returningAll()
26
+ .executeTakeFirst()
27
+
28
+ if (!result)
29
+ throw new Error('Failed to update product unit')
30
+
31
+ // If this unit is set as default, update all other units of the same type
32
+ const d = data as Record<string, unknown>
33
+ if (d.is_default === true && data.type) {
34
+ await db
35
+ .updateTable('product_units')
36
+ .set({ is_default: false })
37
+ .where('type', '=', data.type)
38
+ .where('id', '!=', id)
39
+ .execute()
40
+ }
41
+
42
+ return result as ProductUnitJsonResponse
43
+ }
44
+ catch (error) {
45
+ if (error instanceof Error) {
46
+ throw new TypeError(`Failed to update product unit: ${error.message}`)
47
+ }
48
+
49
+ throw error
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Update multiple product units at once
55
+ *
56
+ * @param data Array of product unit updates
57
+ * @returns Number of product units updated
58
+ */
59
+ export async function bulkUpdate(data: ProductUnitUpdate[]): Promise<number> {
60
+ if (!data.length)
61
+ return 0
62
+
63
+ let updatedCount = 0
64
+
65
+ try {
66
+ for (const unit of data) {
67
+ const unitRecord = unit as Record<string, unknown>
68
+ if (!unitRecord.id)
69
+ continue
70
+
71
+ // Support both flat format and { id, data: { ... } } format
72
+ const updateFields = unitRecord.data && typeof unitRecord.data === 'object'
73
+ ? unitRecord.data as Record<string, unknown>
74
+ : { ...unitRecord }
75
+ delete (updateFields as Record<string, unknown>).id
76
+
77
+ const result = await db
78
+ .updateTable('product_units')
79
+ .set({
80
+ ...updateFields,
81
+ updated_at: formatDate(new Date()),
82
+ })
83
+ .where('id', '=', unitRecord.id)
84
+ .executeTakeFirst()
85
+
86
+ // If this unit is set as default, update all other units of the same type
87
+ const fields = updateFields as Record<string, unknown>
88
+ if (fields.is_default === true && fields.type) {
89
+ await db
90
+ .updateTable('product_units')
91
+ .set({ is_default: false })
92
+ .where('type', '=', fields.type as string)
93
+ .where('id', '!=', unitRecord.id)
94
+ .execute()
95
+ }
96
+
97
+ if (Number(result.numUpdatedRows) > 0)
98
+ updatedCount++
99
+ }
100
+
101
+ return updatedCount
102
+ }
103
+ catch (error) {
104
+ if (error instanceof Error) {
105
+ throw new TypeError(`Failed to update product units in bulk: ${error.message}`)
106
+ }
107
+
108
+ throw error
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Update the default status of a product unit
114
+ *
115
+ * @param id The ID of the product unit
116
+ * @param isDefault The new default status value
117
+ * @returns True if the status was updated successfully
118
+ */
119
+ export async function updateDefaultStatus(id: number, isDefault: boolean): Promise<boolean> {
120
+ try {
121
+ // First get the unit type to update other units if needed
122
+ const unit = await db
123
+ .selectFrom('product_units')
124
+ .select('type' as any)
125
+ .where('id', '=', id)
126
+ .executeTakeFirst() as { type: string } | undefined
127
+
128
+ if (!unit)
129
+ return false
130
+
131
+ const result = await db
132
+ .updateTable('product_units')
133
+ .set({
134
+ is_default: isDefault,
135
+ updated_at: formatDate(new Date()),
136
+ })
137
+ .where('id', '=', id)
138
+ .executeTakeFirst()
139
+
140
+ // If setting this unit as default, update all other units of the same type
141
+ if (isDefault && unit.type) {
142
+ await db
143
+ .updateTable('product_units')
144
+ .set({ is_default: false })
145
+ .where('type', '=', unit.type)
146
+ .where('id', '!=', id)
147
+ .execute()
148
+ }
149
+
150
+ return Number(result.numUpdatedRows) > 0
151
+ }
152
+ catch (error) {
153
+ if (error instanceof Error) {
154
+ throw new TypeError(`Failed to update product unit default status: ${error.message}`)
155
+ }
156
+
157
+ throw error
158
+ }
159
+ }
@@ -0,0 +1,56 @@
1
+ import { db } from '@stacksjs/database'
2
+
3
+ /**
4
+ * Delete a product variant by ID
5
+ *
6
+ * @param id The ID of the product variant to delete
7
+ * @returns True if the product variant was deleted, false otherwise
8
+ */
9
+ export async function destroy(id: number): Promise<boolean> {
10
+ try {
11
+ // Perform the delete operation
12
+ const result = await db
13
+ .deleteFrom('product_variants')
14
+ .where('id', '=', id)
15
+ .executeTakeFirst()
16
+
17
+ // Return true if any row was affected (deleted)
18
+ return Number(result.numDeletedRows) > 0
19
+ }
20
+ catch (error) {
21
+ if (error instanceof Error) {
22
+ throw new TypeError(`Failed to delete product variant: ${error.message}`)
23
+ }
24
+
25
+ throw error
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Delete multiple product variants by ID
31
+ *
32
+ * @param ids Array of product variant IDs to delete
33
+ * @returns Number of product variants deleted
34
+ */
35
+ export async function bulkDestroy(ids: number[]): Promise<number> {
36
+ if (!ids.length)
37
+ return 0
38
+
39
+ try {
40
+ // Perform the delete operation
41
+ const result = await db
42
+ .deleteFrom('product_variants')
43
+ .where('id', 'in', ids)
44
+ .executeTakeFirst()
45
+
46
+ // Return the number of deleted rows
47
+ return Number(result.numDeletedRows)
48
+ }
49
+ catch (error) {
50
+ if (error instanceof Error) {
51
+ throw new TypeError(`Failed to delete product variants: ${error.message}`)
52
+ }
53
+
54
+ throw error
55
+ }
56
+ }
@@ -0,0 +1,20 @@
1
+ type ProductVariantJsonResponse = ModelRow<typeof ProductVariant>
2
+ import { db } from '@stacksjs/database'
3
+
4
+ /**
5
+ * Fetch a product variant by ID
6
+ */
7
+ export async function fetchById(id: number): Promise<ProductVariantJsonResponse | undefined> {
8
+ return await db
9
+ .selectFrom('product_variants')
10
+ .where('id', '=', id)
11
+ .selectAll()
12
+ .executeTakeFirst() as ProductVariantJsonResponse | undefined
13
+ }
14
+
15
+ /**
16
+ * Fetch all product variants
17
+ */
18
+ export async function fetchAll(): Promise<ProductVariantJsonResponse[]> {
19
+ return await db.selectFrom('product_variants').selectAll().execute() as ProductVariantJsonResponse[]
20
+ }
@@ -0,0 +1,21 @@
1
+ export {
2
+ bulkDestroy,
3
+ destroy,
4
+ } from './destroy'
5
+
6
+ export {
7
+ fetchAll,
8
+ fetchById,
9
+ } from './fetch'
10
+
11
+ export {
12
+ bulkStore,
13
+ formatVariantOptions,
14
+ generateVariantCombinations,
15
+ store,
16
+ } from './store'
17
+
18
+ export {
19
+ bulkUpdate,
20
+ update,
21
+ } from './update'
@@ -0,0 +1,136 @@
1
+ type ProductVariantJsonResponse = ModelRow<typeof ProductVariant>
2
+ type NewProductVariant = NewModelData<typeof ProductVariant>
3
+ import { randomUUIDv7 } from 'bun'
4
+ import { db } from '@stacksjs/database'
5
+
6
+ /**
7
+ * Create a new product variant
8
+ *
9
+ * @param data The product variant data to store
10
+ * @returns The newly created product variant record
11
+ */
12
+ export async function store(data: NewProductVariant): Promise<ProductVariantJsonResponse> {
13
+ try {
14
+ const variantData = {
15
+ ...data,
16
+ uuid: randomUUIDv7(),
17
+ }
18
+
19
+ const result = await db
20
+ .insertInto('product_variants')
21
+ .values(variantData)
22
+ .returningAll()
23
+ .executeTakeFirst()
24
+
25
+ if (!result)
26
+ throw new Error('Failed to create product variant')
27
+
28
+ return result as ProductVariantJsonResponse
29
+ }
30
+ catch (error) {
31
+ if (error instanceof Error) {
32
+ throw new TypeError(`Failed to create product variant: ${error.message}`)
33
+ }
34
+
35
+ throw error
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Create multiple product variants at once
41
+ *
42
+ * @param data Array of product variant data to store
43
+ * @returns Number of product variants created
44
+ */
45
+ export async function bulkStore(data: NewProductVariant[]): Promise<number> {
46
+ if (!data.length)
47
+ return 0
48
+
49
+ let createdCount = 0
50
+
51
+ try {
52
+ for (const variant of data) {
53
+ const variantData = {
54
+ ...variant,
55
+ uuid: randomUUIDv7(),
56
+ }
57
+
58
+ await db
59
+ .insertInto('product_variants')
60
+ .values(variantData)
61
+ .execute()
62
+
63
+ createdCount++
64
+ }
65
+
66
+ return createdCount
67
+ }
68
+ catch (error) {
69
+ if (error instanceof Error) {
70
+ throw new TypeError(`Failed to create product variants in bulk: ${error.message}`)
71
+ }
72
+
73
+ throw error
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Generate product variant options from raw input
79
+ *
80
+ * @param rawOptions String array of options
81
+ * @returns Formatted JSON string of options
82
+ */
83
+ export function formatVariantOptions(rawOptions: string[]): string {
84
+ if (!rawOptions || !rawOptions.length)
85
+ return JSON.stringify([])
86
+
87
+ // Clean and normalize the options
88
+ const cleanedOptions = rawOptions.map((option: any) => option.trim()).filter(Boolean)
89
+
90
+ return JSON.stringify(cleanedOptions)
91
+ }
92
+
93
+ /**
94
+ * Create a set of common variant combinations from different option types
95
+ *
96
+ * @param optionSets Object containing option types and their values
97
+ * @returns Array of variant combinations
98
+ *
99
+ * @example
100
+ * // Generate combinations for a t-shirt product
101
+ * const options = {
102
+ * size: ['S', 'M', 'L'],
103
+ * color: ['Red', 'Blue']
104
+ * }
105
+ * // Returns: [
106
+ * // { size: 'S', color: 'Red' },
107
+ * // { size: 'S', color: 'Blue' },
108
+ * // { size: 'M', color: 'Red' },
109
+ * // ...
110
+ * // ]
111
+ */
112
+ export function generateVariantCombinations(optionSets: Record<string, string[]>): Record<string, string>[] {
113
+ const keys = Object.keys(optionSets)
114
+
115
+ if (!keys.length)
116
+ return []
117
+
118
+ // Helper function to create combinations recursively
119
+ function createCombinations(currentIndex: number, currentCombination: Record<string, string>): Record<string, string>[] {
120
+ if (currentIndex === keys.length)
121
+ return [currentCombination]
122
+
123
+ const currentKey = keys[currentIndex]
124
+ const currentOptions = optionSets[currentKey]
125
+ const combinations: Record<string, string>[] = []
126
+
127
+ for (const option of currentOptions) {
128
+ const newCombination = { ...currentCombination, [currentKey]: option }
129
+ combinations.push(...createCombinations(currentIndex + 1, newCombination))
130
+ }
131
+
132
+ return combinations
133
+ }
134
+
135
+ return createCombinations(0, {})
136
+ }
@@ -0,0 +1,104 @@
1
+ import { db } from '@stacksjs/database'
2
+ import { formatDate } from '@stacksjs/orm'
3
+ type ProductVariantJsonResponse = ModelRow<typeof ProductVariant>
4
+ type ProductVariantUpdate = UpdateModelData<typeof ProductVariant>
5
+
6
+ /**
7
+ * Update a product variant
8
+ *
9
+ * @param id The ID of the product variant to update
10
+ * @param data The product variant data to update
11
+ * @returns The updated product variant record
12
+ */
13
+ export async function update(id: number, data: Omit<ProductVariantUpdate, 'id'>): Promise<ProductVariantJsonResponse> {
14
+ try {
15
+ const result = await db
16
+ .updateTable('product_variants')
17
+ .set({
18
+ ...data,
19
+ updated_at: formatDate(new Date()),
20
+ })
21
+ .where('id', '=', id)
22
+ .returningAll()
23
+ .executeTakeFirst()
24
+
25
+ if (!result)
26
+ throw new Error('Failed to update product variant')
27
+
28
+ return result as ProductVariantJsonResponse
29
+ }
30
+ catch (error) {
31
+ if (error instanceof Error)
32
+ throw new TypeError(`Failed to update product variant: ${error.message}`)
33
+
34
+ throw error
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Update multiple product variants at once
40
+ *
41
+ * @param data Array of objects containing variant ID and update data
42
+ * @returns Number of product variants updated
43
+ */
44
+ export async function bulkUpdate(data: ProductVariantUpdate[]): Promise<number> {
45
+ if (!data.length)
46
+ return 0
47
+
48
+ let updatedCount = 0
49
+
50
+ try {
51
+ for (const variant of data) {
52
+ if (!(variant as Record<string, unknown>).id)
53
+ continue
54
+
55
+ const result = await db
56
+ .updateTable('product_variants')
57
+ .set({
58
+ ...variant,
59
+ updated_at: formatDate(new Date()),
60
+ })
61
+ .where('id', '=', (variant as Record<string, unknown>).id)
62
+ .executeTakeFirst()
63
+
64
+ if (Number(result.numUpdatedRows) > 0)
65
+ updatedCount++
66
+ }
67
+
68
+ return updatedCount
69
+ }
70
+ catch (error) {
71
+ if (error instanceof Error)
72
+ throw new TypeError(`Failed to update product variants in bulk: ${error.message}`)
73
+
74
+ throw error
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Update the status of a product variant
80
+ *
81
+ * @param id The ID of the product variant
82
+ * @param status The new status value
83
+ * @returns True if the status was updated successfully
84
+ */
85
+ export async function updateStatus(id: number, status: string): Promise<boolean> {
86
+ try {
87
+ const result = await db
88
+ .updateTable('product_variants')
89
+ .set({
90
+ status,
91
+ updated_at: formatDate(new Date()),
92
+ })
93
+ .where('id', '=', id)
94
+ .executeTakeFirst()
95
+
96
+ return Number(result.numUpdatedRows) > 0
97
+ }
98
+ catch (error) {
99
+ if (error instanceof Error)
100
+ throw new TypeError(`Failed to update product variant status: ${error.message}`)
101
+
102
+ throw error
103
+ }
104
+ }
@@ -0,0 +1,54 @@
1
+ import { db } from '@stacksjs/database'
2
+
3
+ /**
4
+ * Delete a print log by ID
5
+ *
6
+ * @param id The ID of the print log to delete
7
+ * @returns True if the print log was deleted, false otherwise
8
+ */
9
+ export async function destroy(id: number): Promise<boolean> {
10
+ try {
11
+ const result = await db
12
+ .deleteFrom('receipts')
13
+ .where('id', '=', id)
14
+ .executeTakeFirst()
15
+
16
+ return Number(result.numDeletedRows) > 0
17
+ }
18
+ catch (error) {
19
+ if (error instanceof Error) {
20
+ throw new TypeError(`Failed to delete print log: ${error.message}`)
21
+ }
22
+
23
+ throw error
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Delete multiple print logs by ID
29
+ *
30
+ * @param ids Array of print log IDs to delete
31
+ * @returns Number of print logs deleted
32
+ */
33
+ export async function bulkDestroy(ids: number[]): Promise<number> {
34
+ if (!ids.length)
35
+ return 0
36
+
37
+ try {
38
+ // Perform the delete operation
39
+ const result = await db
40
+ .deleteFrom('receipts')
41
+ .where('id', 'in', ids)
42
+ .executeTakeFirst()
43
+
44
+ // Return the number of deleted rows
45
+ return Number(result.numDeletedRows)
46
+ }
47
+ catch (error) {
48
+ if (error instanceof Error) {
49
+ throw new TypeError(`Failed to delete receipts: ${error.message}`)
50
+ }
51
+
52
+ throw error
53
+ }
54
+ }
File without changes