File tree 7 files changed +59
-29
lines changed
7 files changed +59
-29
lines changed Original file line number Diff line number Diff line change 1
- import type { RequestInstance } from '@stacksjs/types '
1
+ import type { CategorizableRequestType } from '@stacksjs/orm '
2
2
import { Action } from '@stacksjs/actions'
3
3
import { categorizable } from '@stacksjs/cms'
4
4
import { response } from '@stacksjs/router'
@@ -8,9 +8,9 @@ export default new Action({
8
8
name : 'Category Store' ,
9
9
description : 'Category Store ORM Action' ,
10
10
method : 'POST' ,
11
- async handle ( request : RequestInstance ) {
11
+ async handle ( request : CategorizableRequestType ) {
12
12
await request . validate ( {
13
- name : {
13
+ name : {
14
14
rule : schema . string ( ) ,
15
15
message : {
16
16
name : 'Name is required' ,
Original file line number Diff line number Diff line change 1
- import type { CategorizableRequestType } from '@stacksjs/orm '
1
+ import type { CategorizableRequestType } from '@stacksjs/types '
2
2
import { Action } from '@stacksjs/actions'
3
3
import { categorizable } from '@stacksjs/cms'
4
4
import { response } from '@stacksjs/router'
5
+ import { schema } from '@stacksjs/validation'
5
6
6
7
export default new Action ( {
7
8
name : 'Category Update' ,
8
9
description : 'Category Update ORM Action' ,
9
10
method : 'PATCH' ,
10
11
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
+ } )
13
26
const id = request . getParam ( 'id' )
14
27
const data = {
15
28
id,
Original file line number Diff line number Diff line change @@ -2,13 +2,27 @@ import type { CommentablesRequestType } from '@stacksjs/orm'
2
2
import { Action } from '@stacksjs/actions'
3
3
import { comments } from '@stacksjs/cms'
4
4
import { response } from '@stacksjs/router'
5
+ import { schema } from '@stacksjs/validation'
5
6
6
7
export default new Action ( {
7
8
name : 'Comment Store' ,
8
9
description : 'Comment Store ORM Action' ,
9
10
method : 'POST' ,
10
11
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
+ } )
12
26
13
27
const data = {
14
28
title : request . get ( 'title' ) ,
Original file line number Diff line number Diff line change @@ -2,14 +2,27 @@ import type { CommentablesRequestType } from '@stacksjs/orm'
2
2
import { Action } from '@stacksjs/actions'
3
3
import { comments } from '@stacksjs/cms'
4
4
import { response } from '@stacksjs/router'
5
+ import { schema } from '@stacksjs/validation'
5
6
6
7
export default new Action ( {
7
8
name : 'Comment Update' ,
8
9
description : 'Comment Update ORM Action' ,
9
10
method : 'PATCH' ,
10
11
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
+ } )
13
26
const id = request . getParam ( 'id' )
14
27
15
28
const data = {
Original file line number Diff line number Diff line change @@ -9,7 +9,15 @@ export default new Action({
9
9
method : 'PATCH' ,
10
10
async handle ( request : PostRequestType ) {
11
11
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 )
13
21
14
22
return response . json ( model )
15
23
} ,
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ import { formatDate } from '@stacksjs/orm'
9
9
* @param data The post data to update
10
10
* @returns The updated post record
11
11
*/
12
- export async function update ( id : number , data : PostUpdate ) : Promise < PostJsonResponse > {
12
+ export async function update ( id : number , data : Partial < PostUpdate > ) : Promise < PostJsonResponse > {
13
13
try {
14
14
const updateData = {
15
15
...data ,
Original file line number Diff line number Diff line change @@ -17,24 +17,6 @@ import { request as RequestParam } from './request'
17
17
import { traitInterfaces } from '@stacksjs/orm'
18
18
import { camelCase } from '@stacksjs/strings'
19
19
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
-
38
20
export async function serve ( options : ServeOptions = { } ) : Promise < void > {
39
21
const hostname = options . host || 'localhost'
40
22
const port = options . port || 3000
You can’t perform that action at this time.
0 commit comments