From bf5d2ff6eab62cb61d9ff0618b4c8bbeff138edb Mon Sep 17 00:00:00 2001 From: Matthew Petro Date: Sat, 2 Mar 2024 17:15:25 -0700 Subject: [PATCH] Added name field to irrigation program --- .../dto/create-irrigation-program.dto.ts | 5 ++++- .../entities/irrigation-program.entity.ts | 1 + .../interfaces/irrigation-program.interface.ts | 1 + .../irrigation-programs.service.spec.ts | 9 +++++++++ src/irrigation-programs/irrigation-programs.service.ts | 1 + 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/irrigation-programs/dto/create-irrigation-program.dto.ts b/src/irrigation-programs/dto/create-irrigation-program.dto.ts index ae96d84..4cbd2a0 100644 --- a/src/irrigation-programs/dto/create-irrigation-program.dto.ts +++ b/src/irrigation-programs/dto/create-irrigation-program.dto.ts @@ -1,6 +1,9 @@ -import { IsBoolean, IsISO8601, IsInt, IsOptional, IsPositive, Matches } from 'class-validator' +import { IsBoolean, IsISO8601, IsInt, IsOptional, IsPositive, Length, Matches } from 'class-validator' export class CreateIrrigationProgramDto { + @Length(1, 255) + name: string + @IsInt() @IsPositive() duration: number diff --git a/src/irrigation-programs/entities/irrigation-program.entity.ts b/src/irrigation-programs/entities/irrigation-program.entity.ts index b12d2a3..bfb54eb 100644 --- a/src/irrigation-programs/entities/irrigation-program.entity.ts +++ b/src/irrigation-programs/entities/irrigation-program.entity.ts @@ -1,5 +1,6 @@ export class IrrigationProgramEntity { constructor( + public readonly name: string, public readonly duration: number, public readonly wateringPeriod: number, public readonly startTime: string, diff --git a/src/irrigation-programs/interfaces/irrigation-program.interface.ts b/src/irrigation-programs/interfaces/irrigation-program.interface.ts index 1425493..faaf631 100644 --- a/src/irrigation-programs/interfaces/irrigation-program.interface.ts +++ b/src/irrigation-programs/interfaces/irrigation-program.interface.ts @@ -1,5 +1,6 @@ export interface IrrigationProgram { id: string + name: string duration: number wateringPeriod: number startTime: string diff --git a/src/irrigation-programs/irrigation-programs.service.spec.ts b/src/irrigation-programs/irrigation-programs.service.spec.ts index 35e1a6d..26d671c 100644 --- a/src/irrigation-programs/irrigation-programs.service.spec.ts +++ b/src/irrigation-programs/irrigation-programs.service.spec.ts @@ -67,6 +67,7 @@ describe('IrrigationProgramsService', () => { it('should create an irrigation program', async () => { mockInsert.mockResolvedValue({ id: uuidv4(), ok: true }) const mockCreateDto: CreateIrrigationProgramDto = { + name: 'Irrigation Program 1', duration: 10, wateringPeriod: 2, startTime: '12:00', @@ -84,6 +85,7 @@ describe('IrrigationProgramsService', () => { it('should not create an irrigation program because the result is not ok', async () => { mockInsert.mockResolvedValue({ ok: false }) const mockCreateDto: CreateIrrigationProgramDto = { + name: 'Irrigation Program 1', duration: 10, wateringPeriod: 2, startTime: '12:00', @@ -101,6 +103,7 @@ describe('IrrigationProgramsService', () => { it('should not create an irrigation program because the database throws an error', async () => { mockInsert.mockRejectedValue({}) const mockCreateDto: CreateIrrigationProgramDto = { + name: 'Irrigation Program 1', duration: 10, wateringPeriod: 2, startTime: '12:00', @@ -119,6 +122,7 @@ describe('IrrigationProgramsService', () => { describe('get all irrigation programs', () => { it('should find all irrigation programs', async () => { const mockIrrigationProgram1 = { + name: 'Irrigation Program 1', duration: 10, wateringPeriod: 2, startTime: '12:00', @@ -126,6 +130,7 @@ describe('IrrigationProgramsService', () => { simultaneousIrrigation: true, } const mockIrrigationProgram2 = { + name: 'Irrigation Program 2', duration: 20, wateringPeriod: 4, startTime: '05:00', @@ -168,6 +173,7 @@ describe('IrrigationProgramsService', () => { it('should find one irrigation program', async () => { const id = uuidv4() const mockPartialIrrigationProgram = { + name: 'Irrigation Program 1', duration: 10, wateringPeriod: 2, startTime: '12:00', @@ -222,6 +228,7 @@ describe('IrrigationProgramsService', () => { const id = uuidv4() const rev = '1-234' const mockIrrigationProgram: IrrigationProgramEntity = { + name: 'Irrigation Program 1', duration: 10, wateringPeriod: 2, startTime: '12:00', @@ -296,6 +303,7 @@ describe('IrrigationProgramsService', () => { const id = uuidv4() const rev = '1-234' const mockIrrigationProgram: IrrigationProgramEntity = { + name: 'Irrigation Program 1', duration: 10, wateringPeriod: 2, startTime: '12:00', @@ -321,6 +329,7 @@ describe('IrrigationProgramsService', () => { const id = uuidv4() const rev = '1-234' const mockIrrigationProgram: IrrigationProgramEntity = { + name: 'Irrigation Program 1', duration: 10, wateringPeriod: 2, startTime: '12:00', diff --git a/src/irrigation-programs/irrigation-programs.service.ts b/src/irrigation-programs/irrigation-programs.service.ts index 2bf2dbe..d6db2aa 100644 --- a/src/irrigation-programs/irrigation-programs.service.ts +++ b/src/irrigation-programs/irrigation-programs.service.ts @@ -13,6 +13,7 @@ type IrrigationProgramEntityWithId = IrrigationProgramEntity & IdentifiedDocumen const irrigationEntityToIrrigationInterface = ( irrigationProgram: IrrigationProgramEntityWithId ): IrrigationProgram => ({ + name: irrigationProgram.name, id: irrigationProgram._id, duration: irrigationProgram.duration, wateringPeriod: irrigationProgram.wateringPeriod,