feat(center-nodes): enforce nodeId and endpoint uniqueness
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user