Skip to content

Commit 29053f1

Browse files
chore: wip
1 parent b8556ff commit 29053f1

File tree

7 files changed

+59
-29
lines changed

7 files changed

+59
-29
lines changed

app/Actions/Cms/CategorizableStoreAction.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RequestInstance } from '@stacksjs/types'
1+
import type { CategorizableRequestType } from '@stacksjs/orm'
22
import { Action } from '@stacksjs/actions'
33
import { categorizable } from '@stacksjs/cms'
44
import { response } from '@stacksjs/router'
@@ -8,9 +8,9 @@ export default new Action({
88
name: 'Category Store',
99
description: 'Category Store ORM Action',
1010
method: 'POST',
11-
async handle(request: RequestInstance) {
11+
async handle(request: CategorizableRequestType) {
1212
await request.validate({
13-
name: {
13+
name: {
1414
rule: schema.string(),
1515
message: {
1616
name: 'Name is required',

app/Actions/Cms/CategorizableUpdateAction.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1-
import type { CategorizableRequestType } from '@stacksjs/orm'
1+
import type { CategorizableRequestType } from '@stacksjs/types'
22
import { Action } from '@stacksjs/actions'
33
import { categorizable } from '@stacksjs/cms'
44
import { response } from '@stacksjs/router'
5+
import { schema } from '@stacksjs/validation'
56

67
export default new Action({
78
name: 'Category Update',
89
description: 'Category Update ORM Action',
910
method: 'PATCH',
1011
async handle(request: CategorizableRequestType) {
11-
await request.validate()
12-
12+
await request.validate({
13+
name: {
14+
rule: schema.string(),
15+
message: {
16+
name: 'Name is required',
17+
},
18+
},
19+
description: {
20+
rule: schema.string(),
21+
message: {
22+
description: 'Description is required',
23+
},
24+
},
25+
})
1326
const id = request.getParam('id')
1427
const data = {
1528
id,

app/Actions/Cms/CommentStoreAction.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,27 @@ import type { CommentablesRequestType } from '@stacksjs/orm'
22
import { Action } from '@stacksjs/actions'
33
import { comments } from '@stacksjs/cms'
44
import { response } from '@stacksjs/router'
5+
import { schema } from '@stacksjs/validation'
56

67
export default new Action({
78
name: 'Comment Store',
89
description: 'Comment Store ORM Action',
910
method: 'POST',
1011
async handle(request: CommentablesRequestType) {
11-
await request.validate()
12+
await request.validate({
13+
title: {
14+
rule: schema.string(),
15+
message: {
16+
title: 'Title is required',
17+
},
18+
},
19+
body: {
20+
rule: schema.string(),
21+
message: {
22+
body: 'Body is required',
23+
},
24+
},
25+
})
1226

1327
const data = {
1428
title: request.get('title'),

app/Actions/Cms/CommentUpdateAction.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,27 @@ import type { CommentablesRequestType } from '@stacksjs/orm'
22
import { Action } from '@stacksjs/actions'
33
import { comments } from '@stacksjs/cms'
44
import { response } from '@stacksjs/router'
5+
import { schema } from '@stacksjs/validation'
56

67
export default new Action({
78
name: 'Comment Update',
89
description: 'Comment Update ORM Action',
910
method: 'PATCH',
1011
async handle(request: CommentablesRequestType) {
11-
await request.validate()
12-
12+
await request.validate({
13+
title: {
14+
rule: schema.string(),
15+
message: {
16+
title: 'Title is required',
17+
},
18+
},
19+
body: {
20+
rule: schema.string(),
21+
message: {
22+
body: 'Body is required',
23+
},
24+
},
25+
})
1326
const id = request.getParam('id')
1427

1528
const data = {

app/Actions/Cms/PostUpdateAction.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ export default new Action({
99
method: 'PATCH',
1010
async handle(request: PostRequestType) {
1111
const id = request.getParam('id')
12-
const model = await posts.update(id, request)
12+
13+
const data = {
14+
title: request.get('title'),
15+
body: request.get('body'),
16+
status: request.get('status'),
17+
poster: request.get('poster'),
18+
}
19+
20+
const model = await posts.update(id, data)
1321

1422
return response.json(model)
1523
},

storage/framework/core/cms/src/posts/update.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { formatDate } from '@stacksjs/orm'
99
* @param data The post data to update
1010
* @returns The updated post record
1111
*/
12-
export async function update(id: number, data: PostUpdate): Promise<PostJsonResponse> {
12+
export async function update(id: number, data: Partial<PostUpdate>): Promise<PostJsonResponse> {
1313
try {
1414
const updateData = {
1515
...data,

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

-18
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,6 @@ import { request as RequestParam } from './request'
1717
import { traitInterfaces } from '@stacksjs/orm'
1818
import { camelCase } from '@stacksjs/strings'
1919

20-
// const limiter = new RateLimiter({
21-
// windowMs: 15 * 60 * 1000, // 15 minutes
22-
// maxRequests: 100,
23-
// algorithm: 'sliding-window',
24-
// handler: (req: Request, result: RateLimitResult) => {
25-
// return new Response(JSON.stringify({
26-
// error: 'Too many requests',
27-
// retryAfter: Math.ceil(result.remaining / 1000),
28-
// }), {
29-
// status: 429,
30-
// headers: {
31-
// 'Content-Type': 'application/json',
32-
// 'Retry-After': Math.ceil(result.remaining / 1000).toString(),
33-
// },
34-
// })
35-
// },
36-
// })
37-
3820
export async function serve(options: ServeOptions = {}): Promise<void> {
3921
const hostname = options.host || 'localhost'
4022
const port = options.port || 3000

0 commit comments

Comments
 (0)