-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move http decorators to plugin-koa, update usage for core
- Loading branch information
Showing
8 changed files
with
644 additions
and
517 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
40 changes: 40 additions & 0 deletions
40
packages/apps/artusx-koa/src/module-validator/validator.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Controller, StatusCode, GET, Query, Params, Body, POST } from '@artusx/core'; | ||
import type { ArtusxContext } from '@artusx/core'; | ||
|
||
import { | ||
QueryTypes, | ||
QueryScheme, | ||
BodyTypes, | ||
BodyScheme, | ||
ParamsTypes, | ||
ParamsScheme, | ||
} from './validator.validator'; | ||
|
||
@Controller('/validator') | ||
export default class ValidatorController { | ||
@GET('/:uuid') | ||
@POST('/:uuid') | ||
|
||
/** | ||
* validator.index.handler | ||
* @description validate query / params / body | ||
* @example: | ||
* - url: /validator/e8b847b9-cb23-4fbf-8e7c-0c4ba72b9629?foo=foo&bar=bar | ||
* - body: { "key": 123456 } | ||
*/ | ||
@Query<QueryTypes>(QueryScheme) | ||
@Body<BodyTypes>(BodyScheme) | ||
@Params<ParamsTypes>(ParamsScheme) | ||
@StatusCode(200) | ||
async index(ctx: ArtusxContext): Promise<Object> { | ||
const query = ctx.context.output.data.query; | ||
const params = ctx.context.output.data.params; | ||
const body = ctx.context.output.data.body; | ||
|
||
return { | ||
query, | ||
body, | ||
params, | ||
}; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/apps/artusx-koa/src/module-validator/validator.validator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// https://json-schema.org/specification | ||
|
||
import { JSONSchemaType } from '@artusx/core'; | ||
|
||
export interface QueryTypes { | ||
foo: string; | ||
bar?: string; | ||
} | ||
|
||
export const QueryScheme: JSONSchemaType<QueryTypes> = { | ||
type: 'object', | ||
properties: { | ||
foo: { type: 'string' }, | ||
bar: { type: 'string', nullable: true }, | ||
}, | ||
required: ['foo'], | ||
additionalProperties: false, | ||
}; | ||
|
||
export interface ParamsTypes { | ||
uuid: string; | ||
} | ||
|
||
export const ParamsScheme: JSONSchemaType<ParamsTypes> = { | ||
type: 'object', | ||
properties: { | ||
uuid: { type: 'string', nullable: false }, | ||
}, | ||
required: ['uuid'], | ||
additionalProperties: false, | ||
}; | ||
|
||
export interface BodyTypes { | ||
key: number; | ||
} | ||
|
||
export const BodyScheme: JSONSchemaType<BodyTypes> = { | ||
type: 'object', | ||
properties: { | ||
key: { type: 'integer', nullable: false }, | ||
}, | ||
required: ['key'], | ||
additionalProperties: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters