Skip to content

Commit b2592d1

Browse files
chore: wip
1 parent 9042a3e commit b2592d1

File tree

5 files changed

+26
-58
lines changed

5 files changed

+26
-58
lines changed

storage/framework/actions/src/index

Lines changed: 0 additions & 11 deletions
This file was deleted.

storage/framework/actions/src/store

Lines changed: 0 additions & 11 deletions
This file was deleted.

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

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -621,25 +621,27 @@ export async function generateApiRoutes(modelFiles: string[]) {
621621
}
622622
}
623623
}
624-
}
625-
626-
if (typeof apiRoutes === 'object') {
627-
for (const apiRoute in apiRoutes) {
628-
if (Object.prototype.hasOwnProperty.call(apiRoutes, apiRoute)) {
629-
const routePath = apiRoutes[apiRoute as keyof typeof apiRoutes]
630-
await writeOrmActions(apiRoute, modelName, routePath)
631-
if (typeof routePath !== 'string') {
632-
throw new Error(`Invalid route path for ${apiRoute}`)
624+
} else {
625+
if (typeof apiRoutes === 'object') {
626+
for (const apiRoute in apiRoutes) {
627+
if (Object.prototype.hasOwnProperty.call(apiRoutes, apiRoute)) {
628+
const routePath = apiRoutes[apiRoute as keyof typeof apiRoutes]
629+
await writeOrmActions(apiRoute, modelName, routePath)
630+
if (typeof routePath !== 'string') {
631+
throw new Error(`Invalid route path for ${apiRoute}`)
632+
}
633+
const pathAction = `${routePath}.ts`
634+
if (apiRoute === 'index')
635+
routeString += `route.get('${uri}', '${pathAction}').${middlewareString}\n\n`
636+
if (apiRoute === 'show')
637+
routeString += `route.get('${uri}/{id}', '${pathAction}').${middlewareString}\n\n`
638+
if (apiRoute === 'store')
639+
routeString += `route.post('${uri}', '${pathAction}').${middlewareString}\n\n`
640+
if (apiRoute === 'update')
641+
routeString += `route.patch('${uri}/{id}', '${pathAction}').${middlewareString}\n\n`
642+
if (apiRoute === 'destroy')
643+
routeString += `route.delete('${uri}/{id}', '${pathAction}').${middlewareString}\n\n`
633644
}
634-
const pathAction = `${routePath}.ts`
635-
if (apiRoute === 'index') routeString += `route.get('${uri}', '${pathAction}').${middlewareString}\n\n`
636-
if (apiRoute === 'show')
637-
routeString += `route.get('${uri}/{id}', '${pathAction}').${middlewareString}\n\n`
638-
if (apiRoute === 'store') routeString += `route.post('${uri}', '${pathAction}').${middlewareString}\n\n`
639-
if (apiRoute === 'update')
640-
routeString += `route.patch('${uri}/{id}', '${pathAction}').${middlewareString}\n\n`
641-
if (apiRoute === 'destroy')
642-
routeString += `route.delete('${uri}/{id}', '${pathAction}').${middlewareString}\n\n`
643645
}
644646
}
645647
}
@@ -702,9 +704,6 @@ export async function deleteExistingModels(modelStringFile?: string) {
702704
}
703705

704706
export async function deleteExistingOrmActions(modelStringFile?: string) {
705-
const routes = path.frameworkPath(`orm/routes.ts`)
706-
if (fs.existsSync(routes)) await fs.promises.unlink(routes)
707-
708707
if (modelStringFile) {
709708
const ormPath = path.builtUserActionsPath(`src/${modelStringFile}.ts`)
710709
if (fs.existsSync(ormPath)) await fs.promises.unlink(ormPath)
@@ -742,7 +741,7 @@ export async function deleteExistingModelRequest(modelStringFile?: string) {
742741
}
743742

744743
export async function deleteExistingOrmRoute() {
745-
const ormRoute = path.storagePath('framework/orm/routes')
744+
const ormRoute = path.frameworkPath('orm/routes.ts')
746745
if (fs.existsSync(ormRoute)) await fs.promises.unlink(ormRoute)
747746
}
748747

storage/framework/orm/routes.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,3 @@ import { route } from '@stacksjs/router'
33
route.get('users', 'storage/framework/actions/src/UserIndexOrmAction.ts').middleware(['Api'])
44

55
route.post('users', 'storage/framework/actions/src/UserStoreOrmAction.ts').middleware(['Api'])
6-
7-
route.patch('users/{id}', 'storage/framework/actions/src/UserUpdateOrmAction.ts').middleware(['Api'])
8-
9-
route.delete('users/{id}', 'storage/framework/actions/src/UserDestroyOrmAction.ts').middleware(['Api'])

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,11 @@ export class PostModel {
282282
static async create(newPost: NewPost): Promise<PostModel | undefined> {
283283
const instance = new this(null)
284284
const filteredValues = Object.keys(newPost)
285-
.filter((key) => {
286-
if (instance.fillable.length) instance.fillable.includes(key)
287-
})
288-
.reduce(
289-
(obj, key) => {
290-
obj[key as keyof NewPost] = newPost[key as keyof NewPost] as any
291-
return obj
292-
},
293-
{} as Partial<NewPost>,
294-
)
285+
.filter((key) => instance.fillable.includes(key))
286+
.reduce((obj: any, key) => {
287+
obj[key] = newPost[key]
288+
return obj
289+
}, {})
295290

296291
if (Object.keys(filteredValues).length === 0) {
297292
return undefined

0 commit comments

Comments
 (0)