Skip to content

Commit f186b8e

Browse files
chore: wip
1 parent ea23c98 commit f186b8e

File tree

17 files changed

+121
-19
lines changed

17 files changed

+121
-19
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ export async function generateModelString(
839839
840840
return Object.entries(this.originalAttributes).some(([key, originalValue]) => {
841841
const currentValue = (this.attributes as any)[key]
842-
842+
843843
return currentValue !== originalValue
844844
})
845845
}
@@ -1782,10 +1782,16 @@ export async function generateModelString(
17821782
async save(): Promise<void> {
17831783
if (!this)
17841784
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+
17861792
if (this.id === undefined) {
17871793
await DB.instance.insertInto('${tableName}')
1788-
.values(this as New${modelName})
1794+
.values(filteredValues)
17891795
.executeTakeFirstOrThrow()
17901796
}
17911797
else {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,9 +1101,15 @@ export class AccessTokenModel {
11011101
if (!this)
11021102
throw new HttpError(500, 'AccessToken data is undefined')
11031103

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+
11041110
if (this.id === undefined) {
11051111
await DB.instance.insertInto('personal_access_tokens')
1106-
.values(this as NewAccessToken)
1112+
.values(filteredValues)
11071113
.executeTakeFirstOrThrow()
11081114
}
11091115
else {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,9 +1163,15 @@ export class DeploymentModel {
11631163
if (!this)
11641164
throw new HttpError(500, 'Deployment data is undefined')
11651165

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+
11661172
if (this.id === undefined) {
11671173
await DB.instance.insertInto('deployments')
1168-
.values(this as NewDeployment)
1174+
.values(filteredValues)
11691175
.executeTakeFirstOrThrow()
11701176
}
11711177
else {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,9 +1101,15 @@ export class ErrorModel {
11011101
if (!this)
11021102
throw new HttpError(500, 'Error data is undefined')
11031103

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+
11041110
if (this.id === undefined) {
11051111
await DB.instance.insertInto('errors')
1106-
.values(this as NewError)
1112+
.values(filteredValues)
11071113
.executeTakeFirstOrThrow()
11081114
}
11091115
else {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,9 +1101,15 @@ export class FailedJobModel {
11011101
if (!this)
11021102
throw new HttpError(500, 'FailedJob data is undefined')
11031103

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+
11041110
if (this.id === undefined) {
11051111
await DB.instance.insertInto('failed_jobs')
1106-
.values(this as NewFailedJob)
1112+
.values(filteredValues)
11071113
.executeTakeFirstOrThrow()
11081114
}
11091115
else {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,9 +1101,15 @@ export class JobModel {
11011101
if (!this)
11021102
throw new HttpError(500, 'Job data is undefined')
11031103

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+
11041110
if (this.id === undefined) {
11051111
await DB.instance.insertInto('jobs')
1106-
.values(this as NewJob)
1112+
.values(filteredValues)
11071113
.executeTakeFirstOrThrow()
11081114
}
11091115
else {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,9 +1176,15 @@ export class PaymentMethodModel {
11761176
if (!this)
11771177
throw new HttpError(500, 'PaymentMethod data is undefined')
11781178

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+
11791185
if (this.id === undefined) {
11801186
await DB.instance.insertInto('payment_methods')
1181-
.values(this as NewPaymentMethod)
1187+
.values(filteredValues)
11821188
.executeTakeFirstOrThrow()
11831189
}
11841190
else {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,9 +1067,15 @@ export class PostModel {
10671067
if (!this)
10681068
throw new HttpError(500, 'Post data is undefined')
10691069

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+
10701076
if (this.id === undefined) {
10711077
await DB.instance.insertInto('posts')
1072-
.values(this as NewPost)
1078+
.values(filteredValues)
10731079
.executeTakeFirstOrThrow()
10741080
}
10751081
else {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,9 +1146,15 @@ export class ProductModel {
11461146
if (!this)
11471147
throw new HttpError(500, 'Product data is undefined')
11481148

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+
11491155
if (this.id === undefined) {
11501156
await DB.instance.insertInto('products')
1151-
.values(this as NewProduct)
1157+
.values(filteredValues)
11521158
.executeTakeFirstOrThrow()
11531159
}
11541160
else {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,9 +1084,15 @@ export class ProjectModel {
10841084
if (!this)
10851085
throw new HttpError(500, 'Project data is undefined')
10861086

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+
10871093
if (this.id === undefined) {
10881094
await DB.instance.insertInto('projects')
1089-
.values(this as NewProject)
1095+
.values(filteredValues)
10901096
.executeTakeFirstOrThrow()
10911097
}
10921098
else {

0 commit comments

Comments
 (0)