How to use the @loopback/rest.put function in @loopback/rest

To help you get started, we’ve selected a few @loopback/rest 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 strongloop / loopback-next / packages / rest-crud / src / crud-rest.controller.ts View on Github external
'204': {description: `${modelName} was updated`},
      },
    })
    async updateById(
      @param(idPathParam) id: IdType,
      @body(modelCtor, {partial: true}) data: Partial,
    ): Promise {
      await this.repository.updateById(
        id,
        // FIXME(bajtos) Improve repository API to support this use case
        // with no explicit type-casts required
        data as DataObject,
      );
    }

    @put('/{id}', {
      responses: {
        '204': {description: `${modelName} was updated`},
      },
    })
    async replaceById(
      @param(idPathParam) id: IdType,
      @body(modelCtor) data: T,
    ): Promise {
      await this.repository.replaceById(id, data);
    }

    @del('/{id}', {
      responses: {
        '204': {description: `${modelName} was deleted`},
      },
    })
github strongloop / loopback-next / examples / todo-list / src / controllers / todo.controller.ts View on Github external
type: 'array',
              items: getModelSchemaRef(Todo, {includeRelations: true}),
            },
          },
        },
      },
    },
  })
  async findTodos(
    @param.query.object('filter', getFilterSchemaFor(Todo))
    filter?: Filter,
  ): Promise {
    return this.todoRepo.find(filter);
  }

  @put('/todos/{id}', {
    responses: {
      '204': {
        description: 'Todo PUT success',
      },
    },
  })
  async replaceTodo(
    @param.path.number('id') id: number,
    @requestBody() todo: Todo,
  ): Promise {
    await this.todoRepo.replaceById(id, todo);
  }

  @patch('/todos/{id}', {
    responses: {
      '204': {
github sourcefuse / loopback4-starter / src / modules / audit / audit-log.controller.ts View on Github external
responses: {
      '204': {
        description: 'AuditLog PATCH success',
      },
    },
  })
  async updateById(
    @param.path.number('id') id: number,
    @requestBody() auditLog: AuditLog,
  ): Promise {
    await this.auditLogRepository.updateById(id, auditLog);
  }

  @authenticate(STRATEGY.BEARER)
  @authorize([PermissionKey.UpdateAudit])
  @put('/audit-logs/{id}', {
    responses: {
      '204': {
        description: 'AuditLog PUT success',
      },
    },
  })
  async replaceById(
    @param.path.number('id') id: number,
    @requestBody() auditLog: AuditLog,
  ): Promise {
    await this.auditLogRepository.replaceById(id, auditLog);
  }

  @authenticate(STRATEGY.BEARER)
  @authorize([PermissionKey.DeleteAudit])
  @del('/audit-logs/{id}', {
github strongloop / loopback-next / examples / express-composition / src / controllers / note.controller.ts View on Github external
})
  async updateById(
    @param.path.number('id') id: number,
    @requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(Note, {partial: true}),
        },
      },
    })
    note: Partial,
  ): Promise {
    await this.noteRepository.updateById(id, note);
  }

  @put('/notes/{id}', {
    responses: {
      '204': {
        description: 'Note PUT success',
      },
    },
  })
  async replaceById(
    @param.path.number('id') id: number,
    @requestBody() note: Note,
  ): Promise {
    await this.noteRepository.replaceById(id, note);
  }

  @del('/notes/{id}', {
    responses: {
      '204': {
github sourcefuse / loopback4-starter / src / modules / roles / role.controller.ts View on Github external
responses: {
      '204': {
        description: 'Role PATCH success',
      },
    },
  })
  async updateById(
    @param.path.number('id') id: number,
    @requestBody() role: Role,
  ): Promise {
    await this.roleRepository.updateById(id, role);
  }

  @authenticate(STRATEGY.BEARER)
  @authorize([PermissionKey.UpdateRole])
  @put('/roles/{id}', {
    responses: {
      '204': {
        description: 'Role PUT success',
      },
    },
  })
  async replaceById(
    @param.path.number('id') id: number,
    @requestBody() role: Role,
  ): Promise {
    await this.roleRepository.replaceById(id, role);
  }

  @authenticate(STRATEGY.BEARER)
  @authorize([PermissionKey.DeleteRole])
  @del('/roles/{id}', {
github sourcefuse / loopback4-starter / src / modules / user-tenants / tenant.controller.ts View on Github external
responses: {
      '204': {
        description: 'Tenant PATCH success',
      },
    },
  })
  async updateById(
    @param.path.number('id') id: number,
    @requestBody() tenant: Tenant,
  ): Promise {
    await this.tenantRepository.updateById(id, tenant);
  }

  @authenticate(STRATEGY.BEARER)
  @authorize([PermissionKey.UpdateTenant])
  @put('/tenants/{id}', {
    responses: {
      '204': {
        description: 'Tenant PUT success',
      },
    },
  })
  async replaceById(
    @param.path.number('id') id: number,
    @requestBody() tenant: Tenant,
  ): Promise {
    await this.tenantRepository.replaceById(id, tenant);
  }

  @authenticate(STRATEGY.BEARER)
  @authorize([PermissionKey.DeleteTenant])
  @del('/tenants/{id}', {
github strongloop / loopback-next / examples / todo / src / controllers / todo.controller.ts View on Github external
content: {
          'application/json': {
            schema: {type: 'array', items: getModelSchemaRef(Todo)},
          },
        },
      },
    },
  })
  async findTodos(
    @param.query.object('filter', getFilterSchemaFor(Todo))
    filter?: Filter,
  ): Promise {
    return this.todoRepo.find(filter);
  }

  @put('/todos/{id}', {
    responses: {
      '204': {
        description: 'Todo PUT success',
      },
    },
  })
  async replaceTodo(
    @param.path.number('id') id: number,
    @requestBody() todo: Todo,
  ): Promise {
    await this.todoRepo.replaceById(id, todo);
  }

  @patch('/todos/{id}', {
    responses: {
      '204': {
github strongloop / loopback4-example-shopping / packages / shopping / src / controllers / shopping-cart.controller.ts View on Github external
/**
 * Controller for shopping cart
 */
export class ShoppingCartController {
  constructor(
    @repository(ShoppingCartRepository)
    public shoppingCartRepository: ShoppingCartRepository,
  ) {}

  /**
   * Create or update the shopping cart for a given user
   * @param userId User id
   * @param cart Shopping cart
   */
  @put('/shoppingCarts/{userId}', {
    responses: {
      '204': {
        description: 'User shopping cart is created or updated',
      },
    },
  })
  async set(
    @param.path.string('userId') userId: string,
    @requestBody({description: 'shopping cart'}) cart: ShoppingCart,
  ): Promise {
    debug('Create shopping cart %s: %j', userId, cart);
    if (userId !== cart.userId) {
      throw new HttpErrors.BadRequest(
        `User id does not match: ${userId} !== ${cart.userId}`,
      );
    }
github sourcefuse / loopback4-starter / src / modules / user-tenants / user.controller.ts View on Github external
},
  })
  async updateById(
    @param.path.number('id') id: number,
    @requestBody() user: User,
  ): Promise {
    await this.userRepository.updateById(id, user);
  }

  @authenticate(STRATEGY.BEARER)
  @authorize([
    PermissionKey.UpdateAnyUser,
    PermissionKey.UpdateOwnUser,
    PermissionKey.UpdateTenantUser,
  ])
  @put('/users/{id}', {
    responses: {
      '204': {
        description: 'User PUT success',
      },
    },
  })
  async replaceById(
    @param.path.number('id') id: number,
    @requestBody() user: User,
  ): Promise {
    await this.userRepository.replaceById(id, user);
  }

  @authenticate(STRATEGY.BEARER)
  @authorize([PermissionKey.DeleteAnyUser, PermissionKey.DeleteTenantUser])
  @del('/users/{id}', {