@@ -621,25 +621,27 @@ export async function generateApiRoutes(modelFiles: string[]) {
621
621
}
622
622
}
623
623
}
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`
633
644
}
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`
643
645
}
644
646
}
645
647
}
@@ -702,9 +704,6 @@ export async function deleteExistingModels(modelStringFile?: string) {
702
704
}
703
705
704
706
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
-
708
707
if ( modelStringFile ) {
709
708
const ormPath = path . builtUserActionsPath ( `src/${ modelStringFile } .ts` )
710
709
if ( fs . existsSync ( ormPath ) ) await fs . promises . unlink ( ormPath )
@@ -742,7 +741,7 @@ export async function deleteExistingModelRequest(modelStringFile?: string) {
742
741
}
743
742
744
743
export async function deleteExistingOrmRoute ( ) {
745
- const ormRoute = path . storagePath ( 'framework/ orm/routes')
744
+ const ormRoute = path . frameworkPath ( ' orm/routes.ts ')
746
745
if ( fs . existsSync ( ormRoute ) ) await fs . promises . unlink ( ormRoute )
747
746
}
748
747
0 commit comments