Skip to content

Commit bf5d751

Browse files
chore: wip
1 parent 2caf129 commit bf5d751

File tree

16 files changed

+134
-37
lines changed

16 files changed

+134
-37
lines changed

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,17 +1006,18 @@ export async function generateModelString(
10061006
let uuidQueryMany = ''
10071007
let whereStatements = ''
10081008
let whereFunctionStatements = ''
1009-
let relationMethods = ``
1010-
let relationImports = ``
1011-
let paymentImports = ``
1009+
let relationMethods = ''
1010+
let relationImports = ''
1011+
let paymentImports = ''
10121012
let twoFactorStatements = ''
10131013
let billableStatements = ''
10141014
let displayableStatements = ''
1015-
let mittCreateStatement = ``
1016-
let mittUpdateStatement = ``
1017-
let mittDeleteStatement = ``
1018-
let mittDeleteStaticFindStatement = ``
1019-
let mittDeleteFindStatement = ``
1015+
let removeInstanceStatment = ''
1016+
let mittCreateStatement = ''
1017+
let mittUpdateStatement = ''
1018+
let mittDeleteStatement = ''
1019+
let mittDeleteStaticFindStatement = ''
1020+
let mittDeleteFindStatement = ''
10201021

10211022
const relations = await getRelations(model, modelName)
10221023

@@ -1077,6 +1078,7 @@ export async function generateModelString(
10771078

10781079
if (typeof observer === 'boolean') {
10791080
if (observer) {
1081+
removeInstanceStatment += `const instance = new ${modelName}Model(null)`
10801082
mittCreateStatement += `if (model)\n dispatch('${formattedModelName}:created', model)`
10811083
mittUpdateStatement += `if (model)\n dispatch('${formattedModelName}:updated', model)`
10821084
mittDeleteStatement += `if (model)\n dispatch('${formattedModelName}:deleted', model)`
@@ -1087,6 +1089,7 @@ export async function generateModelString(
10871089
}
10881090

10891091
if (Array.isArray(observer)) {
1092+
removeInstanceStatment += `const instance = new ${modelName}Model(null)`
10901093
// Iterate through the array and append statements based on its contents
10911094
if (observer.includes('create')) {
10921095
mittCreateStatement += `if (model)\n dispatch('${formattedModelName}:created', model);`
@@ -1960,8 +1963,8 @@ export async function generateModelString(
19601963
19611964
// Method to remove a ${modelName}
19621965
static async remove(id: number): Promise<any> {
1963-
const instance = new ${modelName}Model(null)
1964-
1966+
${removeInstanceStatment}
1967+
19651968
${mittDeleteStaticFindStatement}
19661969
19671970
${instanceSoftDeleteStatementsUpdateFrom}
@@ -2168,6 +2171,14 @@ export async function generateModelString(
21682171
return this
21692172
}
21702173
2174+
static with(relations: string[]): ${modelName}Model {
2175+
const instance = new ${modelName}Model(null)
2176+
2177+
instance.withRelations = relations
2178+
2179+
return instance
2180+
}
2181+
21712182
async last(): Promise<${modelName}Type | undefined> {
21722183
return await db.selectFrom('${tableName}')
21732184
.selectAll()

storage/framework/core/payments/src/billable/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Transaction, type TransactionModel } from '../../../../orm/src/models/T
44

55
export interface ManageTransaction {
66
store: (user: UserModel, productId: number) => Promise<TransactionModel>
7-
list: (user: UserModel) => Promise<TransactionModel[]>
7+
list: (user: UserModel) => Promise<TransactionModel[]>
88
}
99

1010
export const manageTransaction: ManageTransaction = (() => {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,6 @@ export class AccessTokenModel {
273273

274274
// Method to remove a AccessToken
275275
static async remove(id: number): Promise<any> {
276-
const instance = new AccessTokenModel(null)
277-
278276
return await db.deleteFrom('personal_access_tokens')
279277
.where('id', '=', id)
280278
.execute()
@@ -502,6 +500,14 @@ export class AccessTokenModel {
502500
return this
503501
}
504502

503+
static with(relations: string[]): AccessTokenModel {
504+
const instance = new AccessTokenModel(null)
505+
506+
instance.withRelations = relations
507+
508+
return instance
509+
}
510+
505511
async last(): Promise<AccessTokenType | undefined> {
506512
return await db.selectFrom('personal_access_tokens')
507513
.selectAll()

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,6 @@ export class DeploymentModel {
317317

318318
// Method to remove a Deployment
319319
static async remove(id: number): Promise<any> {
320-
const instance = new DeploymentModel(null)
321-
322320
return await db.deleteFrom('deployments')
323321
.where('id', '=', id)
324322
.execute()
@@ -576,6 +574,14 @@ export class DeploymentModel {
576574
return this
577575
}
578576

577+
static with(relations: string[]): DeploymentModel {
578+
const instance = new DeploymentModel(null)
579+
580+
instance.withRelations = relations
581+
582+
return instance
583+
}
584+
579585
async last(): Promise<DeploymentType | undefined> {
580586
return await db.selectFrom('deployments')
581587
.selectAll()

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,6 @@ export class ErrorModel {
277277

278278
// Method to remove a Error
279279
static async remove(id: number): Promise<any> {
280-
const instance = new ErrorModel(null)
281-
282280
return await db.deleteFrom('errors')
283281
.where('id', '=', id)
284282
.execute()
@@ -522,6 +520,14 @@ export class ErrorModel {
522520
return this
523521
}
524522

523+
static with(relations: string[]): ErrorModel {
524+
const instance = new ErrorModel(null)
525+
526+
instance.withRelations = relations
527+
528+
return instance
529+
}
530+
525531
async last(): Promise<ErrorType | undefined> {
526532
return await db.selectFrom('errors')
527533
.selectAll()

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,6 @@ export class PaymentMethodModel {
333333

334334
// Method to remove a PaymentMethod
335335
static async remove(id: number): Promise<any> {
336-
const instance = new PaymentMethodModel(null)
337-
338336
return await db.deleteFrom('payment_methods')
339337
.where('id', '=', id)
340338
.execute()
@@ -596,6 +594,14 @@ export class PaymentMethodModel {
596594
return this
597595
}
598596

597+
static with(relations: string[]): PaymentMethodModel {
598+
const instance = new PaymentMethodModel(null)
599+
600+
instance.withRelations = relations
601+
602+
return instance
603+
}
604+
599605
async last(): Promise<PaymentMethodType | undefined> {
600606
return await db.selectFrom('payment_methods')
601607
.selectAll()

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,6 @@ export class PostModel {
292292

293293
// Method to remove a Post
294294
static async remove(id: number): Promise<any> {
295-
const instance = new PostModel(null)
296-
297295
return await db.deleteFrom('posts')
298296
.where('id', '=', id)
299297
.execute()
@@ -511,6 +509,14 @@ export class PostModel {
511509
return this
512510
}
513511

512+
static with(relations: string[]): PostModel {
513+
const instance = new PostModel(null)
514+
515+
instance.withRelations = relations
516+
517+
return instance
518+
}
519+
514520
async last(): Promise<PostType | undefined> {
515521
return await db.selectFrom('posts')
516522
.selectAll()

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,6 @@ export class ProductModel {
290290

291291
// Method to remove a Product
292292
static async remove(id: number): Promise<any> {
293-
const instance = new ProductModel(null)
294-
295293
return await db.deleteFrom('products')
296294
.where('id', '=', id)
297295
.execute()
@@ -543,6 +541,14 @@ export class ProductModel {
543541
return this
544542
}
545543

544+
static with(relations: string[]): ProductModel {
545+
const instance = new ProductModel(null)
546+
547+
instance.withRelations = relations
548+
549+
return instance
550+
}
551+
546552
async last(): Promise<ProductType | undefined> {
547553
return await db.selectFrom('products')
548554
.selectAll()

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,6 @@ export class ProjectModel {
271271

272272
// Method to remove a Project
273273
static async remove(id: number): Promise<any> {
274-
const instance = new ProjectModel(null)
275-
276274
return await db.deleteFrom('projects')
277275
.where('id', '=', id)
278276
.execute()
@@ -500,6 +498,14 @@ export class ProjectModel {
500498
return this
501499
}
502500

501+
static with(relations: string[]): ProjectModel {
502+
const instance = new ProjectModel(null)
503+
504+
instance.withRelations = relations
505+
506+
return instance
507+
}
508+
503509
async last(): Promise<ProjectType | undefined> {
504510
return await db.selectFrom('projects')
505511
.selectAll()

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,6 @@ export class ReleaseModel {
262262

263263
// Method to remove a Release
264264
static async remove(id: number): Promise<any> {
265-
const instance = new ReleaseModel(null)
266-
267265
return await db.deleteFrom('releases')
268266
.where('id', '=', id)
269267
.execute()
@@ -467,6 +465,14 @@ export class ReleaseModel {
467465
return this
468466
}
469467

468+
static with(relations: string[]): ReleaseModel {
469+
const instance = new ReleaseModel(null)
470+
471+
instance.withRelations = relations
472+
473+
return instance
474+
}
475+
470476
async last(): Promise<ReleaseType | undefined> {
471477
return await db.selectFrom('releases')
472478
.selectAll()

0 commit comments

Comments
 (0)