loopbackio / loopback-next

LoopBack makes it easy to build modern API applications that require complex integrations.
https://loopback.io
Other
4.96k stars 1.07k forks source link

When we delete the record, we need to return true(Deleted) or false(Not Deleted) #2819

Closed AnanthGopal closed 5 years ago

AnanthGopal commented 5 years ago

When we delete the record, we need to return true(Deleted) or false(Not Deleted or error occured)

dougal83 commented 5 years ago

You can customise the controller to deliver that behaviour, if you mean the api response?

AnanthGopal commented 5 years ago

@dougal83 just I asked to implement that feature, because that is basic feature so only i am asking. Its okay fine.

dougal83 commented 5 years ago

@AnanthGopal The loopback 4 framework delivers a CRUD implementation via the CLI. You can alter the controller produced or write your own entirely.

You are free to alter the controller like so for the delete function to give the basic customisation that I think you are after:

  @del('/todos/{id}', {
    responses: {
      '200': {
        description: 'Todo DELETE custom boolean response',
        content: {
          'application/json': {
            schema: {
              type: 'boolean',
            },
          },
        },
      },
    },
  })
  async deleteById(@param.path.number('id') id: number): Promise<boolean> {
    return await this.todoRepository
      .deleteById(id)
      .then(() => {
        // promise fullfilled ergo successful deletion
        return true;
      })
      .catch(() => {
        // promise rejected ergo failure to delete
        return false;
      });
  }

Is this more or less the functionality you are looking for?

AnanthGopal commented 5 years ago

Thank you