1.0.6 • Published 5 years ago

koajs-decorators v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

koajs-decorators

Example

async function check(ctx, next) {
  await next()
}

class AuthMiddleware {

  @Middleware()
  public async isAuthenticated(@Next() next) {
    await next();
  }
}

@Controller({prefix: '/users'})
export class TestController extends AuthMiddleware {

  @Middleware()
  public async existToken(@Next() next) {
    await next();
  }

  @Middleware()
  public async existValidToken(@Next() next) {
    await next();
  }

  @Get("/:id")
  public getById(@Params('id') id, @Context() ctx) {

    ctx.body = id;
  }

  @Put("/:id")
  @Middleware(check)
  public put(@Body() user, @Params('id') id, @Response() res) {

    console.log("some think");
  }

  @Post("/")
  public post(@Body() user, @Response() res) {

    console.log("some think");
  }

  @Delete("/:id")
  public del(@Body() user, @Params('id') id, @Response() res) {

    console.log("some think");
  }
}
1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago