Skip to content

Commit 5f9ddc8

Browse files
committed
chore: remove planning api endpoint
1 parent 9973c7b commit 5f9ddc8

File tree

3 files changed

+7
-119
lines changed

3 files changed

+7
-119
lines changed

src/container/container.controller.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { RequestWithUser } from '../auth/dto/requestWithUser';
1818
import { toTaskType } from '../interface';
1919
import { ValidateObjectId } from '../shared/pipes/validate-object-id.pipes';
2020
import { ContainerService } from './container.service';
21-
import { ContainerPlanSlotDTO } from './dto/container-plan-slot.dto';
2221
import { ContainerTaskUpdateDTO } from './dto/container-task-update.dto';
2322
import { ContainerDTO } from './dto/container.dto';
2423

@@ -123,25 +122,6 @@ export class ContainerController {
123122
return res.status(HttpStatus.OK).json(plantInstancesCreatedCount);
124123
}
125124

126-
@UseGuards(AuthGuard)
127-
@Post('/:containerId/plan-slot')
128-
async planContainerSlot(
129-
@Req() req: RequestWithUser,
130-
@Res() res: Response,
131-
@Param('gardenId', new ValidateObjectId()) gardenId: string,
132-
@Param('containerId', new ValidateObjectId()) containerId: string,
133-
@Body() dto: ContainerPlanSlotDTO
134-
) {
135-
const updatedPlantInstance = await this.containerService.planContainerSlot(
136-
containerId,
137-
req.user.userId,
138-
gardenId,
139-
dto
140-
);
141-
142-
return res.status(HttpStatus.OK).json(updatedPlantInstance);
143-
}
144-
145125
// Update tasks in a container
146126
@UseGuards(AuthGuard)
147127
@Post('/:containerId/:taskType')

src/container/container.service.ts

Lines changed: 7 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import { BadRequestException, forwardRef, Inject, Injectable, Logger, NotFoundException } from '@nestjs/common';
1+
import { forwardRef, Inject, Injectable, Logger, NotFoundException } from '@nestjs/common';
22
import { InjectModel } from '@nestjs/mongoose';
33
import { Model, PipelineStage, Types } from 'mongoose';
44
import { GardenService } from '../garden/garden.service';
5-
import { GrowingZoneData, PLANTED, STARTED_FROM_TYPE_SEED, TaskType } from '../interface';
5+
import { GrowingZoneData, STARTED_FROM_TYPE_SEED, TaskType } from '../interface';
66
import { PlantInstanceService } from '../plant-instance/plant-instance.service';
7-
import { PlantInstanceDTO } from '../plant-instance/dto/plant-instance.dto';
87
import { TaskProjection } from '../task/interfaces/task.projection';
98
import { TaskService } from '../task/services/task.service';
109
import { UserService } from '../users/user.service';
1110
import { fromTaskTypeToHistoryStatus } from '../util/history.util';
1211
import { isNotNullish } from '../util/null.util';
1312
import computeSeason from '../util/season.util';
14-
import { ContainerPlanSlotDTO } from './dto/container-plan-slot.dto';
1513
import { ContainerSlotDTO } from './dto/container-slot.dto';
1614
import { ContainerDTO, sanitizeContainerDTO } from './dto/container.dto';
1715
import { Slot } from './interfaces/container-slot.interface';
@@ -288,7 +286,11 @@ export class ContainerService {
288286
plantId: string | undefined,
289287
growingZoneData: GrowingZoneData
290288
) {
291-
const plantInstance = await this.plantInstanceService.getPlantInstance(slot.plantInstanceId, userId, gardenId);
289+
const plantInstance = await this.plantInstanceService.getPlantInstance(
290+
slot != null ? slot.plantInstanceId : null,
291+
userId,
292+
gardenId
293+
);
292294
if (plantInstance && (!plantId || plantInstance.plant === plantId)) {
293295
this.plantInstanceService.createUpdateTasks(userId, gardenId, container, plantInstance, path, growingZoneData);
294296
}
@@ -371,94 +373,4 @@ export class ContainerService {
371373

372374
return plantInstancesCreatedCount;
373375
}
374-
375-
async planContainerSlot(containerId: string, userId: string, gardenId: string, dto: ContainerPlanSlotDTO) {
376-
const slotId = Number(dto.slotId);
377-
if (!Number.isInteger(slotId) || slotId < 0) {
378-
throw new BadRequestException('Invalid slotId');
379-
}
380-
381-
const plantId = `${dto.plantId ?? ''}`.trim();
382-
if (!plantId) {
383-
throw new BadRequestException('Invalid plantId');
384-
}
385-
386-
const container = await this.getContainer(containerId, userId, gardenId);
387-
if (!container) {
388-
throw new NotFoundException('Container does not exist!');
389-
}
390-
391-
const maxSlots = (container.rows ?? 0) * (container.columns ?? 0);
392-
if (slotId >= maxSlots) {
393-
throw new BadRequestException('slotId is out of range');
394-
}
395-
396-
const slot = container.slots?.[`${slotId}`];
397-
398-
if (!slot?.plantInstanceId) {
399-
return this.plantInstanceService.addPlantInstance(
400-
{
401-
containerId,
402-
slotId,
403-
plant: plantId,
404-
created: new Date().toISOString(),
405-
startedFrom: container.startedFrom ?? STARTED_FROM_TYPE_SEED,
406-
season: computeSeason()
407-
},
408-
userId,
409-
gardenId
410-
);
411-
}
412-
413-
const plantInstance = await this.plantInstanceService.getPlantInstance(slot.plantInstanceId, userId, gardenId);
414-
if (!plantInstance || !plantInstance._id) {
415-
throw new NotFoundException('Plant instance does not exist!');
416-
}
417-
418-
const hasPlantedEvent = (plantInstance.history ?? []).some((history) => history.status === PLANTED);
419-
const isPlanning = !plantInstance.closed && !hasPlantedEvent;
420-
421-
if (plantInstance.closed) {
422-
return this.plantInstanceService.addPlantInstance(
423-
{
424-
containerId,
425-
slotId,
426-
plant: plantId,
427-
created: new Date().toISOString(),
428-
startedFrom: container.startedFrom ?? STARTED_FROM_TYPE_SEED,
429-
season: computeSeason()
430-
},
431-
userId,
432-
gardenId
433-
);
434-
}
435-
436-
if (!isPlanning) {
437-
throw new BadRequestException('Only closed or planning slots can be updated');
438-
}
439-
440-
const updateDto: PlantInstanceDTO = {
441-
containerId,
442-
slotId,
443-
plant: plantId,
444-
created: new Date(plantInstance.created).toISOString(),
445-
comments: plantInstance.comments?.map((comment) => ({
446-
...comment,
447-
date: new Date(comment.date).toISOString()
448-
})),
449-
pictures: plantInstance.pictures?.map((picture) => ({
450-
...picture,
451-
date: new Date(picture.date).toISOString()
452-
})),
453-
history: plantInstance.history?.map((history) => ({
454-
...history,
455-
date: new Date(history.date).toISOString()
456-
})),
457-
closed: plantInstance.closed,
458-
startedFrom: plantInstance.startedFrom,
459-
season: plantInstance.season
460-
};
461-
462-
return this.plantInstanceService.editPlantInstance(plantInstance._id, userId, gardenId, updateDto);
463-
}
464376
}

src/container/dto/container-plan-slot.dto.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)