How to use the @loopback/rest.patch 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
filter?: Filter,
    ): Promise {
      return this.repository.findById(id, filter);
    }

    @get('/count', {
      ...response(200, `${modelName} count`, {schema: CountSchema}),
    })
    async count(
      @param.query.object('where', getWhereSchemaFor(modelCtor))
      where?: Where,
    ): Promise {
      return this.repository.count(where);
    }

    @patch('/', {
      ...response(200, `Count of ${modelName} models updated`, {
        schema: CountSchema,
      }),
    })
    async updateAll(
      @body(modelCtor, {partial: true}) data: Partial,
      @param.query.object('where', getWhereSchemaFor(modelCtor))
      where?: Where,
    ): Promise {
      return this.repository.updateAll(
        // FIXME(bajtos) Improve repository API to support this use case
        // with no explicit type-casts required
        data as DataObject,
        where,
      );
    }
github strongloop / loopback-next / packages / rest-crud / src / crud-rest.controller.ts View on Github external
}),
    })
    async updateAll(
      @body(modelCtor, {partial: true}) data: Partial,
      @param.query.object('where', getWhereSchemaFor(modelCtor))
      where?: Where,
    ): Promise {
      return this.repository.updateAll(
        // FIXME(bajtos) Improve repository API to support this use case
        // with no explicit type-casts required
        data as DataObject,
        where,
      );
    }

    @patch('/{id}', {
      responses: {
        '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,
      );
    }
github strongloop / loopback-next / examples / express-composition / src / controllers / note.controller.ts View on Github external
content: {
          'application/json': {
            schema: {type: 'array', items: getModelSchemaRef(Note)},
          },
        },
      },
    },
  })
  async find(
    @param.query.object('filter', getFilterSchemaFor(Note))
    filter?: Filter,
  ): Promise {
    return this.noteRepository.find(filter);
  }

  @patch('/notes', {
    responses: {
      '200': {
        description: 'Note PATCH success count',
        content: {'application/json': {schema: CountSchema}},
      },
    },
  })
  async updateAll(
    @requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(Note, {partial: true}),
        },
      },
    })
    note: Partial,
