Skip to content

Commit 76a01f0

Browse files
chore: wip
1 parent 45be7e6 commit 76a01f0

File tree

9 files changed

+63
-64
lines changed

9 files changed

+63
-64
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { GiftCardJsonResponse } from '../../../../orm/src/models/GiftCard'
2-
import type { FetchGiftCardsOptions, GiftCardResponse, GiftCardStats } from '../../types'
2+
import type { GiftCardStats } from '../../types'
33
import { db, sql } from '@stacksjs/database'
44

55
/**
@@ -39,12 +39,14 @@ export async function fetchByCode(code: string): Promise<GiftCardJsonResponse |
3939
/**
4040
* Fetch active gift cards (is_active = true and not expired)
4141
*/
42-
export async function fetchActive(options: FetchGiftCardsOptions = {}): Promise<GiftCardResponse> {
43-
return fetchPaginated({
44-
...options,
45-
is_active: true,
46-
status: 'ACTIVE',
47-
})
42+
export async function fetchActive(): Promise<GiftCardJsonResponse> {
43+
const giftCards = await db
44+
.selectFrom('gift_cards')
45+
.where('is_active', '=', true)
46+
.selectAll()
47+
.execute()
48+
49+
return giftCards
4850
}
4951

5052
/**

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import type { OrderJsonResponse } from '../../../../orm/src/models/Order'
12
import type {
23
OrderStats,
3-
OrderType,
44
OrderTypeCount,
55
StatusCount,
66
} from '../../types'
@@ -9,7 +9,7 @@ import { db } from '@stacksjs/database'
99
/**
1010
* Fetch all orders from the database with their items
1111
*/
12-
export async function fetchAll(): Promise<OrderType[]> {
12+
export async function fetchAll(): Promise<OrderJsonResponse[]> {
1313
const orders = await db
1414
.selectFrom('orders')
1515
.selectAll()
@@ -33,7 +33,7 @@ export async function fetchAll(): Promise<OrderType[]> {
3333
/**
3434
* Fetch an order by ID
3535
*/
36-
export async function fetchById(id: number): Promise<OrderType | undefined> {
36+
export async function fetchById(id: number): Promise<OrderJsonResponse | undefined> {
3737
const order = await db
3838
.selectFrom('orders')
3939
.where('id', '=', id)
@@ -352,7 +352,7 @@ export async function fetchDailyOrderTrends(daysRange: number = 30): Promise<{
352352
.execute()
353353

354354
return dailyOrders.map(day => ({
355-
date: day.created_at,
355+
date: day.created_at!,
356356
order_count: Number(day.order_count || 0),
357357
revenue: Number(day.revenue || 0),
358358
}))
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
// Export all order functions
22

3-
// Fetch operations
4-
export {
5-
fetchAll,
6-
fetchById,
7-
fetchStats,
8-
compareOrdersByPeriod,
9-
calculateOrderMetrics,
10-
fetchDailyOrderTrends
11-
} from './fetch'
12-
133
// Delete operations
144
export {
5+
bulkDestroy,
6+
bulkSoftDelete,
157
destroy,
168
softDelete,
17-
bulkDestroy,
18-
bulkSoftDelete
199
} from './destroy'
2010

2111
// Export operations
2212
export {
23-
exportOrders,
2413
downloadOrders,
25-
storeOrdersExport
26-
} from './export'
14+
exportOrders,
15+
storeOrdersExport,
16+
} from './export'
17+
18+
// Fetch operations
19+
export {
20+
calculateOrderMetrics,
21+
compareOrdersByPeriod,
22+
fetchAll,
23+
fetchById,
24+
fetchDailyOrderTrends,
25+
fetchStats,
26+
} from './fetch'

storage/framework/core/commerce/src/variants/destroy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ export async function bulkDestroy(ids: number[]): Promise<number> {
5353

5454
throw error
5555
}
56-
}
56+
}
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
export {
2-
store,
3-
bulkStore,
4-
formatVariantOptions,
5-
generateVariantCombinations
6-
} from './store'
7-
8-
export {
9-
update,
10-
bulkUpdate,
11-
updateStatus
12-
} from './update'
13-
14-
export {
15-
destroy,
16-
bulkDestroy
17-
} from './destroy'
2+
bulkDestroy,
3+
destroy,
4+
} from './destroy'
5+
6+
export {
7+
bulkStore,
8+
formatVariantOptions,
9+
generateVariantCombinations,
10+
store,
11+
} from './store'
12+
13+
export {
14+
bulkUpdate,
15+
update,
16+
updateStatus,
17+
} from './update'

storage/framework/core/commerce/src/variants/update.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Import dependencies
22
import type { ProductVariantRequestType } from '@stacksjs/orm'
3-
import { db } from '@stacksjs/database'
43
import type { ProductVariantJsonResponse } from '../../../../orm/src/models/ProductVariant'
4+
import { db } from '@stacksjs/database'
55

66
/**
77
* Update an existing product variant
@@ -82,7 +82,6 @@ export async function bulkUpdate(updates: Array<{
8282
updated_at: new Date(),
8383
}
8484

85-
8685
// Skip if no fields to update
8786
if (Object.keys(variantData).length === 0)
8887
continue
@@ -122,9 +121,9 @@ export async function updateStatus(id: number, status: string): Promise<boolean>
122121
try {
123122
const result = await db
124123
.updateTable('product_variants')
125-
.set({
124+
.set({
126125
status,
127-
updated_at: new Date()
126+
updated_at: new Date(),
128127
})
129128
.where('id', '=', id)
130129
.executeTakeFirst()
@@ -138,4 +137,4 @@ export async function updateStatus(id: number, status: string): Promise<boolean>
138137

139138
throw error
140139
}
141-
}
140+
}

storage/framework/core/commerce/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// Import the CustomerTable type from the ORM
32
import type { CouponModel } from '../../orm/src/models/Coupon'
43
import type {
@@ -59,7 +58,6 @@ export interface UpdateCustomerInput {
5958
user_id?: number
6059
}
6160

62-
6361
// Define the structure of an order item
6462
export interface OrderItem {
6563
product_id: string

storage/framework/defaults/models/ecommerce/GiftCard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default {
2929
observe: true,
3030
},
3131

32-
belongsTo: ['User'], // For purchaser_id
32+
belongsTo: ['Customer'],
3333
hasMany: ['Order'],
3434

3535
attributes: {

storage/framework/orm/src/models/GiftCard.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Generated, Insertable, RawBuilder, Selectable, Updateable } from '@stacksjs/database'
22
import type { Operator } from '@stacksjs/orm'
3+
import type { CustomerModel } from './Customer'
34
import type { OrderModel } from './Order'
4-
import type { UserModel } from './User'
55
import { randomUUIDv7 } from 'bun'
66
import { cache } from '@stacksjs/cache'
77
import { sql } from '@stacksjs/database'
@@ -10,11 +10,11 @@ import { dispatch } from '@stacksjs/events'
1010

1111
import { DB, SubqueryBuilder } from '@stacksjs/orm'
1212

13-
import User from './User'
13+
import Customer from './Customer'
1414

1515
export interface GiftCardsTable {
1616
id: Generated<number>
17-
user_id: number
17+
customer_id: number
1818
code: string
1919
initial_balance: number
2020
current_balance: number
@@ -149,12 +149,12 @@ export class GiftCardModel {
149149
return this.attributes.orders
150150
}
151151

152-
get user_id(): number {
153-
return this.attributes.user_id
152+
get customer_id(): number {
153+
return this.attributes.customer_id
154154
}
155155

156-
get user(): UserModel | undefined {
157-
return this.attributes.user
156+
get customer(): CustomerModel | undefined {
157+
return this.attributes.customer
158158
}
159159

160160
get id(): number {
@@ -1846,12 +1846,12 @@ export class GiftCardModel {
18461846
.execute()
18471847
}
18481848

1849-
async userBelong(): Promise<UserModel> {
1850-
if (this.user_id === undefined)
1849+
async customerBelong(): Promise<CustomerModel> {
1850+
if (this.customer_id === undefined)
18511851
throw new HttpError(500, 'Relation Error!')
18521852

1853-
const model = await User
1854-
.where('id', '=', this.user_id)
1853+
const model = await Customer
1854+
.where('id', '=', this.customer_id)
18551855
.first()
18561856

18571857
if (!model)
@@ -1931,8 +1931,8 @@ export class GiftCardModel {
19311931
updated_at: this.updated_at,
19321932

19331933
orders: this.orders,
1934-
user_id: this.user_id,
1935-
user: this.user,
1934+
customer_id: this.customer_id,
1935+
customer: this.customer,
19361936
...this.customColumns,
19371937
}
19381938

0 commit comments

Comments
 (0)