File tree Expand file tree Collapse file tree 14 files changed +98
-70
lines changed Expand file tree Collapse file tree 14 files changed +98
-70
lines changed Original file line number Diff line number Diff line change @@ -2045,13 +2045,14 @@ export async function generateModelString(
2045
2045
}
2046
2046
2047
2047
async update(${ formattedModelName } : ${ modelName } Update): Promise<${ modelName } Model | undefined> {
2048
- if (this.id === undefined)
2049
- throw new HttpError(500, '${ modelName } ID is undefined')
2050
-
2051
2048
const filteredValues = Object.fromEntries(
2052
2049
Object.entries(${ formattedModelName } ).filter(([key]) => this.fillable.includes(key)),
2053
2050
) as New${ modelName }
2054
2051
2052
+ if (this.id === undefined) {
2053
+ this.updateFromQuery.set(filteredValues).execute()
2054
+ }
2055
+
2055
2056
await db.updateTable('${ tableName } ')
2056
2057
.set(filteredValues)
2057
2058
.where('id', '=', this.id)
@@ -2065,8 +2066,9 @@ export async function generateModelString(
2065
2066
}
2066
2067
2067
2068
async forceUpdate(${ formattedModelName } : ${ modelName } Update): Promise<${ modelName } Model | undefined> {
2068
- if (this.id === undefined)
2069
- throw new HttpError(500, '${ modelName } ID is undefined')
2069
+ if (this.id === undefined) {
2070
+ this.updateFromQuery.set(${ formattedModelName } ).execute()
2071
+ }
2070
2072
2071
2073
await db.updateTable('${ tableName } ')
2072
2074
.set(${ formattedModelName } )
Original file line number Diff line number Diff line change @@ -529,13 +529,14 @@ export class AccessTokenModel {
529
529
}
530
530
531
531
async update ( accesstoken : AccessTokenUpdate ) : Promise < AccessTokenModel | undefined > {
532
- if ( this . id === undefined )
533
- throw new HttpError ( 500 , 'AccessToken ID is undefined' )
534
-
535
532
const filteredValues = Object . fromEntries (
536
533
Object . entries ( accesstoken ) . filter ( ( [ key ] ) => this . fillable . includes ( key ) ) ,
537
534
) as NewAccessToken
538
535
536
+ if ( this . id === undefined ) {
537
+ this . updateFromQuery . set ( filteredValues ) . execute ( )
538
+ }
539
+
539
540
await db . updateTable ( 'personal_access_tokens' )
540
541
. set ( filteredValues )
541
542
. where ( 'id' , '=' , this . id )
@@ -547,8 +548,9 @@ export class AccessTokenModel {
547
548
}
548
549
549
550
async forceUpdate ( accesstoken : AccessTokenUpdate ) : Promise < AccessTokenModel | undefined > {
550
- if ( this . id === undefined )
551
- throw new HttpError ( 500 , 'AccessToken ID is undefined' )
551
+ if ( this . id === undefined ) {
552
+ this . updateFromQuery . set ( accesstoken ) . execute ( )
553
+ }
552
554
553
555
await db . updateTable ( 'personal_access_tokens' )
554
556
. set ( accesstoken )
Original file line number Diff line number Diff line change @@ -572,13 +572,14 @@ export class DeploymentModel {
572
572
}
573
573
574
574
async update ( deployment : DeploymentUpdate ) : Promise < DeploymentModel | undefined > {
575
- if ( this . id === undefined )
576
- throw new HttpError ( 500 , 'Deployment ID is undefined' )
577
-
578
575
const filteredValues = Object . fromEntries (
579
576
Object . entries ( deployment ) . filter ( ( [ key ] ) => this . fillable . includes ( key ) ) ,
580
577
) as NewDeployment
581
578
579
+ if ( this . id === undefined ) {
580
+ this . updateFromQuery . set ( filteredValues ) . execute ( )
581
+ }
582
+
582
583
await db . updateTable ( 'deployments' )
583
584
. set ( filteredValues )
584
585
. where ( 'id' , '=' , this . id )
@@ -590,8 +591,9 @@ export class DeploymentModel {
590
591
}
591
592
592
593
async forceUpdate ( deployment : DeploymentUpdate ) : Promise < DeploymentModel | undefined > {
593
- if ( this . id === undefined )
594
- throw new HttpError ( 500 , 'Deployment ID is undefined' )
594
+ if ( this . id === undefined ) {
595
+ this . updateFromQuery . set ( deployment ) . execute ( )
596
+ }
595
597
596
598
await db . updateTable ( 'deployments' )
597
599
. set ( deployment )
Original file line number Diff line number Diff line change @@ -545,13 +545,14 @@ export class ErrorModel {
545
545
}
546
546
547
547
async update ( error : ErrorUpdate ) : Promise < ErrorModel | undefined > {
548
- if ( this . id === undefined )
549
- throw new HttpError ( 500 , 'Error ID is undefined' )
550
-
551
548
const filteredValues = Object . fromEntries (
552
549
Object . entries ( error ) . filter ( ( [ key ] ) => this . fillable . includes ( key ) ) ,
553
550
) as NewError
554
551
552
+ if ( this . id === undefined ) {
553
+ this . updateFromQuery . set ( filteredValues ) . execute ( )
554
+ }
555
+
555
556
await db . updateTable ( 'errors' )
556
557
. set ( filteredValues )
557
558
. where ( 'id' , '=' , this . id )
@@ -563,8 +564,9 @@ export class ErrorModel {
563
564
}
564
565
565
566
async forceUpdate ( error : ErrorUpdate ) : Promise < ErrorModel | undefined > {
566
- if ( this . id === undefined )
567
- throw new HttpError ( 500 , 'Error ID is undefined' )
567
+ if ( this . id === undefined ) {
568
+ this . updateFromQuery . set ( error ) . execute ( )
569
+ }
568
570
569
571
await db . updateTable ( 'errors' )
570
572
. set ( error )
Original file line number Diff line number Diff line change @@ -572,13 +572,14 @@ export class PaymentMethodModel {
572
572
}
573
573
574
574
async update ( paymentmethod : PaymentMethodUpdate ) : Promise < PaymentMethodModel | undefined > {
575
- if ( this . id === undefined )
576
- throw new HttpError ( 500 , 'PaymentMethod ID is undefined' )
577
-
578
575
const filteredValues = Object . fromEntries (
579
576
Object . entries ( paymentmethod ) . filter ( ( [ key ] ) => this . fillable . includes ( key ) ) ,
580
577
) as NewPaymentMethod
581
578
579
+ if ( this . id === undefined ) {
580
+ this . updateFromQuery . set ( filteredValues ) . execute ( )
581
+ }
582
+
582
583
await db . updateTable ( 'payment_methods' )
583
584
. set ( filteredValues )
584
585
. where ( 'id' , '=' , this . id )
@@ -590,8 +591,9 @@ export class PaymentMethodModel {
590
591
}
591
592
592
593
async forceUpdate ( paymentmethod : PaymentMethodUpdate ) : Promise < PaymentMethodModel | undefined > {
593
- if ( this . id === undefined )
594
- throw new HttpError ( 500 , 'PaymentMethod ID is undefined' )
594
+ if ( this . id === undefined ) {
595
+ this . updateFromQuery . set ( paymentmethod ) . execute ( )
596
+ }
595
597
596
598
await db . updateTable ( 'payment_methods' )
597
599
. set ( paymentmethod )
Original file line number Diff line number Diff line change @@ -507,13 +507,14 @@ export class PostModel {
507
507
}
508
508
509
509
async update ( post : PostUpdate ) : Promise < PostModel | undefined > {
510
- if ( this . id === undefined )
511
- throw new HttpError ( 500 , 'Post ID is undefined' )
512
-
513
510
const filteredValues = Object . fromEntries (
514
511
Object . entries ( post ) . filter ( ( [ key ] ) => this . fillable . includes ( key ) ) ,
515
512
) as NewPost
516
513
514
+ if ( this . id === undefined ) {
515
+ this . updateFromQuery . set ( filteredValues ) . execute ( )
516
+ }
517
+
517
518
await db . updateTable ( 'posts' )
518
519
. set ( filteredValues )
519
520
. where ( 'id' , '=' , this . id )
@@ -525,8 +526,9 @@ export class PostModel {
525
526
}
526
527
527
528
async forceUpdate ( post : PostUpdate ) : Promise < PostModel | undefined > {
528
- if ( this . id === undefined )
529
- throw new HttpError ( 500 , 'Post ID is undefined' )
529
+ if ( this . id === undefined ) {
530
+ this . updateFromQuery . set ( post ) . execute ( )
531
+ }
530
532
531
533
await db . updateTable ( 'posts' )
532
534
. set ( post )
Original file line number Diff line number Diff line change @@ -568,13 +568,14 @@ export class ProductModel {
568
568
}
569
569
570
570
async update ( product : ProductUpdate ) : Promise < ProductModel | undefined > {
571
- if ( this . id === undefined )
572
- throw new HttpError ( 500 , 'Product ID is undefined' )
573
-
574
571
const filteredValues = Object . fromEntries (
575
572
Object . entries ( product ) . filter ( ( [ key ] ) => this . fillable . includes ( key ) ) ,
576
573
) as NewProduct
577
574
575
+ if ( this . id === undefined ) {
576
+ this . updateFromQuery . set ( filteredValues ) . execute ( )
577
+ }
578
+
578
579
await db . updateTable ( 'products' )
579
580
. set ( filteredValues )
580
581
. where ( 'id' , '=' , this . id )
@@ -586,8 +587,9 @@ export class ProductModel {
586
587
}
587
588
588
589
async forceUpdate ( product : ProductUpdate ) : Promise < ProductModel | undefined > {
589
- if ( this . id === undefined )
590
- throw new HttpError ( 500 , 'Product ID is undefined' )
590
+ if ( this . id === undefined ) {
591
+ this . updateFromQuery . set ( product ) . execute ( )
592
+ }
591
593
592
594
await db . updateTable ( 'products' )
593
595
. set ( product )
Original file line number Diff line number Diff line change @@ -523,13 +523,14 @@ export class ProjectModel {
523
523
}
524
524
525
525
async update ( project : ProjectUpdate ) : Promise < ProjectModel | undefined > {
526
- if ( this . id === undefined )
527
- throw new HttpError ( 500 , 'Project ID is undefined' )
528
-
529
526
const filteredValues = Object . fromEntries (
530
527
Object . entries ( project ) . filter ( ( [ key ] ) => this . fillable . includes ( key ) ) ,
531
528
) as NewProject
532
529
530
+ if ( this . id === undefined ) {
531
+ this . updateFromQuery . set ( filteredValues ) . execute ( )
532
+ }
533
+
533
534
await db . updateTable ( 'projects' )
534
535
. set ( filteredValues )
535
536
. where ( 'id' , '=' , this . id )
@@ -541,8 +542,9 @@ export class ProjectModel {
541
542
}
542
543
543
544
async forceUpdate ( project : ProjectUpdate ) : Promise < ProjectModel | undefined > {
544
- if ( this . id === undefined )
545
- throw new HttpError ( 500 , 'Project ID is undefined' )
545
+ if ( this . id === undefined ) {
546
+ this . updateFromQuery . set ( project ) . execute ( )
547
+ }
546
548
547
549
await db . updateTable ( 'projects' )
548
550
. set ( project )
Original file line number Diff line number Diff line change @@ -490,13 +490,14 @@ export class ReleaseModel {
490
490
}
491
491
492
492
async update ( release : ReleaseUpdate ) : Promise < ReleaseModel | undefined > {
493
- if ( this . id === undefined )
494
- throw new HttpError ( 500 , 'Release ID is undefined' )
495
-
496
493
const filteredValues = Object . fromEntries (
497
494
Object . entries ( release ) . filter ( ( [ key ] ) => this . fillable . includes ( key ) ) ,
498
495
) as NewRelease
499
496
497
+ if ( this . id === undefined ) {
498
+ this . updateFromQuery . set ( filteredValues ) . execute ( )
499
+ }
500
+
500
501
await db . updateTable ( 'releases' )
501
502
. set ( filteredValues )
502
503
. where ( 'id' , '=' , this . id )
@@ -508,8 +509,9 @@ export class ReleaseModel {
508
509
}
509
510
510
511
async forceUpdate ( release : ReleaseUpdate ) : Promise < ReleaseModel | undefined > {
511
- if ( this . id === undefined )
512
- throw new HttpError ( 500 , 'Release ID is undefined' )
512
+ if ( this . id === undefined ) {
513
+ this . updateFromQuery . set ( release ) . execute ( )
514
+ }
513
515
514
516
await db . updateTable ( 'releases' )
515
517
. set ( release )
Original file line number Diff line number Diff line change @@ -494,13 +494,14 @@ export class SubscriberModel {
494
494
}
495
495
496
496
async update ( subscriber : SubscriberUpdate ) : Promise < SubscriberModel | undefined > {
497
- if ( this . id === undefined )
498
- throw new HttpError ( 500 , 'Subscriber ID is undefined' )
499
-
500
497
const filteredValues = Object . fromEntries (
501
498
Object . entries ( subscriber ) . filter ( ( [ key ] ) => this . fillable . includes ( key ) ) ,
502
499
) as NewSubscriber
503
500
501
+ if ( this . id === undefined ) {
502
+ this . updateFromQuery . set ( filteredValues ) . execute ( )
503
+ }
504
+
504
505
await db . updateTable ( 'subscribers' )
505
506
. set ( filteredValues )
506
507
. where ( 'id' , '=' , this . id )
@@ -512,8 +513,9 @@ export class SubscriberModel {
512
513
}
513
514
514
515
async forceUpdate ( subscriber : SubscriberUpdate ) : Promise < SubscriberModel | undefined > {
515
- if ( this . id === undefined )
516
- throw new HttpError ( 500 , 'Subscriber ID is undefined' )
516
+ if ( this . id === undefined ) {
517
+ this . updateFromQuery . set ( subscriber ) . execute ( )
518
+ }
517
519
518
520
await db . updateTable ( 'subscribers' )
519
521
. set ( subscriber )
You can’t perform that action at this time.
0 commit comments