Skip to content

Commit 318536d

Browse files
chore: wip
1 parent e790e17 commit 318536d

File tree

19 files changed

+44
-51
lines changed

19 files changed

+44
-51
lines changed

app/Models/User.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Attributes, Model } from '@stacksjs/types'
1+
import type { AttributesKey, Model } from '@stacksjs/types'
22
// soon, these will be auto-imported
33
import { faker } from '@stacksjs/faker'
44
import { schema } from '@stacksjs/validation'
@@ -107,18 +107,13 @@ export default {
107107
},
108108
},
109109
get: {
110-
firstName: (attributes: Attributes) => {
111-
const nameParts = attributes.name.split(' ')
112-
113-
return nameParts[0]
114-
},
115-
salutationName: (attributes: Attributes) => {
110+
salutationName: (attributes: AttributesKey) => {
116111
return `Mr. ${attributes.name}`
117112
},
118113
},
119114

120115
set: {
121-
password: (password: string) => Bun.password.hash(password),
116+
password: (attributes: AttributesKey) => Bun.password.hash(attributes.password),
122117
},
123118
dashboard: {
124119
highlight: true,

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import type {
66
import { camelCase, pascalCase, plural, singular, snakeCase } from '@stacksjs/strings'
77
import { fetchOtherModelRelations, getFillableAttributes, getGuardedAttributes, getHiddenAttributes, getRelationCount, getRelations, getRelationType, mapEntity } from './utils'
88

9+
// const userModel = (await import(path.userModelsPath('User.ts'))).default
10+
11+
// generateCustomAccessors(userModel)
12+
913
function generateCustomAccessors(model: Model): { output: string, loopString: string } {
1014
let output = ''
1115
let loopString = ''
@@ -919,7 +923,7 @@ export async function generateModelString(
919923
})
920924
} else {
921925
const model = data
922-
926+
923927
const customGetter = {
924928
${getterOutput.output}
925929
}
@@ -1956,8 +1960,8 @@ export async function generateModelString(
19561960
.executeTakeFirst()
19571961
19581962
if (existing${modelName}) {
1959-
instance.mapCustomGetters(model)
1960-
await instance.loadRelations(model)
1963+
instance.mapCustomGetters(existing${modelName})
1964+
await instance.loadRelations(existing${modelName})
19611965
19621966
return new ${modelName}Model(existing${modelName} as ${modelName}Type)
19631967
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,8 +1205,8 @@ export class AccessTokenModel {
12051205
.executeTakeFirst()
12061206

12071207
if (existingAccessToken) {
1208-
instance.mapCustomGetters(model)
1209-
await instance.loadRelations(model)
1208+
instance.mapCustomGetters(existingAccessToken)
1209+
await instance.loadRelations(existingAccessToken)
12101210

12111211
return new AccessTokenModel(existingAccessToken as AccessTokenType)
12121212
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,8 +1255,8 @@ export class ActivityModel {
12551255
.executeTakeFirst()
12561256

12571257
if (existingActivity) {
1258-
instance.mapCustomGetters(model)
1259-
await instance.loadRelations(model)
1258+
instance.mapCustomGetters(existingActivity)
1259+
await instance.loadRelations(existingActivity)
12601260

12611261
return new ActivityModel(existingActivity as ActivityType)
12621262
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,8 +1270,8 @@ export class DeploymentModel {
12701270
.executeTakeFirst()
12711271

12721272
if (existingDeployment) {
1273-
instance.mapCustomGetters(model)
1274-
await instance.loadRelations(model)
1273+
instance.mapCustomGetters(existingDeployment)
1274+
await instance.loadRelations(existingDeployment)
12751275

12761276
return new DeploymentModel(existingDeployment as DeploymentType)
12771277
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,8 +1209,8 @@ export class ErrorModel {
12091209
.executeTakeFirst()
12101210

12111211
if (existingError) {
1212-
instance.mapCustomGetters(model)
1213-
await instance.loadRelations(model)
1212+
instance.mapCustomGetters(existingError)
1213+
await instance.loadRelations(existingError)
12141214

12151215
return new ErrorModel(existingError as ErrorType)
12161216
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,8 +1209,8 @@ export class FailedJobModel {
12091209
.executeTakeFirst()
12101210

12111211
if (existingFailedJob) {
1212-
instance.mapCustomGetters(model)
1213-
await instance.loadRelations(model)
1212+
instance.mapCustomGetters(existingFailedJob)
1213+
await instance.loadRelations(existingFailedJob)
12141214

12151215
return new FailedJobModel(existingFailedJob as FailedJobType)
12161216
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,8 +1209,8 @@ export class JobModel {
12091209
.executeTakeFirst()
12101210

12111211
if (existingJob) {
1212-
instance.mapCustomGetters(model)
1213-
await instance.loadRelations(model)
1212+
instance.mapCustomGetters(existingJob)
1213+
await instance.loadRelations(existingJob)
12141214

12151215
return new JobModel(existingJob as JobType)
12161216
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,8 +1277,8 @@ export class PaymentMethodModel {
12771277
.executeTakeFirst()
12781278

12791279
if (existingPaymentMethod) {
1280-
instance.mapCustomGetters(model)
1281-
await instance.loadRelations(model)
1280+
instance.mapCustomGetters(existingPaymentMethod)
1281+
await instance.loadRelations(existingPaymentMethod)
12821282

12831283
return new PaymentMethodModel(existingPaymentMethod as PaymentMethodType)
12841284
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,8 @@ export class PostModel {
11711171
.executeTakeFirst()
11721172

11731173
if (existingPost) {
1174-
instance.mapCustomGetters(model)
1175-
await instance.loadRelations(model)
1174+
instance.mapCustomGetters(existingPost)
1175+
await instance.loadRelations(existingPost)
11761176

11771177
return new PostModel(existingPost as PostType)
11781178
}

0 commit comments

Comments
 (0)