How to use the midway.patch function in midway

To help you get started, we’ve selected a few midway examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github midwayjs / midway-examples / demo-sequelize / src / app / controller / post.ts View on Github external
/**
   * POST /post/
   */
  @post('/')
  public async create(ctx) {
    const res = await this.service.create(ctx.request.body);
    // tslint:disable-next-line: no-magic-numbers
    ctx.status = 201;
    ctx.body = res;
  }

  /**
   * PATCH /post/:id
   */
  @patch('/:id')
  public async update(ctx) {
    const id = ctx.params.id;
    const updates = {
      title: ctx.request.body.title,
      content: ctx.request.body.content,
    };
    ctx.body = await this.service.update(id, updates);
  }

  /**
   * DEL /post/:id
   */
  @del('/id')
  public async destroy(ctx) {
    const id = parseInt(ctx.params.id, 10);
    await this.service.destroy(id);

midway

A Node.js Serverless Framework for front-end/full-stack developers. Build the application for next decade.

MIT
Latest version published 3 years ago

Package Health Score

60 / 100
Full package analysis