feat(center-nodes): add node status model and status update endpoint
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user