File tree Expand file tree Collapse file tree 15 files changed +98
-120
lines changed Expand file tree Collapse file tree 15 files changed +98
-120
lines changed Original file line number Diff line number Diff line change @@ -1771,22 +1771,22 @@ export async function generateModelString(
1771
1771
1772
1772
1773
1773
static async findOrFail(id: number): Promise<${ modelName } Model> {
1774
- let query = db.selectFrom('${ tableName } ').where('id', '=', id)
1775
-
1776
- const instance = new ${ modelName } Model(null)
1774
+ const model = await db.selectFrom('${ tableName } ').where('id', '=', id).selectAll().executeTakeFirst()
1777
1775
1778
1776
${ instanceSoftDeleteStatements }
1779
1777
1780
- query = query.selectAll()
1781
-
1782
- const model = await query.executeTakeFirst()
1783
-
1784
1778
if (model === undefined)
1785
1779
throw new HttpError(404, \`No ${ modelName } Model results for \${id}\`)
1786
1780
1787
1781
cache.getOrSet(\`${ formattedModelName } :\${id}\`, JSON.stringify(model))
1788
1782
1789
- return instance.parseResult(new ${ modelName } Model(model))
1783
+ ${ relationDeclare }
1784
+ ${ relationStringMany }
1785
+ ${ relationStringBelong }
1786
+
1787
+ const data = new ${ modelName } Model(model as ${ modelName } Type)
1788
+
1789
+ return data
1790
1790
}
1791
1791
1792
1792
static async findMany(ids: number[]): Promise<${ modelName } Model[]> {
Original file line number Diff line number Diff line change @@ -123,20 +123,16 @@ export class AccessTokenModel {
123
123
}
124
124
125
125
static async findOrFail ( id : number ) : Promise < AccessTokenModel > {
126
- let query = db . selectFrom ( 'personal_access_tokens' ) . where ( 'id' , '=' , id )
127
-
128
- const instance = new AccessTokenModel ( null )
129
-
130
- query = query . selectAll ( )
131
-
132
- const model = await query . executeTakeFirst ( )
126
+ const model = await db . selectFrom ( 'personal_access_tokens' ) . where ( 'id' , '=' , id ) . selectAll ( ) . executeTakeFirst ( )
133
127
134
128
if ( model === undefined )
135
129
throw new HttpError ( 404 , `No AccessTokenModel results for ${ id } ` )
136
130
137
131
cache . getOrSet ( `accesstoken:${ id } ` , JSON . stringify ( model ) )
138
132
139
- return instance . parseResult ( new AccessTokenModel ( model ) )
133
+ const data = new AccessTokenModel ( model as AccessTokenType )
134
+
135
+ return data
140
136
}
141
137
142
138
static async findMany ( ids : number [ ] ) : Promise < AccessTokenModel [ ] > {
Original file line number Diff line number Diff line change @@ -149,20 +149,20 @@ export class DeploymentModel {
149
149
}
150
150
151
151
static async findOrFail ( id : number ) : Promise < DeploymentModel > {
152
- let query = db . selectFrom ( 'deployments' ) . where ( 'id' , '=' , id )
153
-
154
- const instance = new DeploymentModel ( null )
155
-
156
- query = query . selectAll ( )
157
-
158
- const model = await query . executeTakeFirst ( )
152
+ const model = await db . selectFrom ( 'deployments' ) . where ( 'id' , '=' , id ) . selectAll ( ) . executeTakeFirst ( )
159
153
160
154
if ( model === undefined )
161
155
throw new HttpError ( 404 , `No DeploymentModel results for ${ id } ` )
162
156
163
157
cache . getOrSet ( `deployment:${ id } ` , JSON . stringify ( model ) )
164
158
165
- return instance . parseResult ( new DeploymentModel ( model ) )
159
+ const instance = new DeploymentModel ( model as DeploymentType )
160
+
161
+ model . user = await instance . userBelong ( )
162
+
163
+ const data = new DeploymentModel ( model as DeploymentType )
164
+
165
+ return data
166
166
}
167
167
168
168
static async findMany ( ids : number [ ] ) : Promise < DeploymentModel [ ] > {
Original file line number Diff line number Diff line change @@ -127,20 +127,16 @@ export class ErrorModel {
127
127
}
128
128
129
129
static async findOrFail ( id : number ) : Promise < ErrorModel > {
130
- let query = db . selectFrom ( 'errors' ) . where ( 'id' , '=' , id )
131
-
132
- const instance = new ErrorModel ( null )
133
-
134
- query = query . selectAll ( )
135
-
136
- const model = await query . executeTakeFirst ( )
130
+ const model = await db . selectFrom ( 'errors' ) . where ( 'id' , '=' , id ) . selectAll ( ) . executeTakeFirst ( )
137
131
138
132
if ( model === undefined )
139
133
throw new HttpError ( 404 , `No ErrorModel results for ${ id } ` )
140
134
141
135
cache . getOrSet ( `error:${ id } ` , JSON . stringify ( model ) )
142
136
143
- return instance . parseResult ( new ErrorModel ( model ) )
137
+ const data = new ErrorModel ( model as ErrorType )
138
+
139
+ return data
144
140
}
145
141
146
142
static async findMany ( ids : number [ ] ) : Promise < ErrorModel [ ] > {
Original file line number Diff line number Diff line change @@ -159,20 +159,22 @@ export class PaymentMethodModel {
159
159
}
160
160
161
161
static async findOrFail ( id : number ) : Promise < PaymentMethodModel > {
162
- let query = db . selectFrom ( 'payment_methods' ) . where ( 'id' , '=' , id )
163
-
164
- const instance = new PaymentMethodModel ( null )
165
-
166
- query = query . selectAll ( )
167
-
168
- const model = await query . executeTakeFirst ( )
162
+ const model = await db . selectFrom ( 'payment_methods' ) . where ( 'id' , '=' , id ) . selectAll ( ) . executeTakeFirst ( )
169
163
170
164
if ( model === undefined )
171
165
throw new HttpError ( 404 , `No PaymentMethodModel results for ${ id } ` )
172
166
173
167
cache . getOrSet ( `paymentmethod:${ id } ` , JSON . stringify ( model ) )
174
168
175
- return instance . parseResult ( new PaymentMethodModel ( model ) )
169
+ const instance = new PaymentMethodModel ( model as PaymentMethodType )
170
+
171
+ model . transactions = await instance . transactionsHasMany ( )
172
+
173
+ model . user = await instance . userBelong ( )
174
+
175
+ const data = new PaymentMethodModel ( model as PaymentMethodType )
176
+
177
+ return data
176
178
}
177
179
178
180
static async findMany ( ids : number [ ] ) : Promise < PaymentMethodModel [ ] > {
Original file line number Diff line number Diff line change @@ -130,20 +130,20 @@ export class PostModel {
130
130
}
131
131
132
132
static async findOrFail ( id : number ) : Promise < PostModel > {
133
- let query = db . selectFrom ( 'posts' ) . where ( 'id' , '=' , id )
134
-
135
- const instance = new PostModel ( null )
136
-
137
- query = query . selectAll ( )
138
-
139
- const model = await query . executeTakeFirst ( )
133
+ const model = await db . selectFrom ( 'posts' ) . where ( 'id' , '=' , id ) . selectAll ( ) . executeTakeFirst ( )
140
134
141
135
if ( model === undefined )
142
136
throw new HttpError ( 404 , `No PostModel results for ${ id } ` )
143
137
144
138
cache . getOrSet ( `post:${ id } ` , JSON . stringify ( model ) )
145
139
146
- return instance . parseResult ( new PostModel ( model ) )
140
+ const instance = new PostModel ( model as PostType )
141
+
142
+ model . user = await instance . userBelong ( )
143
+
144
+ const data = new PostModel ( model as PostType )
145
+
146
+ return data
147
147
}
148
148
149
149
static async findMany ( ids : number [ ] ) : Promise < PostModel [ ] > {
Original file line number Diff line number Diff line change @@ -134,20 +134,16 @@ export class ProductModel {
134
134
}
135
135
136
136
static async findOrFail ( id : number ) : Promise < ProductModel > {
137
- let query = db . selectFrom ( 'products' ) . where ( 'id' , '=' , id )
138
-
139
- const instance = new ProductModel ( null )
140
-
141
- query = query . selectAll ( )
142
-
143
- const model = await query . executeTakeFirst ( )
137
+ const model = await db . selectFrom ( 'products' ) . where ( 'id' , '=' , id ) . selectAll ( ) . executeTakeFirst ( )
144
138
145
139
if ( model === undefined )
146
140
throw new HttpError ( 404 , `No ProductModel results for ${ id } ` )
147
141
148
142
cache . getOrSet ( `product:${ id } ` , JSON . stringify ( model ) )
149
143
150
- return instance . parseResult ( new ProductModel ( model ) )
144
+ const data = new ProductModel ( model as ProductType )
145
+
146
+ return data
151
147
}
152
148
153
149
static async findMany ( ids : number [ ] ) : Promise < ProductModel [ ] > {
Original file line number Diff line number Diff line change @@ -121,20 +121,16 @@ export class ProjectModel {
121
121
}
122
122
123
123
static async findOrFail ( id : number ) : Promise < ProjectModel > {
124
- let query = db . selectFrom ( 'projects' ) . where ( 'id' , '=' , id )
125
-
126
- const instance = new ProjectModel ( null )
127
-
128
- query = query . selectAll ( )
129
-
130
- const model = await query . executeTakeFirst ( )
124
+ const model = await db . selectFrom ( 'projects' ) . where ( 'id' , '=' , id ) . selectAll ( ) . executeTakeFirst ( )
131
125
132
126
if ( model === undefined )
133
127
throw new HttpError ( 404 , `No ProjectModel results for ${ id } ` )
134
128
135
129
cache . getOrSet ( `project:${ id } ` , JSON . stringify ( model ) )
136
130
137
- return instance . parseResult ( new ProjectModel ( model ) )
131
+ const data = new ProjectModel ( model as ProjectType )
132
+
133
+ return data
138
134
}
139
135
140
136
static async findMany ( ids : number [ ] ) : Promise < ProjectModel [ ] > {
Original file line number Diff line number Diff line change @@ -112,20 +112,16 @@ export class ReleaseModel {
112
112
}
113
113
114
114
static async findOrFail ( id : number ) : Promise < ReleaseModel > {
115
- let query = db . selectFrom ( 'releases' ) . where ( 'id' , '=' , id )
116
-
117
- const instance = new ReleaseModel ( null )
118
-
119
- query = query . selectAll ( )
120
-
121
- const model = await query . executeTakeFirst ( )
115
+ const model = await db . selectFrom ( 'releases' ) . where ( 'id' , '=' , id ) . selectAll ( ) . executeTakeFirst ( )
122
116
123
117
if ( model === undefined )
124
118
throw new HttpError ( 404 , `No ReleaseModel results for ${ id } ` )
125
119
126
120
cache . getOrSet ( `release:${ id } ` , JSON . stringify ( model ) )
127
121
128
- return instance . parseResult ( new ReleaseModel ( model ) )
122
+ const data = new ReleaseModel ( model as ReleaseType )
123
+
124
+ return data
129
125
}
130
126
131
127
static async findMany ( ids : number [ ] ) : Promise < ReleaseModel [ ] > {
Original file line number Diff line number Diff line change @@ -112,20 +112,16 @@ export class SubscriberModel {
112
112
}
113
113
114
114
static async findOrFail ( id : number ) : Promise < SubscriberModel > {
115
- let query = db . selectFrom ( 'subscribers' ) . where ( 'id' , '=' , id )
116
-
117
- const instance = new SubscriberModel ( null )
118
-
119
- query = query . selectAll ( )
120
-
121
- const model = await query . executeTakeFirst ( )
115
+ const model = await db . selectFrom ( 'subscribers' ) . where ( 'id' , '=' , id ) . selectAll ( ) . executeTakeFirst ( )
122
116
123
117
if ( model === undefined )
124
118
throw new HttpError ( 404 , `No SubscriberModel results for ${ id } ` )
125
119
126
120
cache . getOrSet ( `subscriber:${ id } ` , JSON . stringify ( model ) )
127
121
128
- return instance . parseResult ( new SubscriberModel ( model ) )
122
+ const data = new SubscriberModel ( model as SubscriberType )
123
+
124
+ return data
129
125
}
130
126
131
127
static async findMany ( ids : number [ ] ) : Promise < SubscriberModel [ ] > {
You can’t perform that action at this time.
0 commit comments