Skip to content

Commit 15220a3

Browse files
chore: wip
1 parent c05d673 commit 15220a3

File tree

14 files changed

+41
-5427
lines changed

14 files changed

+41
-5427
lines changed

app/Models/User.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// soon, these will be auto-imported
22
import { faker } from '@stacksjs/faker'
3-
import { path } from '@stacksjs/path'
43
import { capitalize } from '@stacksjs/strings'
54
import type { Model } from '@stacksjs/types'
65
import { schema } from '@stacksjs/validation'
@@ -35,8 +34,8 @@ export default {
3534
uri: 'users', // your-url.com/api/users
3635
middleware: ['Api'], // defaults to `[]`
3736
routes: {
38-
index: path.projectStoragePath('framework/orm/Actions/UserIndexOrmAction.ts'),
39-
show: path.projectStoragePath('framework/orm/Actions/UserShowOrmAction.ts'),
37+
index: 'ExampleAction.ts',
38+
show: 'HealthAction.ts',
4039
},
4140
},
4241

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,19 @@ async function generateApiRoutes(modelFiles: string[]) {
6161
// console.log(`Route: ${route}, Path: ${apiRoutes[route]}`);
6262
// }
6363

64+
let path: string | null = ''
65+
6466
await writeOrmActions(apiRoute as string, modelName)
6567

66-
const path = `${apiRoutes[apiRoute]}`
68+
path = `${apiRoutes[apiRoute]}`
69+
70+
if (!path.includes('/')) {
71+
path = await lookupFile(path)
72+
}
73+
74+
if (!path) {
75+
throw { message: 'Action Not Found!' }
76+
}
6777

6878
if (apiRoute === 'index') routeString += `await route.get('${uri}', '${path}')\n\n`
6979

@@ -84,6 +94,31 @@ async function generateApiRoutes(modelFiles: string[]) {
8494
await writer.end()
8595
}
8696

97+
async function lookupFile(fileName: string): Promise<string | null> {
98+
const ormDirectory = path.projectStoragePath('framework/orm/Actions')
99+
100+
const filePath = path.join(ormDirectory, fileName)
101+
102+
const pathExists = await fs.existsSync(filePath)
103+
104+
// Check if the directory exists
105+
if (pathExists) {
106+
return filePath
107+
}
108+
109+
const actionDirectory = path.userActionsPath()
110+
111+
const actionFilePath = path.join(actionDirectory, fileName)
112+
113+
const fileExists = await fs.existsSync(actionFilePath)
114+
115+
if (fileExists) {
116+
return actionFilePath
117+
}
118+
119+
return null
120+
}
121+
87122
async function writeModelNames() {
88123
const modelFiles = glob.sync(path.userModelsPath('*.ts'))
89124

storage/framework/orm/Actions/UserShowOrmAction.ts

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

storage/framework/orm/routes.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { route } from '@stacksjs/router'
22

3-
await route.get(
4-
'users',
5-
'/Users/glennmichaeltorregosa/Documents/Projects/stacks/storage/framework/orm/Actions/UserIndexOrmAction.ts',
6-
)
3+
await route.get('users', '/Users/glennmichaeltorregosa/Documents/Projects/stacks/app/Actions/ExampleAction.ts')
74

8-
await route.get(
9-
'users/{id}',
10-
'/Users/glennmichaeltorregosa/Documents/Projects/stacks/storage/framework/orm/Actions/UserShowOrmAction.ts',
11-
)
5+
await route.get('users/{id}', '/Users/glennmichaeltorregosa/Documents/Projects/stacks/app/Actions/HealthAction.ts')

0 commit comments

Comments
 (0)