Skip to content

Commit 674d69e

Browse files
chore: wip
1 parent 58fbe3b commit 674d69e

File tree

8 files changed

+62
-34
lines changed

8 files changed

+62
-34
lines changed

storage/framework/core/commerce/src/customers/fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { db } from '@stacksjs/database'
44
/**
55
* Fetch a customer by ID
66
*/
7-
export async function fetchById(id: number | bigint): Promise<CustomerJsonResponse | undefined> {
7+
export async function fetchById(id: number): Promise<CustomerJsonResponse | undefined> {
88
return await db
99
.selectFrom('customers')
1010
.where('id', '=', id)

storage/framework/core/commerce/src/customers/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function store(data: NewCustomer): Promise<CustomerJsonResponse> {
2020

2121
const insertId = result.insertId || Number(result.numInsertedOrUpdatedRows)
2222

23-
const customerResult = await fetchById(insertId) as CustomerJsonResponse
23+
const customerResult = await fetchById(Number(insertId)) as CustomerJsonResponse
2424

2525
return customerResult
2626
}

storage/framework/core/commerce/src/gift-cards/update.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { GiftCardJsonResponse, GiftCardUpdate } from '@stacksjs/orm'
22
import { db } from '@stacksjs/database'
3-
import { formatDate, toTimestamp } from '@stacksjs/orm'
3+
import { formatDate } from '@stacksjs/orm'
44
import { fetchById } from './fetch'
55

66
/**
@@ -78,7 +78,7 @@ export async function updateBalance(id: number, amount: number): Promise<GiftCar
7878
.updateTable('gift_cards')
7979
.set({
8080
current_balance: newBalance,
81-
last_used_date: toTimestamp(new Date()),
81+
last_used_date: formatDate(new Date()),
8282
status: newBalance === 0 ? 'USED' : 'ACTIVE',
8383
updated_at: formatDate(new Date()),
8484
})

storage/framework/core/commerce/src/orders/export.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ async function fetchAllWithDetails(): Promise<OrderWithTotals[] | []> {
6161

6262
const orderItemsMap = allOrderItems.reduce<Record<number, { totalItems: number, totalPrice: number }>>(
6363
(acc, item) => {
64+
if (!item.order_id)
65+
return acc // Skip items without order_id
66+
6467
if (!acc[item.order_id]) {
6568
acc[item.order_id] = {
6669
totalItems: 0,

storage/framework/core/commerce/src/receipts/fetch.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ReceiptJsonResponse } from '@stacksjs/orm'
22
import { db } from '@stacksjs/database'
3+
import { formatDate } from '@stacksjs/orm'
34

45
/**
56
* Fetch a print log by ID
@@ -27,8 +28,8 @@ export async function fetchAll(): Promise<ReceiptJsonResponse[]> {
2728
* @returns Object containing counts for each status and total
2829
*/
2930
export async function fetchPrintJobStats(
30-
startDate: number,
31-
endDate: number,
31+
startDate: Date,
32+
endDate: Date,
3233
): Promise<{
3334
total: number
3435
success: number
@@ -40,7 +41,7 @@ export async function fetchPrintJobStats(
4041
}> {
4142
const stats = await db
4243
.selectFrom('receipts')
43-
.where('timestamp', '>=', startDate)
44+
.where('timestamp', '>=', formatDate(startDate))
4445
.where('timestamp', '<=', endDate)
4546
.select([
4647
db.fn.count<number>('id').as('total'),
@@ -72,8 +73,8 @@ export async function fetchPrintJobStats(
7273
* @returns Object containing success rate percentage and detailed counts
7374
*/
7475
export async function fetchSuccessRate(
75-
startDate: number,
76-
endDate: number,
76+
startDate: Date,
77+
endDate: Date,
7778
): Promise<{
7879
successRate: number
7980
total: number
@@ -83,8 +84,8 @@ export async function fetchSuccessRate(
8384
}> {
8485
const stats = await db
8586
.selectFrom('receipts')
86-
.where('timestamp', '>=', startDate)
87-
.where('timestamp', '<=', endDate)
87+
.where('timestamp', '>=', formatDate(startDate))
88+
.where('timestamp', '<=', formatDate(endDate))
8889
.select([
8990
db.fn.count<number>('id').as('total'),
9091
db.fn.count<number>('id').filterWhere('status', '=', 'success').as('success'),
@@ -118,17 +119,17 @@ export async function fetchSuccessRate(
118119
* @returns Object containing total pages and average pages per receipt
119120
*/
120121
export async function fetchPageStats(
121-
startDate: number,
122-
endDate: number,
122+
startDate: Date,
123+
endDate: Date,
123124
): Promise<{
124125
totalPages: number
125126
averagePagesPerReceipt: number
126127
totalReceipts: number
127128
}> {
128129
const stats = await db
129130
.selectFrom('receipts')
130-
.where('timestamp', '>=', startDate)
131-
.where('timestamp', '<=', endDate)
131+
.where('timestamp', '>=', formatDate(startDate))
132+
.where('timestamp', '<=', formatDate(endDate))
132133
.select([
133134
db.fn.count<number>('id').as('totalReceipts'),
134135
db.fn.sum<number>('pages').as('totalPages'),
@@ -151,8 +152,8 @@ export async function fetchPageStats(
151152
* @returns Object containing average print time and related statistics
152153
*/
153154
export async function fetchPrintTimeStats(
154-
startDate: number,
155-
endDate: number,
155+
startDate: Date,
156+
endDate: Date,
156157
): Promise<{
157158
averageDuration: number
158159
minDuration: number
@@ -161,8 +162,8 @@ export async function fetchPrintTimeStats(
161162
}> {
162163
const stats = await db
163164
.selectFrom('receipts')
164-
.where('timestamp', '>=', startDate)
165-
.where('timestamp', '<=', endDate)
165+
.where('timestamp', '>=', formatDate(startDate))
166+
.where('timestamp', '<=', formatDate(endDate))
166167
.select([
167168
db.fn.count<number>('id').as('totalJobs'),
168169
db.fn.avg<number>('duration').as('averageDuration'),
@@ -187,8 +188,8 @@ export async function fetchPrintTimeStats(
187188
* @returns Object containing prints per hour statistics
188189
*/
189190
export async function fetchPrintsPerHour(
190-
startDate: number,
191-
endDate: number,
191+
startDate: Date,
192+
endDate: Date,
192193
): Promise<{
193194
totalPrints: number
194195
totalHours: number
@@ -200,13 +201,13 @@ export async function fetchPrintsPerHour(
200201
}> {
201202
const receipts = await db
202203
.selectFrom('receipts')
203-
.where('timestamp', '>=', startDate)
204-
.where('timestamp', '<=', endDate)
204+
.where('timestamp', '>=', formatDate(startDate))
205+
.where('timestamp', '<=', formatDate(endDate))
205206
.selectAll()
206207
.execute()
207208

208209
const totalPrints = receipts.length
209-
const totalHours = Math.ceil((endDate - startDate) / (1000 * 60 * 60))
210+
const totalHours = Math.ceil((endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60))
210211
const printsPerHour = totalHours > 0 ? Math.round(totalPrints / totalHours) : 0
211212

212213
const hourlyBreakdown = Array.from({ length: 24 }, (_, i) => ({

storage/framework/core/commerce/src/receipts/printer.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,48 @@ interface Receipt {
3131
}
3232

3333
class TSPIVPrinter implements PrinterDriver {
34-
async print(receipt: Receipt): Promise<void> {
34+
async print(printJob: PrintJob): Promise<void> {
3535
// eslint-disable-next-line no-console
36-
console.log('TSP IV Printer: Printing receipt', receipt)
36+
console.log('TSP IV Printer: Printing receipt', printJob.receipt)
3737
// Implement actual printing logic here
3838
}
3939

40-
async cleanUp(): Promise<void> {
40+
async cleanUp(printer: Printer): Promise<void> {
4141
// eslint-disable-next-line no-console
4242
console.log('TSP IV Printer: Cleaning up print job...')
4343
// Implement actual cleanup logic here
4444
}
4545

46-
async checkStatus(): Promise<boolean> {
46+
async checkStatus(printer: Printer): Promise<boolean> {
4747
// eslint-disable-next-line no-console
4848
console.log('TSP IV Printer: Checking online status...')
4949
// Implement actual status check logic here
5050
return true // Return actual status
5151
}
52+
53+
async findPrinters(): Promise<Printer[]> {
54+
// eslint-disable-next-line no-console
55+
console.log('TSP IV Printer: Finding printers...')
56+
return [] // Return actual printers
57+
}
58+
59+
async setup(printer: Printer): Promise<void> {
60+
// eslint-disable-next-line no-console
61+
console.log('TSP IV Printer: Setting up printer...')
62+
// Implement actual setup logic here
63+
}
64+
65+
async restart(): Promise<void> {
66+
// eslint-disable-next-line no-console
67+
console.log('TSP IV Printer: Restarting...')
68+
// Implement actual restart logic here
69+
}
70+
71+
async canInteractWithPrinter(printer: Printer): Promise<boolean> {
72+
// eslint-disable-next-line no-console
73+
console.log('TSP IV Printer: Checking if can interact with printer...')
74+
return true // Return actual capability
75+
}
5276
}
5377

5478
// Export the TSP IV printer instance

storage/framework/core/commerce/src/shippings/shipping-rates/update.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ export async function bulkUpdate(updates: Array<{
8686
* @param data The update data to apply
8787
* @returns Number of shipping rates updated
8888
*/
89-
export async function updateByZone(zone: string, data: ShippingRateUpdate): Promise<number> {
89+
export async function updateByZone(zone: number, data: ShippingRateUpdate): Promise<number> {
9090
try {
9191
const result = await db
9292
.updateTable('shipping_rates')
9393
.set({
9494
...data,
9595
updated_at: formatDate(new Date()),
9696
})
97-
.where('zone', '=', zone)
97+
.where('zone_id', '=', zone)
9898
.executeTakeFirst()
9999

100100
return Number(result.numUpdatedRows)

storage/framework/defaults/models/commerce/ShippingRate.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ export default {
1111
useUuid: true,
1212
useTimestamps: true,
1313
useSearch: {
14-
displayable: ['id', 'method', 'zone', 'weightFrom', 'weightTo', 'rate'],
15-
searchable: ['method', 'zone'],
16-
sortable: ['method', 'zone', 'weightFrom', 'weightTo', 'rate', 'createdAt', 'updatedAt'],
17-
filterable: ['method', 'zone'],
14+
displayable: ['id', 'method', 'weightFrom', 'weightTo', 'rate'],
15+
searchable: ['method'],
16+
sortable: ['method', 'weightFrom', 'weightTo', 'rate', 'createdAt', 'updatedAt'],
17+
filterable: ['method'],
1818
},
1919

2020
useSeeder: {

0 commit comments

Comments
 (0)