1
1
import type { Generated , Insertable , RawBuilder , Selectable , Updateable } from '@stacksjs/database'
2
2
import type { Operator } from '@stacksjs/orm'
3
+ import type { CustomerModel } from './Customer'
3
4
import type { OrderModel } from './Order'
4
- import type { UserModel } from './User'
5
5
import { randomUUIDv7 } from 'bun'
6
6
import { cache } from '@stacksjs/cache'
7
7
import { sql } from '@stacksjs/database'
@@ -10,14 +10,14 @@ import { dispatch } from '@stacksjs/events'
10
10
11
11
import { DB , SubqueryBuilder } from '@stacksjs/orm'
12
12
13
- import Order from './Order '
13
+ import Customer from './Customer '
14
14
15
- import User from './User '
15
+ import Order from './Order '
16
16
17
17
export interface PaymentsTable {
18
18
id : Generated < number >
19
19
order_id : number
20
- user_id : number
20
+ customer_id : number
21
21
amount : number
22
22
method : string
23
23
status : string
@@ -153,12 +153,12 @@ export class PaymentModel {
153
153
return this . attributes . order
154
154
}
155
155
156
- get user_id ( ) : number {
157
- return this . attributes . user_id
156
+ get customer_id ( ) : number {
157
+ return this . attributes . customer_id
158
158
}
159
159
160
- get user ( ) : UserModel | undefined {
161
- return this . attributes . user
160
+ get customer ( ) : CustomerModel | undefined {
161
+ return this . attributes . customer
162
162
}
163
163
164
164
get id ( ) : number {
@@ -1816,12 +1816,12 @@ export class PaymentModel {
1816
1816
return model
1817
1817
}
1818
1818
1819
- async userBelong ( ) : Promise < UserModel > {
1820
- if ( this . user_id === undefined )
1819
+ async customerBelong ( ) : Promise < CustomerModel > {
1820
+ if ( this . customer_id === undefined )
1821
1821
throw new HttpError ( 500 , 'Relation Error!' )
1822
1822
1823
- const model = await User
1824
- . where ( 'id' , '=' , this . user_id )
1823
+ const model = await Customer
1824
+ . where ( 'id' , '=' , this . customer_id )
1825
1825
. first ( )
1826
1826
1827
1827
if ( ! model )
@@ -1899,8 +1899,8 @@ export class PaymentModel {
1899
1899
1900
1900
order_id : this . order_id ,
1901
1901
order : this . order ,
1902
- user_id : this . user_id ,
1903
- user : this . user ,
1902
+ customer_id : this . customer_id ,
1903
+ customer : this . customer ,
1904
1904
...this . customColumns ,
1905
1905
}
1906
1906
0 commit comments