async update()

in services/application/apps/product/src/products/products.service.ts [103:143]


  async update(
    id: string,
    tenantId: string,
    updateProductDto: UpdateProductDto,
  ) {
    try {
      console.log('Updating Product: ', id);
      const client = await this.fetchClient(tenantId);
      const cmd = new UpdateCommand({
        TableName: this.tableName,
        Key: {
          tenant_id: tenantId,
          product_id: id,
        },
        UpdateExpression: 'set #name = :n, #price = :p, #description = :d',
        ExpressionAttributeValues: {
          ':n': updateProductDto.name,
          ':p': updateProductDto.price,
          ':d': updateProductDto.description,
        },
        ExpressionAttributeNames: {
          '#name': 'name',
          '#price': 'price',
          '#description': 'description',
        },
      });

      const response = await client.send(cmd);
      console.log('Update Response:', response);
      return JSON.stringify(updateProductDto);
    } catch (error) {
      console.error(error);
      throw new HttpException(
        {
          status: HttpStatus.INTERNAL_SERVER_ERROR,
          error: error,
        },
        HttpStatus.INTERNAL_SERVER_ERROR,
      );
    }
  }