feat(center-nodes): add node status model and status update endpoint
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import { IsIn } from 'class-validator';
|
||||||
|
|
||||||
|
export class UpdateNodeStatusDto {
|
||||||
|
@IsIn(['active', 'offline', 'revoked'])
|
||||||
|
status!: 'active' | 'offline' | 'revoked';
|
||||||
|
}
|
||||||
@@ -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,
|
||||||
|
|||||||
@@ -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 心跳接口(可选)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user