Skip to content

Commit

Permalink
feat: add common interface for put and delete (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
orzyyyy authored Oct 29, 2019
1 parent 09ead4e commit 838a6cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions server/controller/ToyController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,18 @@ export default class ToyController {
const { result } = await this.service.getDataBySqlKey(key, ctx.request.body);
return result;
}

@Request({ url: '/put/:key', method: 'put' })
async getDataByPut(ctx: Context) {
const { key } = ctx.params;
const { result } = await this.service.getDataBySqlKey(key, ctx.request.body);
return result;
}

@Request({ url: '/delete/:key', method: 'delete' })
async getDataByDelete(ctx: Context) {
const { key } = ctx.params;
const { result } = await this.service.getDataBySqlKey(key, ctx.request.body);
return result;
}
}
10 changes: 10 additions & 0 deletions server/controller/__tests__/ToyController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@ describe('ToyController', () => {
const result = await (Controller as any).stack[1].stack[0](defaultPostCtx);
expect(result).toBe('result');
});

it('/put/:key', async () => {
const result = await (Controller as any).stack[2].stack[0](defaultPostCtx);
expect(result).toBe('result');
});

it('/delete/:key', async () => {
const result = await (Controller as any).stack[3].stack[0](defaultPostCtx);
expect(result).toBe('result');
});
});

0 comments on commit 838a6cb

Please sign in to comment.