feat(center-nodes): add node status model and status update endpoint
Some checks failed
backend-ci / verify (Fabric.Backend.Center) (push) Has been cancelled
backend-ci / verify (Fabric.Backend.Guild) (push) Has been cancelled

This commit is contained in:
nav
2026-05-12 08:52:39 +00:00
parent e10d225063
commit 7887a8d3be
4 changed files with 38 additions and 3 deletions

View File

@@ -14,8 +14,12 @@ export class GuildNode {
@Column()
endpoint!: string;
@Column({ default: 'active' })
status!: string;
@Column({
type: 'enum',
enum: ['active', 'offline', 'revoked'],
default: 'active',
})
status!: 'active' | 'offline' | 'revoked';
@CreateDateColumn()
createdAt!: Date;

View File

@@ -0,0 +1,6 @@
import { IsIn } from 'class-validator';
export class UpdateNodeStatusDto {
@IsIn(['active', 'offline', 'revoked'])
status!: 'active' | 'offline' | 'revoked';
}

View File

@@ -5,7 +5,10 @@ import {
DefaultValuePipe,
ForbiddenException,
Get,
NotFoundException,
Param,
ParseIntPipe,
Patch,
Post,
Query,
} from '@nestjs/common';
@@ -13,6 +16,7 @@ import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { GuildNode } from '../entities/guild-node.entity';
import { RegisterNodeDto } from './dto.register-node.dto';
import { UpdateNodeStatusDto } from './dto.update-node-status.dto';
@Controller('nodes')
export class NodesController {
@@ -61,6 +65,27 @@ export class NodesController {
};
}
@Patch(':nodeId/status')
async updateStatus(
@Param('nodeId') nodeId: string,
@Body() body: UpdateNodeStatusDto,
) {
const node = await this.nodeRepo.findOne({ where: { nodeId } });
if (!node) {
throw new NotFoundException('node not found');
}
node.status = body.status;
const saved = await this.nodeRepo.save(node);
return {
id: saved.id,
nodeId: saved.nodeId,
name: saved.name,
endpoint: saved.endpoint,
status: saved.status,
};
}
@Get()
async list(
@Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number,