Skip to content

Commit

Permalink
feat(types): import and use Context for boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed May 26, 2019
1 parent 86170fe commit d183196
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { controller, get, provide } from 'midway';
import { Context, controller, get, provide } from 'midway';

@provide()
@controller('/')
export class HomeController {
@get('/')
async index(ctx) {
async index(ctx: Context) {
await ctx.render('index');
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { provide, controller, get, post, inject } from 'midway';
import { Context, controller, provide, controller, get, post, inject } from 'midway';
import { IUserService } from '../../lib/interface';

@provide()
Expand All @@ -11,7 +11,7 @@ export class UserController {
* GET /user/profile
*/
@get('/profile')
async profile(ctx) {
async profile(ctx: Context) {
const res = await this.service.profile();
ctx.body = res.data;
}
Expand All @@ -20,7 +20,7 @@ export class UserController {
* POST /user/login
*/
@post('/login')
async login(ctx) {
async login(ctx: Context) {
const { username, password } = ctx.query;

if (username === 'admin' && password === 'admin') {
Expand Down Expand Up @@ -48,7 +48,7 @@ export class UserController {
* POST /user/register
*/
@post('/register')
async register(ctx) {
async register(ctx: Context) {
ctx.body = {
status: 200,
statusText: 'ok',
Expand All @@ -60,7 +60,7 @@ export class UserController {
* POST /user/logout
*/
@post('/logout')
async logout(ctx) {
async logout(ctx: Context) {
ctx.body = {
status: 200,
statusText: 'ok',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { controller, get, provide } from 'midway';
import { Context, controller, get, provide } from 'midway';

@provide()
@controller('/')
export class HomeController {

@get('/')
async index(ctx) {
async index(ctx: Context) {
ctx.body = `Welcome to midwayjs!`;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { controller, get, inject, provide } from 'midway';
import { Context, controller, get, inject, provide } from 'midway';
import { IUserService, IUserResult } from '../../interface';

@provide()
Expand All @@ -8,7 +8,7 @@ export class UserController {
service: IUserService;

@get('/:id')
async getUser(ctx): Promise<void> {
async getUser(ctx: Context): Promise<void> {
const id: number = ctx.params.id;
const user: IUserResult = await this.service.getUser({id});
ctx.body = {success: true, message: 'OK', data: user};
Expand Down

0 comments on commit d183196

Please sign in to comment.