async findOne()

in services/application/apps/order/src/orders/orders.service.ts [83:115]


  async findOne(id: string, tenantId: string) {
    console.log('Find order:', id, 'TenantId:', tenantId);
    try {
      const client = await this.fetchClient(tenantId);
      const cmd = new QueryCommand({
        TableName: this.tableName,
        KeyConditionExpression: 'tenant_id=:t_id AND order_id=:o_id',
        ExpressionAttributeValues: {
          ':t_id': tenantId,
          ':o_id': id,
        },
      });
      const result = await client.send(cmd);
      const item = result.Items[0];
      if (!item) {
        return;
      }
      const order = {
        ...item,
        products: JSON.parse(item.products),
      };
      return order;
    } catch (error) {
      console.error(error);
      throw new HttpException(
        {
          status: HttpStatus.INTERNAL_SERVER_ERROR,
          error: error,
        },
        HttpStatus.INTERNAL_SERVER_ERROR,
      );
    }
  }