Skip to content

Commit

Permalink
Restored code for transforming irrigation entity
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewpetro committed Mar 3, 2024
1 parent c2ff93a commit e8c7794
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/irrigation-programs/irrigation-programs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ import { IrrigationProgram } from './interfaces/irrigation-program.interface'
import { ConfigService } from '@nestjs/config'
import EnvironmentVariables from '@/environment-variables'
import { DatabaseService } from '@/database/database.service'
import { DocumentScope, IdentifiedDocument, MaybeDocument } from 'nano'
import { DocumentScope, IdentifiedDocument, MaybeDocument, MaybeRevisionedDocument } from 'nano'

type IrrigationProgramEntityWithId = IrrigationProgramEntity & IdentifiedDocument

const irrigationEntityToIrrigationInterface = (
irrigationProgramEntity: IrrigationProgramEntityWithId
): IrrigationProgram => {
const { _id, ...irrigationProgram } = irrigationProgramEntity
return { id: _id, ...irrigationProgram } as IrrigationProgram
}
): IrrigationProgram => ({
id: irrigationProgramEntity._id,
name: irrigationProgramEntity.name,
duration: irrigationProgramEntity.duration,
wateringPeriod: irrigationProgramEntity.wateringPeriod,
startTime: irrigationProgramEntity.startTime,
switches: irrigationProgramEntity.switches,
simultaneousIrrigation: irrigationProgramEntity.simultaneousIrrigation,
nextRunDate: irrigationProgramEntity.nextRunDate,
})

@Injectable()
export class IrrigationProgramsService implements OnModuleInit {
Expand Down Expand Up @@ -62,7 +68,7 @@ export class IrrigationProgramsService implements OnModuleInit {
if (result._deleted) {
throw new HttpException(`Irrigation program with ID ${id} not found`, HttpStatus.NOT_FOUND)
}
return result as IrrigationProgramEntityWithId
return result as IrrigationProgramEntityWithId & MaybeRevisionedDocument
} catch (error) {
if (error instanceof HttpException) {
throw error
Expand Down

0 comments on commit e8c7794

Please sign in to comment.