Skip to content

Commit 038044e

Browse files
chore: wip
1 parent 7312c19 commit 038044e

File tree

6 files changed

+98
-1
lines changed

6 files changed

+98
-1
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { db } from '@stacksjs/database'
2+
3+
/**
4+
* Delete a coupon by ID
5+
* @param id The ID of the coupon to delete
6+
* @returns A boolean indicating success
7+
*/
8+
export async function deleteCoupon(id: number): Promise<boolean> {
9+
const result = await db
10+
.deleteFrom('coupons')
11+
.where('id', '=', id)
12+
.executeTakeFirst()
13+
14+
return !!result
15+
}
16+
17+
/**
18+
* Delete multiple coupons by IDs
19+
* @param ids Array of coupon IDs to delete
20+
* @returns Number of deleted coupons
21+
*/
22+
export async function deleteCoupons(ids: number[]): Promise<number> {
23+
if (!ids.length) {
24+
return 0
25+
}
26+
27+
const result = await db
28+
.deleteFrom('coupons')
29+
.where('id', 'in', ids)
30+
.execute()
31+
32+
return result.length || 0
33+
}
34+
35+
/**
36+
* Delete expired coupons
37+
* @returns The number of deleted coupons
38+
*/
39+
export async function deleteExpiredCoupons(): Promise<number> {
40+
const currentDate = new Date().toISOString().split('T')[0]
41+
42+
const result = await db
43+
.deleteFrom('coupons')
44+
.where('end_date', '<', currentDate)
45+
.execute()
46+
47+
return result.length || 0
48+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Export types that might be needed elsewhere
2+
export type {
3+
CouponJsonResponse,
4+
CouponResponse,
5+
} from '../../../../orm/src/models/Coupon'
6+
7+
export type {
8+
CouponStats,
9+
} from '../../types'
10+
11+
// Export functions from destroy.ts
12+
export {
13+
deleteCoupon,
14+
deleteCoupons,
15+
deleteExpiredCoupons,
16+
} from './destroy'
17+
18+
// Export functions from fetch.ts
19+
export {
20+
fetchActive,
21+
fetchAll,
22+
fetchByCode,
23+
fetchById,
24+
type FetchCouponsOptions,
25+
fetchPaginated,
26+
fetchStats,
27+
} from './fetch'
28+
29+
// Export functions from store.ts
30+
export {
31+
store,
32+
} from './store'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1+
// Export functions from destroy.ts
2+
export {
3+
bulkRemove,
4+
remove,
5+
} from './destroy'
6+
7+
// Export functions from fetch.ts
18
export {
29
fetchById,
310
type FetchCustomersOptions,
411
fetchPaginated,
512
type PaginatedCustomers,
613
} from './fetch'
14+
15+
// Export functions from store.ts
16+
export {
17+
store,
18+
} from './store'
19+
20+
// Export functions from update.ts
21+
export {
22+
update,
23+
} from './update'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export {
1616
bulkSoftDelete,
1717
destroy,
1818
softDelete,
19-
} from './delete'
19+
} from './destroy'
2020

2121
// Export fetch functionality
2222
export {

0 commit comments

Comments
 (0)