feat(center-nodes): enforce nodeId and endpoint uniqueness

This commit is contained in:
nav
2026-05-12 08:49:34 +00:00
parent 0020df5d5e
commit e381679165
2 changed files with 16 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
import {
Body,
ConflictException,
Controller,
ForbiddenException,
Get,
@@ -23,6 +24,20 @@ export class NodesController {
throw new ForbiddenException('invalid shared secret');
}
const existedByNodeId = await this.nodeRepo.findOne({
where: { nodeId: body.nodeId },
});
if (existedByNodeId) {
throw new ConflictException('nodeId already exists');
}
const existedByEndpoint = await this.nodeRepo.findOne({
where: { endpoint: body.endpoint },
});
if (existedByEndpoint) {
throw new ConflictException('endpoint already exists');
}
const node = this.nodeRepo.create({
nodeId: body.nodeId,
name: body.name,