mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-21 21:31:12 +08:00
Identified some missing definitions for ctx.request.body and ctx.request.params
This commit is contained in:
17
types/koa-joi-router/index.d.ts
vendored
17
types/koa-joi-router/index.d.ts
vendored
@@ -8,7 +8,7 @@ import * as Joi from 'joi';
|
||||
interface Spec {
|
||||
method: string;
|
||||
path: string|RegExp;
|
||||
handler: (ctx: Koa.Context) => void;
|
||||
handler: (ctx: createRouter.Context) => void;
|
||||
validate?: {
|
||||
type: string;
|
||||
body?: Joi.AnySchema;
|
||||
@@ -27,6 +27,17 @@ interface createRouter {
|
||||
Joi: typeof Joi;
|
||||
}
|
||||
|
||||
declare var create: createRouter;
|
||||
declare namespace createRouter {
|
||||
interface Request extends Koa.Request {
|
||||
body: any;
|
||||
params: {[key: string]: string};
|
||||
}
|
||||
|
||||
export = create;
|
||||
interface Context extends Koa.Context {
|
||||
request: Request;
|
||||
}
|
||||
}
|
||||
|
||||
declare var createRouter: createRouter;
|
||||
|
||||
export = createRouter;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import * as router from 'koa-joi-router';
|
||||
import { Context } from 'koa';
|
||||
|
||||
const { Joi } = router;
|
||||
|
||||
const spec1 = {
|
||||
path: '/user',
|
||||
method: 'POST',
|
||||
handler: (ctx: Context) => ctx.body = '',
|
||||
handler: (ctx: router.Context) => ctx.body = '',
|
||||
};
|
||||
|
||||
router().route(spec1);
|
||||
@@ -17,7 +16,7 @@ const spec2 = {
|
||||
validate: {
|
||||
type: 'json',
|
||||
},
|
||||
handler: (ctx: Context) => ctx.status = 201,
|
||||
handler: (ctx: router.Context) => ctx.status = 201,
|
||||
};
|
||||
|
||||
router().route(spec2);
|
||||
@@ -29,7 +28,7 @@ const spec3 = {
|
||||
type: 'json',
|
||||
body: Joi.any(),
|
||||
},
|
||||
handler: (ctx: Context) => ctx.status = 201,
|
||||
handler: (ctx: router.Context) => ctx.status = 201,
|
||||
};
|
||||
|
||||
router().route(spec3);
|
||||
@@ -41,10 +40,32 @@ const spec4 = {
|
||||
type: 'json',
|
||||
201: Joi.object(),
|
||||
},
|
||||
handler: (ctx: Context) => {
|
||||
handler: (ctx: router.Context) => {
|
||||
ctx.status = 201;
|
||||
ctx.body = {};
|
||||
},
|
||||
};
|
||||
|
||||
router().route(spec3);
|
||||
router().route(spec4);
|
||||
|
||||
const spec5 = {
|
||||
method: 'PUT',
|
||||
path: '/user',
|
||||
handler: (ctx: router.Context) => {
|
||||
ctx.status = 201;
|
||||
ctx.body = ctx.request.body;
|
||||
},
|
||||
};
|
||||
|
||||
router().route(spec5);
|
||||
|
||||
const spec6 = {
|
||||
method: 'GET',
|
||||
path: '/user',
|
||||
handler: (ctx: router.Context) => {
|
||||
ctx.status = 201;
|
||||
ctx.body = ctx.request.params;
|
||||
},
|
||||
};
|
||||
|
||||
router().route(spec6);
|
||||
|
||||
Reference in New Issue
Block a user