feat(api): add RoutesModule with GET/POST/DELETE /routes endpoints

Implements RoutesService and RoutesController for SyncRoute CRUD, wires
GroupsModule and RoutesModule into AppModule; 11 new tests, all 31 pass.
This commit is contained in:
2026-05-28 01:07:15 +05:30
parent f4a40b573e
commit 6b4920ce41
6 changed files with 221 additions and 0 deletions
@@ -0,0 +1,41 @@
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
import { PrismaService } from '../../prisma/prisma.service';
const routeInclude = {
sourceGroup: { select: { name: true } },
targetGroup: { select: { name: true } },
} as const;
@Injectable()
export class RoutesService {
constructor(private readonly prisma: PrismaService) {}
list(sourceGroupId?: string) {
return this.prisma.syncRoute.findMany({
where: sourceGroupId ? { sourceGroupId } : undefined,
include: routeInclude,
orderBy: { createdAt: 'desc' },
});
}
async create(sourceGroupId: string, targetGroupId: string) {
if (!sourceGroupId || !targetGroupId) {
throw new BadRequestException('sourceGroupId and targetGroupId are required');
}
return this.prisma.syncRoute.create({
data: { sourceGroupId, targetGroupId },
include: routeInclude,
});
}
async remove(id: string) {
try {
await this.prisma.syncRoute.delete({ where: { id } });
} catch (e) {
if ((e as { code?: string })?.code === 'P2025') {
throw new NotFoundException(`Route ${id} not found`);
}
throw e;
}
}
}