1
- import type { PaymentTransactionModel } from '../../../../orm/src/models/PaymentTransaction'
1
+ import type { PaymentTransactionModel , PaymentTransactionsTable } from '../../../../orm/src/models/PaymentTransaction'
2
2
import type { UserModel } from '../../../../orm/src/models/User'
3
- import PaymentProduct from '../../../../orm/src/models/PaymentProduct'
4
- import { PaymentTransaction } from '../../../../orm/src/models/PaymentTransaction'
3
+ import { db } from '@stacksjs/database'
5
4
6
5
export interface ManageTransaction {
7
- store : ( user : UserModel , productId : number ) => Promise < PaymentTransactionModel >
8
- list : ( user : UserModel ) => Promise < PaymentTransactionModel [ ] >
6
+ store : ( user : UserModel , productId : number ) => Promise < PaymentTransactionsTable >
7
+ list : ( user : UserModel ) => Promise < PaymentTransactionsTable [ ] >
9
8
}
10
9
11
10
export const manageTransaction : ManageTransaction = ( ( ) => {
12
- async function store ( user : UserModel , productId : number ) : Promise < PaymentTransactionModel > {
13
- const product = await PaymentProduct . find ( productId )
11
+ async function store ( user : UserModel , productId : number ) : Promise < PaymentTransactionsTable > {
12
+ const product = await db . selectFrom ( 'payment_products' ) . where ( 'id' , '=' , productId ) . selectAll ( ) . executeTakeFirst ( )
14
13
15
14
const data = {
16
15
name : product ?. name ,
@@ -22,13 +21,15 @@ export const manageTransaction: ManageTransaction = (() => {
22
21
user_id : user . id ,
23
22
}
24
23
25
- const transaction = await PaymentTransaction . create ( data )
24
+ const createdTransaction = await db . insertInto ( 'payment_transactions' ) . values ( data ) . executeTakeFirst ( )
25
+
26
+ const transaction = await db . selectFrom ( 'payment_transactions' ) . where ( 'id' , '=' , Number ( createdTransaction . insertId ) ) . selectAll ( ) . executeTakeFirst ( )
26
27
27
28
return transaction
28
29
}
29
30
30
- async function list ( user : UserModel ) : Promise < PaymentTransactionModel [ ] > {
31
- const transaction = await PaymentTransaction . where ( 'user_id' , user . id ) . get ( )
31
+ async function list ( user : UserModel ) : Promise < PaymentTransactionsTable [ ] > {
32
+ const transaction = await db . selectFrom ( 'payment_transactions' ) . where ( 'user_id' , '=' , user . id ) . selectAll ( ) . execute ( )
32
33
33
34
return transaction
34
35
}
0 commit comments