Skip to content

Commit 41b325b

Browse files
chore: wip
1 parent f6f85d5 commit 41b325b

File tree

15 files changed

+98
-120
lines changed

15 files changed

+98
-120
lines changed

storage/framework/core/orm/src/utils.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,22 +1771,22 @@ export async function generateModelString(
17711771
17721772
17731773
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()
17771775
17781776
${instanceSoftDeleteStatements}
17791777
1780-
query = query.selectAll()
1781-
1782-
const model = await query.executeTakeFirst()
1783-
17841778
if (model === undefined)
17851779
throw new HttpError(404, \`No ${modelName}Model results for \${id}\`)
17861780
17871781
cache.getOrSet(\`${formattedModelName}:\${id}\`, JSON.stringify(model))
17881782
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
17901790
}
17911791
17921792
static async findMany(ids: number[]): Promise<${modelName}Model[]> {

storage/framework/orm/src/models/AccessToken.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,16 @@ export class AccessTokenModel {
123123
}
124124

125125
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()
133127

134128
if (model === undefined)
135129
throw new HttpError(404, `No AccessTokenModel results for ${id}`)
136130

137131
cache.getOrSet(`accesstoken:${id}`, JSON.stringify(model))
138132

139-
return instance.parseResult(new AccessTokenModel(model))
133+
const data = new AccessTokenModel(model as AccessTokenType)
134+
135+
return data
140136
}
141137

142138
static async findMany(ids: number[]): Promise<AccessTokenModel[]> {

storage/framework/orm/src/models/Deployment.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,20 @@ export class DeploymentModel {
149149
}
150150

151151
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()
159153

160154
if (model === undefined)
161155
throw new HttpError(404, `No DeploymentModel results for ${id}`)
162156

163157
cache.getOrSet(`deployment:${id}`, JSON.stringify(model))
164158

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
166166
}
167167

168168
static async findMany(ids: number[]): Promise<DeploymentModel[]> {

storage/framework/orm/src/models/Error.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,16 @@ export class ErrorModel {
127127
}
128128

129129
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()
137131

138132
if (model === undefined)
139133
throw new HttpError(404, `No ErrorModel results for ${id}`)
140134

141135
cache.getOrSet(`error:${id}`, JSON.stringify(model))
142136

143-
return instance.parseResult(new ErrorModel(model))
137+
const data = new ErrorModel(model as ErrorType)
138+
139+
return data
144140
}
145141

146142
static async findMany(ids: number[]): Promise<ErrorModel[]> {

storage/framework/orm/src/models/PaymentMethod.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,20 +159,22 @@ export class PaymentMethodModel {
159159
}
160160

161161
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()
169163

170164
if (model === undefined)
171165
throw new HttpError(404, `No PaymentMethodModel results for ${id}`)
172166

173167
cache.getOrSet(`paymentmethod:${id}`, JSON.stringify(model))
174168

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
176178
}
177179

178180
static async findMany(ids: number[]): Promise<PaymentMethodModel[]> {

storage/framework/orm/src/models/Post.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,20 @@ export class PostModel {
130130
}
131131

132132
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()
140134

141135
if (model === undefined)
142136
throw new HttpError(404, `No PostModel results for ${id}`)
143137

144138
cache.getOrSet(`post:${id}`, JSON.stringify(model))
145139

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
147147
}
148148

149149
static async findMany(ids: number[]): Promise<PostModel[]> {

storage/framework/orm/src/models/Product.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,16 @@ export class ProductModel {
134134
}
135135

136136
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()
144138

145139
if (model === undefined)
146140
throw new HttpError(404, `No ProductModel results for ${id}`)
147141

148142
cache.getOrSet(`product:${id}`, JSON.stringify(model))
149143

150-
return instance.parseResult(new ProductModel(model))
144+
const data = new ProductModel(model as ProductType)
145+
146+
return data
151147
}
152148

153149
static async findMany(ids: number[]): Promise<ProductModel[]> {

storage/framework/orm/src/models/Project.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,16 @@ export class ProjectModel {
121121
}
122122

123123
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()
131125

132126
if (model === undefined)
133127
throw new HttpError(404, `No ProjectModel results for ${id}`)
134128

135129
cache.getOrSet(`project:${id}`, JSON.stringify(model))
136130

137-
return instance.parseResult(new ProjectModel(model))
131+
const data = new ProjectModel(model as ProjectType)
132+
133+
return data
138134
}
139135

140136
static async findMany(ids: number[]): Promise<ProjectModel[]> {

storage/framework/orm/src/models/Release.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,16 @@ export class ReleaseModel {
112112
}
113113

114114
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()
122116

123117
if (model === undefined)
124118
throw new HttpError(404, `No ReleaseModel results for ${id}`)
125119

126120
cache.getOrSet(`release:${id}`, JSON.stringify(model))
127121

128-
return instance.parseResult(new ReleaseModel(model))
122+
const data = new ReleaseModel(model as ReleaseType)
123+
124+
return data
129125
}
130126

131127
static async findMany(ids: number[]): Promise<ReleaseModel[]> {

storage/framework/orm/src/models/Subscriber.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,16 @@ export class SubscriberModel {
112112
}
113113

114114
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()
122116

123117
if (model === undefined)
124118
throw new HttpError(404, `No SubscriberModel results for ${id}`)
125119

126120
cache.getOrSet(`subscriber:${id}`, JSON.stringify(model))
127121

128-
return instance.parseResult(new SubscriberModel(model))
122+
const data = new SubscriberModel(model as SubscriberType)
123+
124+
return data
129125
}
130126

131127
static async findMany(ids: number[]): Promise<SubscriberModel[]> {

0 commit comments

Comments
 (0)