Skip to content

Commit 2ffe6e3

Browse files
committed
chore: wip
1 parent 60cf4ba commit 2ffe6e3

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,9 @@ async function generateApiRoutes(modelFiles: string[]) {
7878
}
7979

8080
if (apiRoute === 'index') routeString += `route.get('${uri}', '${path}')\n\n`
81-
8281
if (apiRoute === 'show') routeString += `route.get('${uri}/{id}', '${path}')\n\n`
83-
8482
if (apiRoute === 'store') routeString += `route.post('${uri}', '${path}')\n\n`
85-
8683
if (apiRoute === 'update') routeString += `route.patch('${uri}/{id}', '${path}')\n\n`
87-
8884
if (apiRoute === 'destroy') routeString += `route.delete('${uri}/{id}', '${path}')\n\n`
8985
}
9086
}
@@ -100,7 +96,7 @@ async function generateApiRoutes(modelFiles: string[]) {
10096
async function lookupFile(fileName: string): Promise<string | null> {
10197
const ormDirectory = path.builtUserActionsPath('src', { relative: true })
10298
const filePath = path.join(ormDirectory, fileName)
103-
const pathExists = await fs.existsSync(filePath)
99+
const pathExists = fs.existsSync(filePath)
104100

105101
// Check if the directory exists
106102
if (pathExists) {
@@ -109,7 +105,7 @@ async function lookupFile(fileName: string): Promise<string | null> {
109105

110106
const actionDirectory = path.userActionsPath()
111107
const actionFilePath = path.join(actionDirectory, fileName)
112-
const fileExists = await fs.existsSync(actionFilePath)
108+
const fileExists = fs.existsSync(actionFilePath)
113109

114110
if (fileExists) {
115111
return actionFilePath
@@ -188,18 +184,14 @@ async function writeModelRequest() {
188184
if (attribute.fieldArray?.entity === 'number') defaultValue = 0
189185

190186
fieldString += ` ${attribute.field}: ${entity}\n `
191-
192187
fieldStringType += ` get(key: '${attribute.field}'): ${entity}\n`
193-
194188
fieldStringInt += `public ${attribute.field} = ${defaultValue}\n`
195189
keyCounter++
196190
}
197191

198192
for (const otherModel of otherModelRelations) {
199193
fieldString += ` ${otherModel.foreignKey}: number\n `
200-
201194
fieldStringType += ` get(key: '${otherModel.foreignKey}'): string \n`
202-
203195
fieldStringInt += `public ${otherModel.foreignKey} = 0\n`
204196
keyCounterForeign++
205197
}
@@ -288,9 +280,7 @@ async function writeOrmActions(apiRoute: string, modelName: String): Promise<voi
288280
let method = 'GET'
289281
let actionString = `import { Action } from '@stacksjs/actions'\n`
290282
actionString += `import ${modelName} from '../../orm/src/models/${modelName}'\n`
291-
292283
let handleString = ``
293-
294284
actionString += ` import type { ${modelName}RequestType } from '../../types/requests'\n\n`
295285

296286
if (apiRoute === 'index') {
@@ -341,7 +331,6 @@ async function writeOrmActions(apiRoute: string, modelName: String): Promise<voi
341331
await request.validate()
342332
343333
const id = request.getParam('id')
344-
345334
const model = await ${modelName}.findOrFail(Number(id))
346335
347336
return model.update(request.all())
@@ -371,7 +360,6 @@ async function initiateModelGeneration(modelStringFile?: string): Promise<void>
371360
await deleteExistingModelNameTypes()
372361
await deleteExistingModelRequest(modelStringFile)
373362
await deleteExistingOrmRoute()
374-
375363
await writeModelNames()
376364
await writeModelRequest()
377365

0 commit comments

Comments
 (0)