Skip to content

Commit 218c673

Browse files
chore: wip
1 parent 1e180c4 commit 218c673

12 files changed

+31
-18
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,20 +162,23 @@ async function writeOrmActions(apiRoute: string, modelName: String): Promise<voi
162162
const formattedApiRoute = apiRoute.charAt(0).toUpperCase() + apiRoute.slice(1)
163163
let method = 'GET'
164164
let actionString = `import { Action } from '@stacksjs/actions'\n`
165-
actionString += `import ${modelName} from '../src/models/${modelName}'\n\n`
165+
actionString += `import ${modelName} from '../src/models/${modelName}'\n`
166166

167167
let handleString = ``
168168

169+
170+
actionString += ` import type { ${modelName}RequestType } from '../../requests/${modelName}Request'\n\n`
171+
169172
if (apiRoute === 'index') {
170-
handleString += `async handle(request: any) {
173+
handleString += `async handle(request: ${modelName}RequestType) {
171174
return await ${modelName}.all()
172175
},`
173176

174177
method = 'GET'
175178
}
176179

177180
if (apiRoute === 'show') {
178-
handleString += `async handle(request: any) {
181+
handleString += `async handle(request: ${modelName}RequestType) {
179182
const id = await request.getParam('id')
180183
181184
return ${modelName}.findOrFail(Number(id))
@@ -185,7 +188,7 @@ async function writeOrmActions(apiRoute: string, modelName: String): Promise<voi
185188
}
186189

187190
if (apiRoute === 'destroy') {
188-
handleString += `async handle(request: any) {
191+
handleString += `async handle(request: ${modelName}RequestType) {
189192
const id = request.getParam('id')
190193
191194
const model = await ${modelName}.findOrFail(Number(id))
@@ -199,7 +202,7 @@ async function writeOrmActions(apiRoute: string, modelName: String): Promise<voi
199202
}
200203

201204
if (apiRoute === 'store') {
202-
handleString += `async handle(request: any) {
205+
handleString += `async handle(request: ${modelName}RequestType) {
203206
const model = await ${modelName}.create(request.all())
204207
205208
return model
@@ -209,7 +212,7 @@ async function writeOrmActions(apiRoute: string, modelName: String): Promise<voi
209212
}
210213

211214
if (apiRoute === 'update') {
212-
handleString += `async handle(request: any) {
215+
handleString += `async handle(request: ${modelName}RequestType) {
213216
const id = request.getParam('id')
214217
215218
const model = await ${modelName}.findOrFail(Number(id))

storage/framework/core/router/src/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import process from 'node:process'
22
import { log } from '@stacksjs/logging'
33
import { extname, path } from '@stacksjs/path'
44
import { glob } from '@stacksjs/storage'
5-
import type { Route, RouteParam, StatusCode } from '@stacksjs/types'
5+
import type { Model, Route, RouteParam, StatusCode } from '@stacksjs/types'
66
import { route } from '.'
77
import { middlewares } from './middleware'
88
import { request as RequestParam } from './request'
@@ -174,7 +174,7 @@ async function addRouteParam(param: RouteParam): Promise<void> {
174174
const modelFiles = glob.sync(path.userModelsPath('*.ts'));
175175

176176
for (const modelFile of modelFiles) {
177-
const model = (await import(modelFile)).default;
177+
const model = (await import(modelFile)).default as Model;
178178
const modelName = getModelName(model, modelFile);
179179
const modelNameLower = `${lowercase(modelName)}Request`;
180180
const requestPath = path.projectStoragePath(`framework/requests/${modelName}Request.ts`);

storage/framework/orm/Actions/SubscriberDestroyOrmAction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Action } from '@stacksjs/actions'
22
import Subscriber from '../src/models/Subscriber'
3+
import type { SubscriberRequestType } from '../../requests/SubscriberRequest'
34

45
export default new Action({
56
name: 'Subscriber Destroy',
67
description: 'Subscriber Destroy ORM Action',
78
method: 'DELETE',
8-
async handle(request: any) {
9+
async handle(request: SubscriberRequestType) {
910
const id = request.getParam('id')
1011

1112
const model = await Subscriber.findOrFail(Number(id))

storage/framework/orm/Actions/SubscriberIndexOrmAction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Action } from '@stacksjs/actions'
22
import Subscriber from '../src/models/Subscriber'
3+
import type { SubscriberRequestType } from '../../requests/SubscriberRequest'
34

45
export default new Action({
56
name: 'Subscriber Index',
67
description: 'Subscriber Index ORM Action',
78
method: 'GET',
8-
async handle(request: any) {
9+
async handle(request: SubscriberRequestType) {
910
return await Subscriber.all()
1011
},
1112
})

storage/framework/orm/Actions/SubscriberShowOrmAction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Action } from '@stacksjs/actions'
22
import Subscriber from '../src/models/Subscriber'
3+
import type { SubscriberRequestType } from '../../requests/SubscriberRequest'
34

45
export default new Action({
56
name: 'Subscriber Show',
67
description: 'Subscriber Show ORM Action',
78
method: 'GET',
8-
async handle(request: any) {
9+
async handle(request: SubscriberRequestType) {
910
const id = await request.getParam('id')
1011

1112
return Subscriber.findOrFail(Number(id))

storage/framework/orm/Actions/SubscriberStoreOrmAction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Action } from '@stacksjs/actions'
22
import Subscriber from '../src/models/Subscriber'
3+
import type { SubscriberRequestType } from '../../requests/SubscriberRequest'
34

45
export default new Action({
56
name: 'Subscriber Store',
67
description: 'Subscriber Store ORM Action',
78
method: 'POST',
8-
async handle(request: any) {
9+
async handle(request: SubscriberRequestType) {
910
const model = await Subscriber.create(request.all())
1011

1112
return model

storage/framework/orm/Actions/SubscriberUpdateOrmAction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Action } from '@stacksjs/actions'
22
import Subscriber from '../src/models/Subscriber'
3+
import type { SubscriberRequestType } from '../../requests/SubscriberRequest'
34

45
export default new Action({
56
name: 'Subscriber Update',
67
description: 'Subscriber Update ORM Action',
78
method: 'PATCH',
8-
async handle(request: any) {
9+
async handle(request: SubscriberRequestType) {
910
const id = request.getParam('id')
1011

1112
const model = await Subscriber.findOrFail(Number(id))

storage/framework/orm/Actions/UserDestroyOrmAction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Action } from '@stacksjs/actions'
22
import User from '../src/models/User'
3+
import type { UserRequestType } from '../../requests/UserRequest'
34

45
export default new Action({
56
name: 'User Destroy',
67
description: 'User Destroy ORM Action',
78
method: 'DELETE',
8-
async handle(request: any) {
9+
async handle(request: UserRequestType) {
910
const id = request.getParam('id')
1011

1112
const model = await User.findOrFail(Number(id))

storage/framework/orm/Actions/UserIndexOrmAction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Action } from '@stacksjs/actions'
22
import User from '../src/models/User'
3+
import type { UserRequestType } from '../../requests/UserRequest'
34

45
export default new Action({
56
name: 'User Index',
67
description: 'User Index ORM Action',
78
method: 'GET',
8-
async handle(request: any) {
9+
async handle(request: UserRequestType) {
910
return await User.all()
1011
},
1112
})

storage/framework/orm/Actions/UserShowOrmAction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Action } from '@stacksjs/actions'
22
import User from '../src/models/User'
3+
import type { UserRequestType } from '../../requests/UserRequest'
34

45
export default new Action({
56
name: 'User Show',
67
description: 'User Show ORM Action',
78
method: 'GET',
8-
async handle(request: any) {
9+
async handle(request: UserRequestType) {
910
const id = await request.getParam('id')
1011

1112
return User.findOrFail(Number(id))

0 commit comments

Comments
 (0)