github strongloop / loopback-next / examples / todo-list / src / controllers / todo-list.controller.ts View on Github external
type: 'array',
              items: getModelSchemaRef(TodoList, {includeRelations: true}),
            },
          },
        },
      },
    },
  })
  async find(
    @param.query.object('filter', getFilterSchemaFor(TodoList))
    filter?: Filter,
  ): Promise {
    return this.todoListRepository.find(filter);
  }

  @patch('/todo-lists', {
    responses: {
      '200': {
        description: 'TodoList PATCH success count',
        content: {'application/json': {schema: CountSchema}},
      },
    },
  })
  async updateAll(
    @requestBody({
      content: {
        'application/json': {
          schema: getModelSchemaRef(TodoList, {partial: true}),
        },
      },
    })
    todoList: Partial,
github gobackhuoxing / first-web-game-lb4 / firstgame / src / controllers / update-character.controller.ts View on Github external
levels++;
      char.currentExp! -= char.nextLevelExp!;
      char.nextLevelExp! += 100;
    }
    char.level! += levels;
    char.maxHealth! += 10 * levels;
    char.currentHealth! = char.maxHealth!;
    char.maxMana! += 5 * levels;
    char.currentMana! = char.maxMana!;
    char.attack! += 3 * levels;
    char.defence! += levels;
    await this.characterRepository!.updateById(currentUser.email, char);
    return char;
  }

  @patch('/updatecharacter/initCharacter', {
    responses: {
      '200': {
        description: 'initCharacter',
        content: {},
      },
    },
  })
  @authenticate('jwt', {
    required: [PermissionKey.ViewOwnUser, PermissionKey.UpdateOwnUser],
  })
  async initCharacter(@requestBody() newChar: NewChar): Promise {
    const currentUser = await this.getCurrentUser();
    //equip new weapon
    let char: Character = await this.characterRepository.findById(
      currentUser.email,
    );
github gobackhuoxing / first-web-game-lb4 / firstgame / src / controllers / admin.controller.ts View on Github external
content: {'application/json': {schema: {'x-ts-type': Character}}},
      },
    },
  })
  @authenticate('jwt', {"required":[PermissionKey.ViewAnyUser]})
  async findById(
    @param.path.string('email') email: string
  ): Promise {
    return await this.characterRepository.findById(email);
  }

  /**
   * patch character by email
   * @param where filter
   */
  @patch('/admin/characters/{email}', {
    responses: {
      '204': {
        description: 'Character PATCH success',
      },
    },
  })
  @authenticate('jwt', {"required": [PermissionKey.ViewAnyUser, PermissionKey.UpdateAnyUser]})
  async updateById(
    @param.query.string('email') email: string,
    @requestBody() character: Character,
  ): Promise {
    await this.characterRepository.updateById(email, character);
  }

  /**
   * delete character by email
github sourcefuse / loopback4-starter / src / modules / user-tenants / tenant.controller.ts View on Github external
schema: {type: 'array', items: {'x-ts-type': Tenant}},
          },
        },
      },
    },
  })
  async find(
    @param.query.object('filter', getFilterSchemaFor(Tenant))
    filter?: Filter,
  ): Promise {
    return await this.tenantRepository.find(filter);
  }

  @authenticate(STRATEGY.BEARER)
  @authorize([PermissionKey.UpdateTenant])
  @patch('/tenants', {
    responses: {
      '200': {
        description: 'Tenant PATCH success count',
        content: {'application/json': {schema: CountSchema}},
      },
    },
  })
  async updateAll(
    @requestBody() tenant: Tenant,
    @param.query.object('where', getWhereSchemaFor(Tenant))
    where?: Where,
  ): Promise {
    return await this.tenantRepository.updateAll(tenant, where);
  }

  @authenticate(STRATEGY.BEARER)
github gobackhuoxing / first-web-game-lb4 / firstgame / src / controllers / update-character.controller.ts View on Github external
.weapon(currentUser.email)
      .create(newChar.gear.weapon);
    await this.characterRepository
      .armor(currentUser.email)
      .create(newChar.gear.armor);
    await this.characterRepository
      .skill(currentUser.email)
      .create(newChar.gear.skill);
    return newChar;
  }

  /**
   * update weapon for current character
   * @param weapon weapon
   */
  @patch('/updatecharacter/weapon', {
    responses: {
      '200': {
        description: 'update weapon',
        content: {'application/json': {schema: Weapon}},
      },
    },
  })
  @authenticate('jwt', {
    required: [PermissionKey.ViewOwnUser, PermissionKey.UpdateOwnUser],
  })
  async updateWeapon(@requestBody() weapon: Weapon): Promise {
    const currentUser = await this.getCurrentUser();
    //equip new weapon
    let char: Character = await this.characterRepository.findById(
      currentUser.email,
    );
github gobackhuoxing / first-web-game-lb4 / firstgame / src / controllers / update-character.controller.ts View on Github external
.get();
      char.attack! -= oldArmor.attack;
      char.defence! -= oldArmor.defence;
      await this.characterRepository.armor(currentUser.email).delete();
    }
    await this.characterRepository.updateById(currentUser.email, char);
    return await this.characterRepository
      .armor(currentUser.email)
      .create(armor);
  }

  /**
   * update skill for current character
   * @param skill skill
   */
  @patch('/updatecharacter/skill', {
    responses: {
      '200': {
        description: 'update skill',
        content: {'application/json': {schema: Skill}},
      },
    },
  })
  @authenticate('jwt', {
    required: [PermissionKey.ViewOwnUser, PermissionKey.UpdateOwnUser],
  })
  async updateSkill(@requestBody() skill: Skill): Promise {
    const currentUser = await this.getCurrentUser();
    await this.characterRepository.skill(currentUser.email).delete();
    return await this.characterRepository
      .skill(currentUser.email)
      .create(skill);
github sourcefuse / loopback4-starter / src / modules / user-tenants / user.controller.ts View on Github external
},
  })
  async find(
    @param.query.object('filter', getFilterSchemaFor(User))
    filter?: Filter,
  ): Promise {
    return await this.userRepository.find(filter);
  }

  @authenticate(STRATEGY.BEARER)
  @authorize([
    PermissionKey.UpdateAnyUser,
    PermissionKey.UpdateOwnUser,
    PermissionKey.UpdateTenantUser,
  ])
  @patch('/users', {
    responses: {
      '200': {
        description: 'User PATCH success count',
        content: {'application/json': {schema: CountSchema}},
      },
    },
  })
  async updateAll(
    @requestBody() user: User,
    @param.query.object('where', getWhereSchemaFor(User)) where?: Where,
  ): Promise {
    return await this.userRepository.updateAll(user, where);
  }

  @authenticate(STRATEGY.BEARER)
  @authorize([