feat(backend): Durchsichten-Modul (Modul 5)

InspectionsModule mit CRUD, Colony-Historie-Endpunkt und
Folgeaufgaben-Erstellung aus einer Durchsicht heraus.
This commit is contained in:
Nick Szaunig committed 2026-08-21 18:43:08 +02:00
1 parent 49ce23147c
commit 9b59e4bb35
10 files changed
+489 -1

No files matched your search

@@ -0,0 +1,61 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
import { Inspection, Task } from '../../generated/prisma';
import { CreateInspectionDto } from './dto/create-inspection.dto';
import { CreateTaskFromInspectionDto } from './dto/create-task-from-inspection.dto';
@Injectable()
export class InspectionsService {
constructor(private readonly prisma: PrismaService) {}
async findAll(): Promise<Inspection[]> {
return this.prisma.inspection.findMany({ orderBy: { date: 'desc' } });
}
async findById(id: string): Promise<Inspection> {
const inspection = await this.prisma.inspection.findUnique({
where: { id },
});
if (!inspection) {
throw new NotFoundException('Inspection not found');
}
return inspection;
}
async findByColony(colonyId: string): Promise<Inspection[]> {
return this.prisma.inspection.findMany({
where: { colonyId },
orderBy: { date: 'desc' },
});
}
async create(
dto: CreateInspectionDto,
actingUserId: string,
): Promise<Inspection> {
return this.prisma.inspection.create({
data: { ...dto, date: new Date(dto.date), userId: actingUserId },
});
}
async createTaskFromInspection(
id: string,
dto: CreateTaskFromInspectionDto,
actingUserId: string,
): Promise<Task> {
const inspection = await this.findById(id);
return this.prisma.task.create({
data: {
title: dto.title,
description: dto.description,
priority: dto.priority,
dueDate: dto.dueDate ? new Date(dto.dueDate) : undefined,
assignedUserId: dto.assignedUserId,
createdByUserId: actingUserId,
relatedType: 'COLONY',
relatedId: inspection.colonyId,
sourceInspectionId: inspection.id,
},
});
}
}