Skip to content

Commit 45dd616

Browse files
chore: wip
1 parent 6fcf927 commit 45dd616

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

storage/framework/actions/src/ActivityIndexOrmAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ export default new Action({
88
async handle() {
99
const results = Activity.all()
1010

11-
return json.response(response)
11+
return response.json(results)
1212
},
1313
})

storage/framework/actions/src/UserIndexOrmAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ export default new Action({
88
async handle() {
99
const results = User.all()
1010

11-
return json.response(response)
11+
return response.json(results)
1212
},
1313
})

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -548,26 +548,27 @@ export async function writeOrmActions(apiRoute: string, modelName: string, actio
548548
const formattedApiRoute = apiRoute.charAt(0).toUpperCase() + apiRoute.slice(1)
549549

550550
let method = 'GET'
551-
let actionString = `import { Action } from '@stacksjs/actions'\n`
552-
actionString += `import { response } from '@stacksjs/router'\n`
551+
let actionString = `import { Action } from '@stacksjs/actions'\n import { response } from '@stacksjs/router'\n\n`
553552
let handleString = ``
554553

555554
if (apiRoute === 'index') {
556555
handleString += `async handle() {
557556
const results = ${modelName}.all()
558557
559-
return json.response(response)
558+
return response.json(results)
560559
},`
561560

562561
method = 'GET'
563562
}
564563

565564
if (apiRoute === 'show') {
566-
actionString += ` import type { ${modelName}RequestType } from '@stacksjs/orm'\n\n`
565+
actionString += ` import type { ${modelName}RequestType } from '@stacksjs/orm'\n import { response } from '@stacksjs/router'\n\n`
567566
handleString += `async handle(request: ${modelName}RequestType) {
568567
const id = request.getParam('id')
569568
570-
return await ${modelName}.findOrFail(Number(id))
569+
const model = await ${modelName}.findOrFail(Number(id))
570+
571+
return response.json(model)
571572
},`
572573

573574
method = 'GET'
@@ -589,26 +590,28 @@ export async function writeOrmActions(apiRoute: string, modelName: string, actio
589590
}
590591

591592
if (apiRoute === 'store') {
592-
actionString += ` import type { ${modelName}RequestType } from '@stacksjs/orm'\n\n`
593+
actionString += ` import type { ${modelName}RequestType } from '@stacksjs/orm'\n import { response } from '@stacksjs/router'\n\n`
593594
handleString += `async handle(request: ${modelName}RequestType) {
594595
await request.validate()
595596
const model = await ${modelName}.create(request.all())
596597
597-
return model
598+
return response.json(model)
598599
},`
599600

600601
method = 'POST'
601602
}
602603

603604
if (apiRoute === 'update') {
604-
actionString += ` import type { ${modelName}RequestType } from '@stacksjs/orm'\n\n`
605+
actionString += ` import type { ${modelName}RequestType } from '@stacksjs/orm'\n import { response } from '@stacksjs/router'\n\n`
605606
handleString += `async handle(request: ${modelName}RequestType) {
606607
await request.validate()
607608
608609
const id = request.getParam('id')
609610
const model = await ${modelName}.findOrFail(Number(id))
610611
611-
return model.update(request.all())
612+
const result = model.update(request.all())
613+
614+
return response.json(result)
612615
},`
613616

614617
method = 'PATCH'

0 commit comments

Comments
 (0)