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() @Column()
endpoint!: string; endpoint!: string;
@Column({ default: 'active' }) @Column({
status!: string; type: 'enum',
enum: ['active', 'offline', 'revoked'],
default: 'active',
})
status!: 'active' | 'offline' | 'revoked';
@CreateDateColumn() @CreateDateColumn()
createdAt!: Date; 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, DefaultValuePipe,
ForbiddenException, ForbiddenException,
Get, Get,
NotFoundException,
Param,
ParseIntPipe, ParseIntPipe,
Patch,
Post, Post,
Query, Query,
} from '@nestjs/common'; } from '@nestjs/common';
@@ -13,6 +16,7 @@ import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm'; import { Repository } from 'typeorm';
import { GuildNode } from '../entities/guild-node.entity'; import { GuildNode } from '../entities/guild-node.entity';
import { RegisterNodeDto } from './dto.register-node.dto'; import { RegisterNodeDto } from './dto.register-node.dto';
import { UpdateNodeStatusDto } from './dto.update-node-status.dto';
@Controller('nodes') @Controller('nodes')
export class NodesController { 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() @Get()
async list( async list(
@Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number, @Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number,

View File

@@ -25,7 +25,7 @@
### 1.2 Guild Node 注册与握手 ### 1.2 Guild Node 注册与握手
- [x] `POST /nodes/register` shared-secret 校验 - [x] `POST /nodes/register` shared-secret 校验
- [x] node 唯一性校验nodeId/endpoint - [x] node 唯一性校验nodeId/endpoint
- [ ] node 状态模型active/offline/revoked - [x] node 状态模型active/offline/revoked
- [x] `GET /nodes` 列表 + 分页 - [x] `GET /nodes` 列表 + 分页
- [ ] node 心跳接口(可选) - [ ] node 心跳接口(可选)