File tree Expand file tree Collapse file tree 18 files changed +234
-90
lines changed Expand file tree Collapse file tree 18 files changed +234
-90
lines changed Original file line number Diff line number Diff line change @@ -1596,13 +1596,11 @@ export async function generateModelString(
1596
1596
1597
1597
return await instance.applyPaginate(options)
1598
1598
}
1599
-
1600
- static async create(new${ modelName } : New${ modelName } ): Promise<${ modelName } Model> {
1601
- const instance = new ${ modelName } Model(null)
1602
1599
1600
+ async applyCreate(new${ modelName } : New${ modelName } ): Promise<${ modelName } Model> {
1603
1601
const filteredValues = Object.fromEntries(
1604
1602
Object.entries(new${ modelName } ).filter(([key]) =>
1605
- !instance .guarded.includes(key) && instance .fillable.includes(key)
1603
+ !this .guarded.includes(key) && this .fillable.includes(key)
1606
1604
),
1607
1605
) as New${ modelName }
1608
1606
@@ -1612,13 +1610,23 @@ export async function generateModelString(
1612
1610
.values(filteredValues)
1613
1611
.executeTakeFirst()
1614
1612
1615
- const model = await instance .find(Number(result.numInsertedOrUpdatedRows)) as ${ modelName } Model
1613
+ const model = await this .find(Number(result.numInsertedOrUpdatedRows)) as ${ modelName } Model
1616
1614
1617
1615
if (model)
1618
1616
dispatch('${ formattedModelName } :created', model)
1619
1617
1620
1618
return model
1621
1619
}
1620
+
1621
+ async create(new${ modelName } : New${ modelName } ): Promise<${ modelName } Model> {
1622
+ return await this.create(new${ modelName } )
1623
+ }
1624
+
1625
+ static async create(new${ modelName } : New${ modelName } ): Promise<${ modelName } Model> {
1626
+ const instance = new ${ modelName } Model(null)
1627
+
1628
+ return await instance.create(new${ modelName } )
1629
+ }
1622
1630
1623
1631
static async createMany(new${ modelName } : New${ modelName } []): Promise<void> {
1624
1632
const instance = new ${ modelName } Model(null)
Original file line number Diff line number Diff line change @@ -827,27 +827,35 @@ export class AccessTokenModel {
827
827
return await instance . applyPaginate ( options )
828
828
}
829
829
830
- static async create ( newAccessToken : NewAccessToken ) : Promise < AccessTokenModel > {
831
- const instance = new AccessTokenModel ( null )
832
-
830
+ async applyCreate ( newAccessToken : NewAccessToken ) : Promise < AccessTokenModel > {
833
831
const filteredValues = Object . fromEntries (
834
832
Object . entries ( newAccessToken ) . filter ( ( [ key ] ) =>
835
- ! instance . guarded . includes ( key ) && instance . fillable . includes ( key ) ,
833
+ ! this . guarded . includes ( key ) && this . fillable . includes ( key ) ,
836
834
) ,
837
835
) as NewAccessToken
838
836
839
837
const result = await DB . instance . insertInto ( 'personal_access_tokens' )
840
838
. values ( filteredValues )
841
839
. executeTakeFirst ( )
842
840
843
- const model = await instance . find ( Number ( result . numInsertedOrUpdatedRows ) ) as AccessTokenModel
841
+ const model = await this . find ( Number ( result . numInsertedOrUpdatedRows ) ) as AccessTokenModel
844
842
845
843
if ( model )
846
844
dispatch ( 'accesstoken:created' , model )
847
845
848
846
return model
849
847
}
850
848
849
+ async create ( newAccessToken : NewAccessToken ) : Promise < AccessTokenModel > {
850
+ return await this . create ( newAccessToken )
851
+ }
852
+
853
+ static async create ( newAccessToken : NewAccessToken ) : Promise < AccessTokenModel > {
854
+ const instance = new AccessTokenModel ( null )
855
+
856
+ return await instance . create ( newAccessToken )
857
+ }
858
+
851
859
static async createMany ( newAccessToken : NewAccessToken [ ] ) : Promise < void > {
852
860
const instance = new AccessTokenModel ( null )
853
861
Original file line number Diff line number Diff line change @@ -850,27 +850,35 @@ export class ActivityModel {
850
850
return await instance . applyPaginate ( options )
851
851
}
852
852
853
- static async create ( newActivity : NewActivity ) : Promise < ActivityModel > {
854
- const instance = new ActivityModel ( null )
855
-
853
+ async applyCreate ( newActivity : NewActivity ) : Promise < ActivityModel > {
856
854
const filteredValues = Object . fromEntries (
857
855
Object . entries ( newActivity ) . filter ( ( [ key ] ) =>
858
- ! instance . guarded . includes ( key ) && instance . fillable . includes ( key ) ,
856
+ ! this . guarded . includes ( key ) && this . fillable . includes ( key ) ,
859
857
) ,
860
858
) as NewActivity
861
859
862
860
const result = await DB . instance . insertInto ( 'activities' )
863
861
. values ( filteredValues )
864
862
. executeTakeFirst ( )
865
863
866
- const model = await instance . find ( Number ( result . numInsertedOrUpdatedRows ) ) as ActivityModel
864
+ const model = await this . find ( Number ( result . numInsertedOrUpdatedRows ) ) as ActivityModel
867
865
868
866
if ( model )
869
867
dispatch ( 'activity:created' , model )
870
868
871
869
return model
872
870
}
873
871
872
+ async create ( newActivity : NewActivity ) : Promise < ActivityModel > {
873
+ return await this . create ( newActivity )
874
+ }
875
+
876
+ static async create ( newActivity : NewActivity ) : Promise < ActivityModel > {
877
+ const instance = new ActivityModel ( null )
878
+
879
+ return await instance . create ( newActivity )
880
+ }
881
+
874
882
static async createMany ( newActivity : NewActivity [ ] ) : Promise < void > {
875
883
const instance = new ActivityModel ( null )
876
884
Original file line number Diff line number Diff line change @@ -864,12 +864,10 @@ export class DeploymentModel {
864
864
return await instance . applyPaginate ( options )
865
865
}
866
866
867
- static async create ( newDeployment : NewDeployment ) : Promise < DeploymentModel > {
868
- const instance = new DeploymentModel ( null )
869
-
867
+ async applyCreate ( newDeployment : NewDeployment ) : Promise < DeploymentModel > {
870
868
const filteredValues = Object . fromEntries (
871
869
Object . entries ( newDeployment ) . filter ( ( [ key ] ) =>
872
- ! instance . guarded . includes ( key ) && instance . fillable . includes ( key ) ,
870
+ ! this . guarded . includes ( key ) && this . fillable . includes ( key ) ,
873
871
) ,
874
872
) as NewDeployment
875
873
@@ -879,14 +877,24 @@ export class DeploymentModel {
879
877
. values ( filteredValues )
880
878
. executeTakeFirst ( )
881
879
882
- const model = await instance . find ( Number ( result . numInsertedOrUpdatedRows ) ) as DeploymentModel
880
+ const model = await this . find ( Number ( result . numInsertedOrUpdatedRows ) ) as DeploymentModel
883
881
884
882
if ( model )
885
883
dispatch ( 'deployment:created' , model )
886
884
887
885
return model
888
886
}
889
887
888
+ async create ( newDeployment : NewDeployment ) : Promise < DeploymentModel > {
889
+ return await this . create ( newDeployment )
890
+ }
891
+
892
+ static async create ( newDeployment : NewDeployment ) : Promise < DeploymentModel > {
893
+ const instance = new DeploymentModel ( null )
894
+
895
+ return await instance . create ( newDeployment )
896
+ }
897
+
890
898
static async createMany ( newDeployment : NewDeployment [ ] ) : Promise < void > {
891
899
const instance = new DeploymentModel ( null )
892
900
Original file line number Diff line number Diff line change @@ -823,27 +823,35 @@ export class ErrorModel {
823
823
return await instance . applyPaginate ( options )
824
824
}
825
825
826
- static async create ( newError : NewError ) : Promise < ErrorModel > {
827
- const instance = new ErrorModel ( null )
828
-
826
+ async applyCreate ( newError : NewError ) : Promise < ErrorModel > {
829
827
const filteredValues = Object . fromEntries (
830
828
Object . entries ( newError ) . filter ( ( [ key ] ) =>
831
- ! instance . guarded . includes ( key ) && instance . fillable . includes ( key ) ,
829
+ ! this . guarded . includes ( key ) && this . fillable . includes ( key ) ,
832
830
) ,
833
831
) as NewError
834
832
835
833
const result = await DB . instance . insertInto ( 'errors' )
836
834
. values ( filteredValues )
837
835
. executeTakeFirst ( )
838
836
839
- const model = await instance . find ( Number ( result . numInsertedOrUpdatedRows ) ) as ErrorModel
837
+ const model = await this . find ( Number ( result . numInsertedOrUpdatedRows ) ) as ErrorModel
840
838
841
839
if ( model )
842
840
dispatch ( 'error:created' , model )
843
841
844
842
return model
845
843
}
846
844
845
+ async create ( newError : NewError ) : Promise < ErrorModel > {
846
+ return await this . create ( newError )
847
+ }
848
+
849
+ static async create ( newError : NewError ) : Promise < ErrorModel > {
850
+ const instance = new ErrorModel ( null )
851
+
852
+ return await instance . create ( newError )
853
+ }
854
+
847
855
static async createMany ( newError : NewError [ ] ) : Promise < void > {
848
856
const instance = new ErrorModel ( null )
849
857
Original file line number Diff line number Diff line change @@ -823,27 +823,35 @@ export class FailedJobModel {
823
823
return await instance . applyPaginate ( options )
824
824
}
825
825
826
- static async create ( newFailedJob : NewFailedJob ) : Promise < FailedJobModel > {
827
- const instance = new FailedJobModel ( null )
828
-
826
+ async applyCreate ( newFailedJob : NewFailedJob ) : Promise < FailedJobModel > {
829
827
const filteredValues = Object . fromEntries (
830
828
Object . entries ( newFailedJob ) . filter ( ( [ key ] ) =>
831
- ! instance . guarded . includes ( key ) && instance . fillable . includes ( key ) ,
829
+ ! this . guarded . includes ( key ) && this . fillable . includes ( key ) ,
832
830
) ,
833
831
) as NewFailedJob
834
832
835
833
const result = await DB . instance . insertInto ( 'failed_jobs' )
836
834
. values ( filteredValues )
837
835
. executeTakeFirst ( )
838
836
839
- const model = await instance . find ( Number ( result . numInsertedOrUpdatedRows ) ) as FailedJobModel
837
+ const model = await this . find ( Number ( result . numInsertedOrUpdatedRows ) ) as FailedJobModel
840
838
841
839
if ( model )
842
840
dispatch ( 'failedjob:created' , model )
843
841
844
842
return model
845
843
}
846
844
845
+ async create ( newFailedJob : NewFailedJob ) : Promise < FailedJobModel > {
846
+ return await this . create ( newFailedJob )
847
+ }
848
+
849
+ static async create ( newFailedJob : NewFailedJob ) : Promise < FailedJobModel > {
850
+ const instance = new FailedJobModel ( null )
851
+
852
+ return await instance . create ( newFailedJob )
853
+ }
854
+
847
855
static async createMany ( newFailedJob : NewFailedJob [ ] ) : Promise < void > {
848
856
const instance = new FailedJobModel ( null )
849
857
Original file line number Diff line number Diff line change @@ -823,27 +823,35 @@ export class JobModel {
823
823
return await instance . applyPaginate ( options )
824
824
}
825
825
826
- static async create ( newJob : NewJob ) : Promise < JobModel > {
827
- const instance = new JobModel ( null )
828
-
826
+ async applyCreate ( newJob : NewJob ) : Promise < JobModel > {
829
827
const filteredValues = Object . fromEntries (
830
828
Object . entries ( newJob ) . filter ( ( [ key ] ) =>
831
- ! instance . guarded . includes ( key ) && instance . fillable . includes ( key ) ,
829
+ ! this . guarded . includes ( key ) && this . fillable . includes ( key ) ,
832
830
) ,
833
831
) as NewJob
834
832
835
833
const result = await DB . instance . insertInto ( 'jobs' )
836
834
. values ( filteredValues )
837
835
. executeTakeFirst ( )
838
836
839
- const model = await instance . find ( Number ( result . numInsertedOrUpdatedRows ) ) as JobModel
837
+ const model = await this . find ( Number ( result . numInsertedOrUpdatedRows ) ) as JobModel
840
838
841
839
if ( model )
842
840
dispatch ( 'job:created' , model )
843
841
844
842
return model
845
843
}
846
844
845
+ async create ( newJob : NewJob ) : Promise < JobModel > {
846
+ return await this . create ( newJob )
847
+ }
848
+
849
+ static async create ( newJob : NewJob ) : Promise < JobModel > {
850
+ const instance = new JobModel ( null )
851
+
852
+ return await instance . create ( newJob )
853
+ }
854
+
847
855
static async createMany ( newJob : NewJob [ ] ) : Promise < void > {
848
856
const instance = new JobModel ( null )
849
857
Original file line number Diff line number Diff line change @@ -871,12 +871,10 @@ export class PaymentMethodModel {
871
871
return await instance . applyPaginate ( options )
872
872
}
873
873
874
- static async create ( newPaymentMethod : NewPaymentMethod ) : Promise < PaymentMethodModel > {
875
- const instance = new PaymentMethodModel ( null )
876
-
874
+ async applyCreate ( newPaymentMethod : NewPaymentMethod ) : Promise < PaymentMethodModel > {
877
875
const filteredValues = Object . fromEntries (
878
876
Object . entries ( newPaymentMethod ) . filter ( ( [ key ] ) =>
879
- ! instance . guarded . includes ( key ) && instance . fillable . includes ( key ) ,
877
+ ! this . guarded . includes ( key ) && this . fillable . includes ( key ) ,
880
878
) ,
881
879
) as NewPaymentMethod
882
880
@@ -886,14 +884,24 @@ export class PaymentMethodModel {
886
884
. values ( filteredValues )
887
885
. executeTakeFirst ( )
888
886
889
- const model = await instance . find ( Number ( result . numInsertedOrUpdatedRows ) ) as PaymentMethodModel
887
+ const model = await this . find ( Number ( result . numInsertedOrUpdatedRows ) ) as PaymentMethodModel
890
888
891
889
if ( model )
892
890
dispatch ( 'paymentmethod:created' , model )
893
891
894
892
return model
895
893
}
896
894
895
+ async create ( newPaymentMethod : NewPaymentMethod ) : Promise < PaymentMethodModel > {
896
+ return await this . create ( newPaymentMethod )
897
+ }
898
+
899
+ static async create ( newPaymentMethod : NewPaymentMethod ) : Promise < PaymentMethodModel > {
900
+ const instance = new PaymentMethodModel ( null )
901
+
902
+ return await instance . create ( newPaymentMethod )
903
+ }
904
+
897
905
static async createMany ( newPaymentMethod : NewPaymentMethod [ ] ) : Promise < void > {
898
906
const instance = new PaymentMethodModel ( null )
899
907
Original file line number Diff line number Diff line change @@ -809,27 +809,35 @@ export class PostModel {
809
809
return await instance . applyPaginate ( options )
810
810
}
811
811
812
- static async create ( newPost : NewPost ) : Promise < PostModel > {
813
- const instance = new PostModel ( null )
814
-
812
+ async applyCreate ( newPost : NewPost ) : Promise < PostModel > {
815
813
const filteredValues = Object . fromEntries (
816
814
Object . entries ( newPost ) . filter ( ( [ key ] ) =>
817
- ! instance . guarded . includes ( key ) && instance . fillable . includes ( key ) ,
815
+ ! this . guarded . includes ( key ) && this . fillable . includes ( key ) ,
818
816
) ,
819
817
) as NewPost
820
818
821
819
const result = await DB . instance . insertInto ( 'posts' )
822
820
. values ( filteredValues )
823
821
. executeTakeFirst ( )
824
822
825
- const model = await instance . find ( Number ( result . numInsertedOrUpdatedRows ) ) as PostModel
823
+ const model = await this . find ( Number ( result . numInsertedOrUpdatedRows ) ) as PostModel
826
824
827
825
if ( model )
828
826
dispatch ( 'post:created' , model )
829
827
830
828
return model
831
829
}
832
830
831
+ async create ( newPost : NewPost ) : Promise < PostModel > {
832
+ return await this . create ( newPost )
833
+ }
834
+
835
+ static async create ( newPost : NewPost ) : Promise < PostModel > {
836
+ const instance = new PostModel ( null )
837
+
838
+ return await instance . create ( newPost )
839
+ }
840
+
833
841
static async createMany ( newPost : NewPost [ ] ) : Promise < void > {
834
842
const instance = new PostModel ( null )
835
843
You can’t perform that action at this time.
0 commit comments