feat(center-nodes): add paginated node listing
This commit is contained in:
@@ -2,9 +2,12 @@ import {
|
|||||||
Body,
|
Body,
|
||||||
ConflictException,
|
ConflictException,
|
||||||
Controller,
|
Controller,
|
||||||
|
DefaultValuePipe,
|
||||||
ForbiddenException,
|
ForbiddenException,
|
||||||
Get,
|
Get,
|
||||||
|
ParseIntPipe,
|
||||||
Post,
|
Post,
|
||||||
|
Query,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
@@ -59,10 +62,25 @@ export class NodesController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async list() {
|
async list(
|
||||||
const items = await this.nodeRepo.find({
|
@Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number,
|
||||||
|
@Query('pageSize', new DefaultValuePipe(20), ParseIntPipe) pageSize: number,
|
||||||
|
) {
|
||||||
|
const safePage = page < 1 ? 1 : page;
|
||||||
|
const safePageSize = pageSize < 1 ? 20 : Math.min(pageSize, 100);
|
||||||
|
|
||||||
|
const [items, total] = await this.nodeRepo.findAndCount({
|
||||||
order: { createdAt: 'DESC' },
|
order: { createdAt: 'DESC' },
|
||||||
|
skip: (safePage - 1) * safePageSize,
|
||||||
|
take: safePageSize,
|
||||||
});
|
});
|
||||||
return { items };
|
|
||||||
|
return {
|
||||||
|
items,
|
||||||
|
page: safePage,
|
||||||
|
pageSize: safePageSize,
|
||||||
|
total,
|
||||||
|
totalPages: Math.max(1, Math.ceil(total / safePageSize)),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
- [x] `POST /nodes/register` shared-secret 校验
|
- [x] `POST /nodes/register` shared-secret 校验
|
||||||
- [x] node 唯一性校验(nodeId/endpoint)
|
- [x] node 唯一性校验(nodeId/endpoint)
|
||||||
- [ ] node 状态模型(active/offline/revoked)
|
- [ ] node 状态模型(active/offline/revoked)
|
||||||
- [ ] `GET /nodes` 列表 + 分页
|
- [x] `GET /nodes` 列表 + 分页
|
||||||
- [ ] node 心跳接口(可选)
|
- [ ] node 心跳接口(可选)
|
||||||
|
|
||||||
### 1.3 Center 运维能力
|
### 1.3 Center 运维能力
|
||||||
|
|||||||
Reference in New Issue
Block a user