Skip to content

Commit f82c01a

Browse files
chore: wip
1 parent ac654f5 commit f82c01a

File tree

7 files changed

+25
-16
lines changed

7 files changed

+25
-16
lines changed

app/Actions/UserStoreAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Action } from '@stacksjs/actions'
2+
import User from '../../storage/framework/orm/src/models/User.ts'
23
import type { UserRequestType } from '../../storage/framework/types/requests'
34

45
export default new Action({
@@ -7,7 +8,6 @@ export default new Action({
78
method: 'POST',
89
requestFile: 'UserRequest',
910
async handle(request: UserRequestType) {
10-
console.log(request)
1111
await request.validate()
1212

1313
const model = await User.create(request.all())

app/Models/User.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default {
5454
name: {
5555
required: true,
5656
order: 3,
57-
57+
fillable: true,
5858
validation: {
5959
rule: schema.string().minLength(3).maxLength(88),
6060
message: {
@@ -70,6 +70,7 @@ export default {
7070
unique: true,
7171
required: true,
7272
order: 1,
73+
fillable: true,
7374
validation: {
7475
rule: schema.string().email(),
7576
message: {
@@ -83,6 +84,7 @@ export default {
8384
jobTitle: {
8485
required: true,
8586
order: 5,
87+
fillable: true,
8688
validation: {
8789
rule: schema.string().minLength(3).maxLength(255),
8890
message: {
@@ -97,6 +99,7 @@ export default {
9799
required: true,
98100
order: 2,
99101
hidden: true,
102+
fillable: true,
100103
validation: {
101104
rule: schema.string().minLength(6).maxLength(255),
102105
message: {

storage/framework/core/actions/src/orm/generate-model.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ async function initiateModelGeneration(modelStringFile?: string): Promise<void>
391391
await deleteExistingOrmActions(modelStringFile)
392392
await deleteExistingModelNameTypes()
393393
await deleteExistingModelRequest(modelStringFile)
394+
await deleteExistingOrmRoute()
394395

395396
await writeModelNames()
396397
await writeModelRequest()
@@ -540,6 +541,12 @@ async function deleteExistingModelRequest(modelStringFile?: string) {
540541
}
541542
}
542543

544+
async function deleteExistingOrmRoute() {
545+
const ormRoute = path.projectStoragePath('framework/orm/routes.ts')
546+
547+
if (fs.existsSync(ormRoute)) await Bun.$`rm ${ormRoute}`
548+
}
549+
543550
async function setKyselyTypes() {
544551
let text = ``
545552
const modelFiles = glob.sync(path.userModelsPath('*.ts'))
@@ -766,11 +773,13 @@ function getHiddenAttributes(attributes: Attributes | undefined): string[] {
766773
function getFillableAttributes(attributes: Attributes | undefined): string[] {
767774
if (attributes === undefined) return []
768775

769-
return Object.keys(attributes).filter((key) => {
770-
if (attributes === undefined) return false
776+
return Object.keys(attributes)
777+
.filter((key) => {
778+
if (attributes === undefined) return false
771779

772-
return attributes[key]?.fillable === true
773-
})
780+
return attributes[key]?.fillable === true
781+
})
782+
.map((attribute) => snakeCase(attribute))
774783
}
775784

776785
async function generateModelString(

storage/framework/core/router/src/server.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ async function addRouteQuery(url: URL) {
306306
for (const modelFile of modelFiles) {
307307
const model = (await import(modelFile)).default
308308
const modelName = getModelName(model, modelFile)
309-
const modelNameLower = `${camelCase(modelName)}Request`
310309
const requestPath = path.projectStoragePath(`framework/requests/${modelName}Request.ts`)
311310
const requestImport = await import(requestPath)
312311
const requestInstance = requestImport.request
@@ -325,7 +324,6 @@ async function addBody(params: any) {
325324
for (const modelFile of modelFiles) {
326325
const model = (await import(modelFile)).default
327326
const modelName = getModelName(model, modelFile)
328-
const modelNameLower = `${camelCase(modelName)}Request`
329327
const requestPath = path.projectStoragePath(`framework/requests/${modelName}Request.ts`)
330328
const requestImport = await import(requestPath)
331329
const requestInstance = requestImport.request
@@ -362,10 +360,9 @@ async function addHeaders(headers: Headers): Promise<void> {
362360
for (const modelFile of modelFiles) {
363361
const model = (await import(modelFile)).default as Model
364362
const modelName = getModelName(model, modelFile)
365-
const modelNameLower = `${lowercase(modelName)}Request`
366363
const requestPath = path.projectStoragePath(`framework/requests/${modelName}Request.ts`)
367364
const requestImport = await import(requestPath)
368-
const requestInstance = requestImport[modelNameLower]
365+
const requestInstance = requestImport.request
369366

370367
if (requestInstance) {
371368
requestInstance.addHeaders(headers)

storage/framework/core/router/src/utils.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ export async function findRequestInstance(requestInstance: string) {
8282

8383
const filePath = path.join(frameworkDirectory, `${requestInstance}.ts`)
8484

85-
8685
const pathExists = await existsSync(filePath)
8786

8887
// Check if the directory exists
@@ -106,8 +105,8 @@ export async function findRequestInstance(requestInstance: string) {
106105
}
107106

108107
export async function extractDefaultRequest(action: string) {
109-
const requestPath = path.projectStoragePath(`framework/core/router/src/request.ts`)
110-
const requestInstance = await import(requestPath)
108+
const requestPath = path.projectStoragePath(`framework/core/router/src/request.ts`)
109+
const requestInstance = await import(requestPath)
111110

112-
return requestInstance.request
111+
return requestInstance.request
113112
}

storage/framework/core/validation/src/validator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { path } from '@stacksjs/path'
2+
import { snakeCase } from '@stacksjs/strings'
23
import type { Model } from '@stacksjs/types'
34
import type { VineType } from '@stacksjs/types'
45
import type { SchemaTypes } from '@vinejs/vine/types'
@@ -31,7 +32,7 @@ export async function validateField(modelFile: string, params: RequestData): Pro
3132

3233
for (const key in attributes) {
3334
if (Object.prototype.hasOwnProperty.call(attributes, key)) {
34-
ruleObject[key] = attributes[key]?.validation?.rule
35+
ruleObject[snakeCase(key)] = attributes[key]?.validation?.rule
3536
const validatorMessages = attributes[key]?.validation?.message
3637

3738
for (const validatorMessageKey in validatorMessages) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ interface QueryOptions {
6767

6868
export class UserModel {
6969
private hidden = ['password']
70-
private fillable = []
70+
private fillable = ['name', 'email', 'job_title', 'password']
7171
protected query: any
7272
protected hasSelect: boolean
7373
public id: number | undefined

0 commit comments

Comments
 (0)