@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.
- package/package.json +3 -2
- package/src/carts/destroy.ts +54 -0
- package/src/carts/fetch.ts +20 -0
- package/src/carts/index.ts +13 -0
- package/src/carts/store.ts +75 -0
- package/src/carts/update.ts +78 -0
- package/src/coupons/destroy.ts +49 -0
- package/src/coupons/fetch.ts +510 -0
- package/src/coupons/index.ts +30 -0
- package/src/coupons/store.ts +46 -0
- package/src/coupons/update.ts +147 -0
- package/src/customers/destroy.ts +62 -0
- package/src/customers/fetch.ts +20 -0
- package/src/customers/index.ts +17 -0
- package/src/customers/store.ts +45 -0
- package/src/customers/update.ts +44 -0
- package/src/devices/destroy.ts +54 -0
- package/src/devices/export.ts +98 -0
- package/src/devices/fetch.ts +125 -0
- package/src/devices/index.ts +31 -0
- package/src/devices/store.ts +82 -0
- package/src/devices/update.ts +125 -0
- package/src/errors/destroy.ts +54 -0
- package/src/errors/fetch.ts +197 -0
- package/src/errors/index.ts +28 -0
- package/src/errors/update.ts +116 -0
- package/src/gift-cards/destroy.ts +87 -0
- package/src/gift-cards/fetch.ts +431 -0
- package/src/gift-cards/index.ts +26 -0
- package/src/gift-cards/store.ts +56 -0
- package/src/gift-cards/update.ts +102 -0
- package/src/index.ts +78 -0
- package/src/orders/destroy.ts +111 -0
- package/src/orders/events.ts +121 -0
- package/src/orders/export.ts +158 -0
- package/src/orders/fetch.ts +379 -0
- package/src/orders/guards.ts +261 -0
- package/src/orders/index.ts +91 -0
- package/src/orders/place-order.ts +274 -0
- package/src/orders/store.ts +51 -0
- package/src/orders/totals.ts +190 -0
- package/src/orders/update.ts +164 -0
- package/src/orders/webhook.ts +312 -0
- package/src/payments/destroy.ts +56 -0
- package/src/payments/fetch.ts +288 -0
- package/src/payments/index.ts +16 -0
- package/src/payments/store.ts +63 -0
- package/src/payments/update.ts +52 -0
- package/src/product.ts +0 -0
- package/src/products/categories/destroy.ts +103 -0
- package/src/products/categories/fetch.ts +285 -0
- package/src/products/categories/index.ts +36 -0
- package/src/products/categories/store.ts +87 -0
- package/src/products/categories/update.ts +251 -0
- package/src/products/index.ts +35 -0
- package/src/products/items/destroy.ts +54 -0
- package/src/products/items/fetch.ts +282 -0
- package/src/products/items/index.ts +26 -0
- package/src/products/items/store.ts +84 -0
- package/src/products/items/update.ts +324 -0
- package/src/products/manufacturers/destroy.ts +56 -0
- package/src/products/manufacturers/fetch.ts +117 -0
- package/src/products/manufacturers/index.ts +24 -0
- package/src/products/manufacturers/store.ts +82 -0
- package/src/products/manufacturers/update.ts +113 -0
- package/src/products/reviews/destroy.ts +56 -0
- package/src/products/reviews/fetch.ts +63 -0
- package/src/products/reviews/index.ts +25 -0
- package/src/products/reviews/store.ts +46 -0
- package/src/products/reviews/update.ts +82 -0
- package/src/products/units/destroy.ts +56 -0
- package/src/products/units/fetch.ts +20 -0
- package/src/products/units/index.ts +13 -0
- package/src/products/units/store.ts +162 -0
- package/src/products/units/update.ts +159 -0
- package/src/products/variants/destroy.ts +56 -0
- package/src/products/variants/fetch.ts +20 -0
- package/src/products/variants/index.ts +21 -0
- package/src/products/variants/store.ts +136 -0
- package/src/products/variants/update.ts +104 -0
- package/src/receipts/destroy.ts +54 -0
- package/src/receipts/export.ts +0 -0
- package/src/receipts/fetch.ts +222 -0
- package/src/receipts/index.ts +24 -0
- package/src/receipts/printer.ts +69 -0
- package/src/receipts/store.ts +69 -0
- package/src/receipts/update.ts +124 -0
- package/src/shippings/delivery-routes/destroy.ts +54 -0
- package/src/shippings/delivery-routes/fetch.ts +42 -0
- package/src/shippings/delivery-routes/index.ts +26 -0
- package/src/shippings/delivery-routes/store.ts +69 -0
- package/src/shippings/delivery-routes/update.ts +120 -0
- package/src/shippings/digital-deliveries/destroy.ts +111 -0
- package/src/shippings/digital-deliveries/fetch.ts +20 -0
- package/src/shippings/digital-deliveries/index.ts +26 -0
- package/src/shippings/digital-deliveries/store.ts +76 -0
- package/src/shippings/digital-deliveries/update.ts +129 -0
- package/src/shippings/drivers/destroy.ts +78 -0
- package/src/shippings/drivers/fetch.ts +20 -0
- package/src/shippings/drivers/index.ts +24 -0
- package/src/shippings/drivers/store.ts +69 -0
- package/src/shippings/drivers/update.ts +117 -0
- package/src/shippings/index.ts +39 -0
- package/src/shippings/license-keys/destroy.ts +111 -0
- package/src/shippings/license-keys/fetch.ts +20 -0
- package/src/shippings/license-keys/index.ts +26 -0
- package/src/shippings/license-keys/store.ts +77 -0
- package/src/shippings/license-keys/update.ts +117 -0
- package/src/shippings/shipping-methods/destroy.ts +111 -0
- package/src/shippings/shipping-methods/fetch.ts +62 -0
- package/src/shippings/shipping-methods/index.ts +28 -0
- package/src/shippings/shipping-methods/store.ts +123 -0
- package/src/shippings/shipping-methods/update.ts +120 -0
- package/src/shippings/shipping-rates/destroy.ts +102 -0
- package/src/shippings/shipping-rates/fetch.ts +320 -0
- package/src/shippings/shipping-rates/index.ts +36 -0
- package/src/shippings/shipping-rates/store.ts +102 -0
- package/src/shippings/shipping-rates/update.ts +139 -0
- package/src/shippings/shipping-zones/destroy.ts +111 -0
- package/src/shippings/shipping-zones/fetch.ts +96 -0
- package/src/shippings/shipping-zones/index.ts +26 -0
- package/src/shippings/shipping-zones/store.ts +74 -0
- package/src/shippings/shipping-zones/update.ts +156 -0
- package/src/tax/destroy.ts +54 -0
- package/src/tax/fetch.ts +20 -0
- package/src/tax/index.ts +24 -0
- package/src/tax/store.ts +69 -0
- package/src/tax/update.ts +119 -0
- package/src/tests/coupons.test.ts +90 -0
- package/src/tests/customers.test.ts +39 -0
- package/src/tests/device.test.ts +111 -0
- package/src/tests/digitals.test.ts +31 -0
- package/src/tests/drivers.test.ts +25 -0
- package/src/tests/gift-cards.test.ts +36 -0
- package/src/tests/license.test.ts +31 -0
- package/src/tests/manufacturers.test.ts +80 -0
- package/src/tests/orders.test.ts +25 -0
- package/src/tests/payments.test.ts +75 -0
- package/src/tests/rates.test.ts +367 -0
- package/src/tests/receipts.test.ts +287 -0
- package/src/tests/restaurant.test.ts +522 -0
- package/src/tests/reviews.test.ts +165 -0
- package/src/tests/routes.test.ts +51 -0
- package/src/tests/setup.ts +149 -0
- package/src/tests/shipping.test.ts +88 -0
- package/src/tests/tax.test.ts +25 -0
- package/src/tests/units.test.ts +110 -0
- package/src/tests/variants.test.ts +133 -0
- package/src/tests/waitlist.test.ts +303 -0
- package/src/tests/zones.test.ts +86 -0
- package/src/types.ts +312 -0
- package/src/utils/typed-stats.ts +67 -0
- package/src/waitlists/index.ts +19 -0
- package/src/waitlists/products/destroy.ts +65 -0
- package/src/waitlists/products/export.ts +113 -0
- package/src/waitlists/products/fetch.ts +362 -0
- package/src/waitlists/products/index.ts +33 -0
- package/src/waitlists/products/store.ts +112 -0
- package/src/waitlists/products/update.ts +125 -0
- package/src/waitlists/restaurant/destroy.ts +65 -0
- package/src/waitlists/restaurant/export.ts +107 -0
- package/src/waitlists/restaurant/fetch.ts +538 -0
- package/src/waitlists/restaurant/index.ts +43 -0
- package/src/waitlists/restaurant/store.ts +109 -0
- package/src/waitlists/restaurant/update.ts +198 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
type WaitlistProductJsonResponse = ModelRow<typeof WaitlistProduct>
|
|
2
|
+
type NewWaitlistProduct = NewModelData<typeof WaitlistProduct>
|
|
3
|
+
import { randomUUIDv7 } from 'bun'
|
|
4
|
+
import { db } from '@stacksjs/database'
|
|
5
|
+
import { formatDate } from '@stacksjs/orm'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Create a new waitlist product entry
|
|
9
|
+
*
|
|
10
|
+
* @param data Waitlist product data to store
|
|
11
|
+
* @returns The newly created waitlist product record
|
|
12
|
+
*/
|
|
13
|
+
export async function store(data: NewWaitlistProduct): Promise<WaitlistProductJsonResponse> {
|
|
14
|
+
try {
|
|
15
|
+
const d = data as Record<string, unknown>
|
|
16
|
+
const waitlistData: Record<string, any> = {
|
|
17
|
+
name: data.name,
|
|
18
|
+
email: data.email,
|
|
19
|
+
phone: data.phone,
|
|
20
|
+
quantity: data.quantity ?? d.party_size,
|
|
21
|
+
notification_preference: d.notification_preference,
|
|
22
|
+
source: data.source,
|
|
23
|
+
notes: data.notes,
|
|
24
|
+
product_id: data.product_id,
|
|
25
|
+
customer_id: data.customer_id,
|
|
26
|
+
uuid: randomUUIDv7(),
|
|
27
|
+
status: data.status || 'waiting',
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if ((data as any).notified_at !== undefined)
|
|
31
|
+
waitlistData.notified_at = typeof (data as any).notified_at === 'number' ? formatDate((data as any).notified_at) : (data as any).notified_at
|
|
32
|
+
|
|
33
|
+
if ((data as any).purchased_at !== undefined)
|
|
34
|
+
waitlistData.purchased_at = typeof (data as any).purchased_at === 'number' ? formatDate((data as any).purchased_at) : (data as any).purchased_at
|
|
35
|
+
|
|
36
|
+
if ((data as any).cancelled_at !== undefined)
|
|
37
|
+
waitlistData.cancelled_at = typeof (data as any).cancelled_at === 'number' ? formatDate((data as any).cancelled_at) : (data as any).cancelled_at
|
|
38
|
+
|
|
39
|
+
const result = await db
|
|
40
|
+
.insertInto('waitlist_products')
|
|
41
|
+
.values(waitlistData)
|
|
42
|
+
.returningAll()
|
|
43
|
+
.executeTakeFirst()
|
|
44
|
+
|
|
45
|
+
if (!result)
|
|
46
|
+
throw new Error('Failed to create waitlist product')
|
|
47
|
+
|
|
48
|
+
return result as WaitlistProductJsonResponse
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (error instanceof Error) {
|
|
52
|
+
throw new TypeError(`Failed to create waitlist product: ${error.message}`)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
throw error
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Create multiple waitlist product entries at once
|
|
61
|
+
*
|
|
62
|
+
* @param data Array of waitlist product data to store
|
|
63
|
+
* @returns Number of waitlist products created
|
|
64
|
+
*/
|
|
65
|
+
export async function bulkStore(data: NewWaitlistProduct[]): Promise<number> {
|
|
66
|
+
if (!data.length)
|
|
67
|
+
return 0
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
const waitlistDataArray = data.map((item) => {
|
|
71
|
+
const i = item as Record<string, unknown>
|
|
72
|
+
const entry: Record<string, any> = {
|
|
73
|
+
name: item.name,
|
|
74
|
+
email: item.email,
|
|
75
|
+
phone: item.phone,
|
|
76
|
+
quantity: item.quantity ?? i.party_size,
|
|
77
|
+
notification_preference: i.notification_preference,
|
|
78
|
+
source: item.source,
|
|
79
|
+
notes: item.notes,
|
|
80
|
+
product_id: item.product_id,
|
|
81
|
+
customer_id: item.customer_id,
|
|
82
|
+
uuid: randomUUIDv7(),
|
|
83
|
+
status: item.status || 'waiting',
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if ((item as any).notified_at !== undefined)
|
|
87
|
+
entry.notified_at = typeof (item as any).notified_at === 'number' ? formatDate((item as any).notified_at) : (item as any).notified_at
|
|
88
|
+
|
|
89
|
+
if ((item as any).purchased_at !== undefined)
|
|
90
|
+
entry.purchased_at = typeof (item as any).purchased_at === 'number' ? formatDate((item as any).purchased_at) : (item as any).purchased_at
|
|
91
|
+
|
|
92
|
+
if ((item as any).cancelled_at !== undefined)
|
|
93
|
+
entry.cancelled_at = typeof (item as any).cancelled_at === 'number' ? formatDate((item as any).cancelled_at) : (item as any).cancelled_at
|
|
94
|
+
|
|
95
|
+
return entry
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
const result = await db
|
|
99
|
+
.insertInto('waitlist_products')
|
|
100
|
+
.values(waitlistDataArray)
|
|
101
|
+
.executeTakeFirst()
|
|
102
|
+
|
|
103
|
+
return Number(result.numInsertedOrUpdatedRows)
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (error instanceof Error) {
|
|
107
|
+
throw new TypeError(`Failed to create waitlist products in bulk: ${error.message}`)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
throw error
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { db } from '@stacksjs/database'
|
|
2
|
+
import { formatDate } from '@stacksjs/orm'
|
|
3
|
+
type WaitlistProductJsonResponse = ModelRow<typeof WaitlistProduct>
|
|
4
|
+
type WaitlistProductUpdate = UpdateModelData<typeof WaitlistProduct>
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Update a waitlist product
|
|
8
|
+
*
|
|
9
|
+
* @param id The id of the waitlist product to update
|
|
10
|
+
* @param data The waitlist product data to update
|
|
11
|
+
* @returns The updated waitlist product record
|
|
12
|
+
*/
|
|
13
|
+
export async function update(id: number, data: WaitlistProductUpdate): Promise<WaitlistProductJsonResponse> {
|
|
14
|
+
try {
|
|
15
|
+
if (!id)
|
|
16
|
+
throw new Error('Waitlist product ID is required for update')
|
|
17
|
+
|
|
18
|
+
const d = data as Record<string, unknown>
|
|
19
|
+
const result = await db
|
|
20
|
+
.updateTable('waitlist_products')
|
|
21
|
+
.set({
|
|
22
|
+
name: data.name,
|
|
23
|
+
email: data.email,
|
|
24
|
+
phone: data.phone,
|
|
25
|
+
quantity: data.quantity ?? d.party_size,
|
|
26
|
+
notification_preference: d.notification_preference,
|
|
27
|
+
source: data.source,
|
|
28
|
+
notes: data.notes,
|
|
29
|
+
status: data.status,
|
|
30
|
+
product_id: data.product_id,
|
|
31
|
+
customer_id: data.customer_id,
|
|
32
|
+
notified_at: d.notified_at,
|
|
33
|
+
purchased_at: d.purchased_at,
|
|
34
|
+
cancelled_at: d.cancelled_at,
|
|
35
|
+
updated_at: formatDate(new Date()),
|
|
36
|
+
})
|
|
37
|
+
.where('id', '=', id)
|
|
38
|
+
.returningAll()
|
|
39
|
+
.executeTakeFirst()
|
|
40
|
+
|
|
41
|
+
if (!result)
|
|
42
|
+
throw new Error('Failed to update waitlist product')
|
|
43
|
+
|
|
44
|
+
return result as WaitlistProductJsonResponse
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error instanceof Error) {
|
|
48
|
+
throw new TypeError(`Failed to update waitlist product: ${error.message}`)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
throw error
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Update a waitlist product's status
|
|
57
|
+
*
|
|
58
|
+
* @param id The ID of the waitlist product
|
|
59
|
+
* @param status The new status
|
|
60
|
+
* @returns The updated waitlist product with the new status
|
|
61
|
+
*/
|
|
62
|
+
export async function updateStatus(
|
|
63
|
+
id: number,
|
|
64
|
+
status: 'waiting' | 'purchased' | 'notified' | 'cancelled',
|
|
65
|
+
): Promise<WaitlistProductJsonResponse> {
|
|
66
|
+
try {
|
|
67
|
+
const result = await db
|
|
68
|
+
.updateTable('waitlist_products')
|
|
69
|
+
.set({
|
|
70
|
+
status,
|
|
71
|
+
updated_at: formatDate(new Date()),
|
|
72
|
+
})
|
|
73
|
+
.where('id', '=', id)
|
|
74
|
+
.returningAll()
|
|
75
|
+
.executeTakeFirst()
|
|
76
|
+
|
|
77
|
+
if (!result)
|
|
78
|
+
throw new Error('Failed to update waitlist product status')
|
|
79
|
+
|
|
80
|
+
return result as WaitlistProductJsonResponse
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (error instanceof Error) {
|
|
84
|
+
throw new TypeError(`Failed to update waitlist product status: ${error.message}`)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
throw error
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Update party size for a waitlist product
|
|
93
|
+
*
|
|
94
|
+
* @param id The ID of the waitlist product
|
|
95
|
+
* @param partySize The updated party size
|
|
96
|
+
* @returns The updated waitlist product
|
|
97
|
+
*/
|
|
98
|
+
export async function updatePartySize(
|
|
99
|
+
id: number,
|
|
100
|
+
partySize: number,
|
|
101
|
+
): Promise<WaitlistProductJsonResponse> {
|
|
102
|
+
try {
|
|
103
|
+
const result = await db
|
|
104
|
+
.updateTable('waitlist_products')
|
|
105
|
+
.set({
|
|
106
|
+
quantity: partySize,
|
|
107
|
+
updated_at: formatDate(new Date()),
|
|
108
|
+
})
|
|
109
|
+
.where('id', '=', id)
|
|
110
|
+
.returningAll()
|
|
111
|
+
.executeTakeFirst()
|
|
112
|
+
|
|
113
|
+
if (!result)
|
|
114
|
+
throw new Error('Failed to update party size')
|
|
115
|
+
|
|
116
|
+
return result as WaitlistProductJsonResponse
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
if (error instanceof Error) {
|
|
120
|
+
throw new TypeError(`Failed to update party size: ${error.message}`)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
throw error
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
type WaitlistRestaurantJsonResponse = ModelRow<typeof WaitlistRestaurant>
|
|
2
|
+
import { db } from '@stacksjs/database'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Delete a restaurant waitlist entry by ID
|
|
6
|
+
*
|
|
7
|
+
* @param id The ID of the restaurant waitlist entry to delete
|
|
8
|
+
* @returns The deleted restaurant waitlist record
|
|
9
|
+
*/
|
|
10
|
+
export async function destroy(id: number): Promise<WaitlistRestaurantJsonResponse | undefined> {
|
|
11
|
+
try {
|
|
12
|
+
// First get the restaurant waitlist entry to return it after deletion
|
|
13
|
+
const waitlistEntry = await db
|
|
14
|
+
.selectFrom('waitlist_restaurants')
|
|
15
|
+
.where('id', '=', id)
|
|
16
|
+
.selectAll()
|
|
17
|
+
.executeTakeFirst()
|
|
18
|
+
|
|
19
|
+
if (!waitlistEntry)
|
|
20
|
+
return undefined
|
|
21
|
+
|
|
22
|
+
// Delete the restaurant waitlist entry
|
|
23
|
+
await db
|
|
24
|
+
.deleteFrom('waitlist_restaurants')
|
|
25
|
+
.where('id', '=', id)
|
|
26
|
+
.execute()
|
|
27
|
+
|
|
28
|
+
return waitlistEntry as WaitlistRestaurantJsonResponse
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (error instanceof Error) {
|
|
32
|
+
throw new TypeError(`Failed to delete restaurant waitlist entry: ${error.message}`)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
throw error
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Delete multiple restaurant waitlist entries by their IDs
|
|
41
|
+
*
|
|
42
|
+
* @param ids Array of restaurant waitlist entry IDs to delete
|
|
43
|
+
* @returns Number of restaurant waitlist entries deleted
|
|
44
|
+
*/
|
|
45
|
+
export async function bulkDestroy(ids: number[]): Promise<number> {
|
|
46
|
+
if (!ids.length)
|
|
47
|
+
return 0
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
// Delete all restaurant waitlist entries with the given IDs
|
|
51
|
+
const result = await db
|
|
52
|
+
.deleteFrom('waitlist_restaurants')
|
|
53
|
+
.where('id', 'in', ids)
|
|
54
|
+
.execute()
|
|
55
|
+
|
|
56
|
+
return (result as any).length || 0
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error instanceof Error) {
|
|
60
|
+
throw new TypeError(`Failed to delete restaurant waitlist entries in bulk: ${error.message}`)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
throw error
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
type WaitlistRestaurantJsonResponse = ModelRow<typeof WaitlistRestaurant>
|
|
2
|
+
import type { SpreadsheetWrapper } from 'ts-spreadsheets'
|
|
3
|
+
import { createSpreadsheet } from 'ts-spreadsheets'
|
|
4
|
+
import { fetchAll } from './fetch'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents the structure of an exported restaurant waitlist entry
|
|
8
|
+
*/
|
|
9
|
+
export interface ExportedRestaurantWaitlist {
|
|
10
|
+
'ID': number
|
|
11
|
+
'Name': string
|
|
12
|
+
'Phone': string
|
|
13
|
+
'Party Size': number
|
|
14
|
+
'Table Preference': string
|
|
15
|
+
'Status': string
|
|
16
|
+
'Quoted Wait Time': number
|
|
17
|
+
'Actual Wait Time': number
|
|
18
|
+
'Check In Time': string
|
|
19
|
+
'Created At': string
|
|
20
|
+
'Notes': string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Export restaurant waitlist entries to a spreadsheet
|
|
25
|
+
* @param format The format of the spreadsheet (default is CSV)
|
|
26
|
+
* @returns Spreadsheet object ready for download or storage
|
|
27
|
+
*/
|
|
28
|
+
export async function exportRestaurantWaitlist(format: 'csv' | 'excel' = 'csv'): Promise<SpreadsheetWrapper> {
|
|
29
|
+
// Fetch all restaurant waitlist entries
|
|
30
|
+
const waitlistEntries = await fetchAll()
|
|
31
|
+
|
|
32
|
+
// Prepare data for spreadsheet
|
|
33
|
+
const spreadsheetData = prepareRestaurantWaitlistForExport(waitlistEntries)
|
|
34
|
+
|
|
35
|
+
// Create and return spreadsheet
|
|
36
|
+
return createSpreadsheet(spreadsheetData, { type: format })
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Prepare restaurant waitlist data for spreadsheet export
|
|
41
|
+
* @param waitlistEntries Array of restaurant waitlist entry objects
|
|
42
|
+
* @returns Spreadsheet data structure
|
|
43
|
+
*/
|
|
44
|
+
function prepareRestaurantWaitlistForExport(waitlistEntries: WaitlistRestaurantJsonResponse[]) {
|
|
45
|
+
// Define headings
|
|
46
|
+
const headings: (keyof ExportedRestaurantWaitlist)[] = [
|
|
47
|
+
'ID',
|
|
48
|
+
'Name',
|
|
49
|
+
'Phone',
|
|
50
|
+
'Party Size',
|
|
51
|
+
'Table Preference',
|
|
52
|
+
'Status',
|
|
53
|
+
'Quoted Wait Time',
|
|
54
|
+
'Actual Wait Time',
|
|
55
|
+
'Check In Time',
|
|
56
|
+
'Created At',
|
|
57
|
+
'Notes',
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
// Transform waitlist entries into export format
|
|
61
|
+
const data = waitlistEntries.map((entry) => {
|
|
62
|
+
return [
|
|
63
|
+
entry.id,
|
|
64
|
+
entry.name,
|
|
65
|
+
entry.phone || 'N/A',
|
|
66
|
+
entry.partySize,
|
|
67
|
+
entry.tablePreference,
|
|
68
|
+
entry.status,
|
|
69
|
+
(entry as any).quoted_wait_time || 'N/A',
|
|
70
|
+
(entry as any).actual_wait_time || 'N/A',
|
|
71
|
+
entry.checkInTime || 'N/A',
|
|
72
|
+
entry.created_at,
|
|
73
|
+
(entry as any).notes || 'N/A',
|
|
74
|
+
]
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
return { headings, data }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Export restaurant waitlist entries and automatically download
|
|
82
|
+
* @param format The format of the spreadsheet (default is CSV)
|
|
83
|
+
* @param filename Optional filename for the download
|
|
84
|
+
* @returns Download response
|
|
85
|
+
*/
|
|
86
|
+
export async function downloadRestaurantWaitlist(format: 'csv' | 'excel' = 'csv', filename?: string): Promise<Response> {
|
|
87
|
+
const spreadsheet = await exportRestaurantWaitlist(format)
|
|
88
|
+
|
|
89
|
+
// Use default filename if not provided
|
|
90
|
+
const defaultFilename = `restaurant_waitlist_export_${new Date().toISOString().split('T')[0]}.${format}`
|
|
91
|
+
return spreadsheet.download(filename || defaultFilename)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Store restaurant waitlist export to disk
|
|
96
|
+
* @param format The format of the spreadsheet (default is CSV)
|
|
97
|
+
* @param path Optional path to store the file
|
|
98
|
+
* @returns Path where the file is stored
|
|
99
|
+
*/
|
|
100
|
+
export async function storeRestaurantWaitlistExport(format: 'csv' | 'excel' = 'csv', path?: string): Promise<void> {
|
|
101
|
+
const spreadsheet = await exportRestaurantWaitlist(format)
|
|
102
|
+
|
|
103
|
+
// Use default path and filename if not provided
|
|
104
|
+
const defaultPath = `restaurant_waitlist_export_${new Date().toISOString().split('T')[0]}.${format}`
|
|
105
|
+
|
|
106
|
+
spreadsheet.store(path || defaultPath)
|
|
107
|
+
}
|