message: fix(origin-backend): smart meter reads serialization
diff: @@ -49,10 +49,12 @@ export class DeviceController {
  @Query('withMeterStats') withMeterStats: boolean,
  @Query('loadRelationIds') loadRelationIds: string | boolean = true
  ) {
  - return this.deviceService.getAll(withMeterStats ?? false, {
  + const devices = await this.deviceService.getAll(withMeterStats ?? false, {
  relations: ['organization'],
  loadRelationIds: loadRelationIds === 'true' || loadRelationIds === true
  });
  +
  + return this.serializeDevices(devices);
  }
  @Get('/my-devices')
  @@ -62,9 +64,11 @@ export class DeviceController {
  @Query('withMeterStats') withMeterStats: boolean,
  @UserDecorator() { organizationId }: ILoggedInUser
  ) {
  - return this.deviceService.getAll(withMeterStats ?? false, {
  + const devices = await this.deviceService.getAll(withMeterStats ?? false, {
  where: { organization: { id: organizationId } }
  });
  +
  + return this.serializeDevices(devices);
  }
  @Get('supplyBy')
  @@ -75,11 +79,13 @@ export class DeviceController {
  @Query('facility') facilityName: string,
  @Query('status') status: string
  ) {
  - return this.deviceService.getSupplyBy(
  + const devices = await this.deviceService.getSupplyBy(
  organizationId,
  facilityName,
  Number.parseInt(status, 10)
  );
  +
  + return this.serializeDevices(devices);
  }
  @Get('/:id')
  @@ -101,6 +107,10 @@ export class DeviceController {
  throw new NotFoundException(StorageErrors.NON_EXISTENT);
  }
  + existingEntity.smartMeterReads = this.serializeSmartMeterReads(
  + existingEntity.smartMeterReads
  + );
  +
  return existingEntity;
  }
  @@ -200,7 +210,9 @@ export class DeviceController {
  throw new NotFoundException(StorageErrors.NON_EXISTENT);
  }
  - return this.deviceService.getAllSmartMeterReadings(id);
  + const reads = await this.deviceService.getAllSmartMeterReadings(id);
  +
  + return this.serializeSmartMeterReads(reads);
  }
  @Get('/get-by-external-id/:type/:id')
  @@ -256,4 +268,15 @@ export class DeviceController {
  });
  }
  }
  +
  + private serializeSmartMeterReads(reads: ISmartMeterRead[]) {
  + return reads?.map((r) => ({ ...r, meterReading: r.meterReading.toString() }));
  + }
  +
  + private serializeDevices(devices: IDevice[]) {
  + return devices?.map((device) => ({
  + ...device,
  + smartMeterReads: this.serializeSmartMeterReads(device.smartMeterReads)
  + }));
  + }
  }
  