File tree Expand file tree Collapse file tree 17 files changed +121
-19
lines changed Expand file tree Collapse file tree 17 files changed +121
-19
lines changed Original file line number Diff line number Diff line change @@ -839,7 +839,7 @@ export async function generateModelString(
839
839
840
840
return Object.entries(this.originalAttributes).some(([key, originalValue]) => {
841
841
const currentValue = (this.attributes as any)[key]
842
-
842
+
843
843
return currentValue !== originalValue
844
844
})
845
845
}
@@ -1782,10 +1782,16 @@ export async function generateModelString(
1782
1782
async save(): Promise<void> {
1783
1783
if (!this)
1784
1784
throw new HttpError(500, '${ modelName } data is undefined')
1785
-
1785
+
1786
+ const filteredValues = Object.fromEntries(
1787
+ Object.entries(this).filter(([key]) =>
1788
+ !this.guarded.includes(key) && this.fillable.includes(key)
1789
+ ),
1790
+ ) as New${ modelName }
1791
+
1786
1792
if (this.id === undefined) {
1787
1793
await DB.instance.insertInto('${ tableName } ')
1788
- .values(this as New ${ modelName } )
1794
+ .values(filteredValues )
1789
1795
.executeTakeFirstOrThrow()
1790
1796
}
1791
1797
else {
Original file line number Diff line number Diff line change @@ -1101,9 +1101,15 @@ export class AccessTokenModel {
1101
1101
if ( ! this )
1102
1102
throw new HttpError ( 500 , 'AccessToken data is undefined' )
1103
1103
1104
+ const filteredValues = Object . fromEntries (
1105
+ Object . entries ( this ) . filter ( ( [ key ] ) =>
1106
+ ! this . guarded . includes ( key ) && this . fillable . includes ( key ) ,
1107
+ ) ,
1108
+ ) as NewAccessToken
1109
+
1104
1110
if ( this . id === undefined ) {
1105
1111
await DB . instance . insertInto ( 'personal_access_tokens' )
1106
- . values ( this as NewAccessToken )
1112
+ . values ( filteredValues )
1107
1113
. executeTakeFirstOrThrow ( )
1108
1114
}
1109
1115
else {
Original file line number Diff line number Diff line change @@ -1163,9 +1163,15 @@ export class DeploymentModel {
1163
1163
if ( ! this )
1164
1164
throw new HttpError ( 500 , 'Deployment data is undefined' )
1165
1165
1166
+ const filteredValues = Object . fromEntries (
1167
+ Object . entries ( this ) . filter ( ( [ key ] ) =>
1168
+ ! this . guarded . includes ( key ) && this . fillable . includes ( key ) ,
1169
+ ) ,
1170
+ ) as NewDeployment
1171
+
1166
1172
if ( this . id === undefined ) {
1167
1173
await DB . instance . insertInto ( 'deployments' )
1168
- . values ( this as NewDeployment )
1174
+ . values ( filteredValues )
1169
1175
. executeTakeFirstOrThrow ( )
1170
1176
}
1171
1177
else {
Original file line number Diff line number Diff line change @@ -1101,9 +1101,15 @@ export class ErrorModel {
1101
1101
if ( ! this )
1102
1102
throw new HttpError ( 500 , 'Error data is undefined' )
1103
1103
1104
+ const filteredValues = Object . fromEntries (
1105
+ Object . entries ( this ) . filter ( ( [ key ] ) =>
1106
+ ! this . guarded . includes ( key ) && this . fillable . includes ( key ) ,
1107
+ ) ,
1108
+ ) as NewError
1109
+
1104
1110
if ( this . id === undefined ) {
1105
1111
await DB . instance . insertInto ( 'errors' )
1106
- . values ( this as NewError )
1112
+ . values ( filteredValues )
1107
1113
. executeTakeFirstOrThrow ( )
1108
1114
}
1109
1115
else {
Original file line number Diff line number Diff line change @@ -1101,9 +1101,15 @@ export class FailedJobModel {
1101
1101
if ( ! this )
1102
1102
throw new HttpError ( 500 , 'FailedJob data is undefined' )
1103
1103
1104
+ const filteredValues = Object . fromEntries (
1105
+ Object . entries ( this ) . filter ( ( [ key ] ) =>
1106
+ ! this . guarded . includes ( key ) && this . fillable . includes ( key ) ,
1107
+ ) ,
1108
+ ) as NewFailedJob
1109
+
1104
1110
if ( this . id === undefined ) {
1105
1111
await DB . instance . insertInto ( 'failed_jobs' )
1106
- . values ( this as NewFailedJob )
1112
+ . values ( filteredValues )
1107
1113
. executeTakeFirstOrThrow ( )
1108
1114
}
1109
1115
else {
Original file line number Diff line number Diff line change @@ -1101,9 +1101,15 @@ export class JobModel {
1101
1101
if ( ! this )
1102
1102
throw new HttpError ( 500 , 'Job data is undefined' )
1103
1103
1104
+ const filteredValues = Object . fromEntries (
1105
+ Object . entries ( this ) . filter ( ( [ key ] ) =>
1106
+ ! this . guarded . includes ( key ) && this . fillable . includes ( key ) ,
1107
+ ) ,
1108
+ ) as NewJob
1109
+
1104
1110
if ( this . id === undefined ) {
1105
1111
await DB . instance . insertInto ( 'jobs' )
1106
- . values ( this as NewJob )
1112
+ . values ( filteredValues )
1107
1113
. executeTakeFirstOrThrow ( )
1108
1114
}
1109
1115
else {
Original file line number Diff line number Diff line change @@ -1176,9 +1176,15 @@ export class PaymentMethodModel {
1176
1176
if ( ! this )
1177
1177
throw new HttpError ( 500 , 'PaymentMethod data is undefined' )
1178
1178
1179
+ const filteredValues = Object . fromEntries (
1180
+ Object . entries ( this ) . filter ( ( [ key ] ) =>
1181
+ ! this . guarded . includes ( key ) && this . fillable . includes ( key ) ,
1182
+ ) ,
1183
+ ) as NewPaymentMethod
1184
+
1179
1185
if ( this . id === undefined ) {
1180
1186
await DB . instance . insertInto ( 'payment_methods' )
1181
- . values ( this as NewPaymentMethod )
1187
+ . values ( filteredValues )
1182
1188
. executeTakeFirstOrThrow ( )
1183
1189
}
1184
1190
else {
Original file line number Diff line number Diff line change @@ -1067,9 +1067,15 @@ export class PostModel {
1067
1067
if ( ! this )
1068
1068
throw new HttpError ( 500 , 'Post data is undefined' )
1069
1069
1070
+ const filteredValues = Object . fromEntries (
1071
+ Object . entries ( this ) . filter ( ( [ key ] ) =>
1072
+ ! this . guarded . includes ( key ) && this . fillable . includes ( key ) ,
1073
+ ) ,
1074
+ ) as NewPost
1075
+
1070
1076
if ( this . id === undefined ) {
1071
1077
await DB . instance . insertInto ( 'posts' )
1072
- . values ( this as NewPost )
1078
+ . values ( filteredValues )
1073
1079
. executeTakeFirstOrThrow ( )
1074
1080
}
1075
1081
else {
Original file line number Diff line number Diff line change @@ -1146,9 +1146,15 @@ export class ProductModel {
1146
1146
if ( ! this )
1147
1147
throw new HttpError ( 500 , 'Product data is undefined' )
1148
1148
1149
+ const filteredValues = Object . fromEntries (
1150
+ Object . entries ( this ) . filter ( ( [ key ] ) =>
1151
+ ! this . guarded . includes ( key ) && this . fillable . includes ( key ) ,
1152
+ ) ,
1153
+ ) as NewProduct
1154
+
1149
1155
if ( this . id === undefined ) {
1150
1156
await DB . instance . insertInto ( 'products' )
1151
- . values ( this as NewProduct )
1157
+ . values ( filteredValues )
1152
1158
. executeTakeFirstOrThrow ( )
1153
1159
}
1154
1160
else {
Original file line number Diff line number Diff line change @@ -1084,9 +1084,15 @@ export class ProjectModel {
1084
1084
if ( ! this )
1085
1085
throw new HttpError ( 500 , 'Project data is undefined' )
1086
1086
1087
+ const filteredValues = Object . fromEntries (
1088
+ Object . entries ( this ) . filter ( ( [ key ] ) =>
1089
+ ! this . guarded . includes ( key ) && this . fillable . includes ( key ) ,
1090
+ ) ,
1091
+ ) as NewProject
1092
+
1087
1093
if ( this . id === undefined ) {
1088
1094
await DB . instance . insertInto ( 'projects' )
1089
- . values ( this as NewProject )
1095
+ . values ( filteredValues )
1090
1096
. executeTakeFirstOrThrow ( )
1091
1097
}
1092
1098
else {
You can’t perform that action at this time.
0 commit comments