File tree Expand file tree Collapse file tree 6 files changed +98
-1
lines changed
storage/framework/core/commerce/src Expand file tree Collapse file tree 6 files changed +98
-1
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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'
File renamed without changes.
Original file line number Diff line number Diff line change
1
+ // Export functions from destroy.ts
2
+ export {
3
+ bulkRemove ,
4
+ remove ,
5
+ } from './destroy'
6
+
7
+ // Export functions from fetch.ts
1
8
export {
2
9
fetchById ,
3
10
type FetchCustomersOptions ,
4
11
fetchPaginated ,
5
12
type PaginatedCustomers ,
6
13
} 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'
File renamed without changes.
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ export {
16
16
bulkSoftDelete ,
17
17
destroy ,
18
18
softDelete ,
19
- } from './delete '
19
+ } from './destroy '
20
20
21
21
// Export fetch functionality
22
22
export {
You can’t perform that action at this time.
0 commit comments