@@ -548,26 +548,27 @@ export async function writeOrmActions(apiRoute: string, modelName: string, actio
548
548
const formattedApiRoute = apiRoute . charAt ( 0 ) . toUpperCase ( ) + apiRoute . slice ( 1 )
549
549
550
550
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`
553
552
let handleString = ``
554
553
555
554
if ( apiRoute === 'index' ) {
556
555
handleString += `async handle() {
557
556
const results = ${ modelName } .all()
558
557
559
- return json. response(response )
558
+ return response.json(results )
560
559
},`
561
560
562
561
method = 'GET'
563
562
}
564
563
565
564
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`
567
566
handleString += `async handle(request: ${ modelName } RequestType) {
568
567
const id = request.getParam('id')
569
568
570
- return await ${ modelName } .findOrFail(Number(id))
569
+ const model = await ${ modelName } .findOrFail(Number(id))
570
+
571
+ return response.json(model)
571
572
},`
572
573
573
574
method = 'GET'
@@ -589,26 +590,28 @@ export async function writeOrmActions(apiRoute: string, modelName: string, actio
589
590
}
590
591
591
592
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`
593
594
handleString += `async handle(request: ${ modelName } RequestType) {
594
595
await request.validate()
595
596
const model = await ${ modelName } .create(request.all())
596
597
597
- return model
598
+ return response.json( model)
598
599
},`
599
600
600
601
method = 'POST'
601
602
}
602
603
603
604
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`
605
606
handleString += `async handle(request: ${ modelName } RequestType) {
606
607
await request.validate()
607
608
608
609
const id = request.getParam('id')
609
610
const model = await ${ modelName } .findOrFail(Number(id))
610
611
611
- return model.update(request.all())
612
+ const result = model.update(request.all())
613
+
614
+ return response.json(result)
612
615
},`
613
616
614
617
method = 'PATCH'
0 commit comments