feat(pagination): add generic typed pagination with ordering to all list endpoints
- add PaginationQueryDto<TOrderBy> generic with orderBy and orderDir fields - add SessionOrderBy, EnvironmentOrderBy, ScenarioOrderBy type aliases - update session, environment, scenario services and controllers to use typed pagination - update MCP list_sessions, list_environments, list_scenarios tools to expose orderBy/orderDir - update tests for all list endpoints to cover page, limit, ordering, and invalid param rejection
This commit is contained in:
1 parent
d9cdb64ee2
commit
36f8b8c0ca
16 files changed
+337
-81
No files matched your search
@@ -3,6 +3,9 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { SessionEntity } from './session.entity';
|
||||
import type { Cookie } from 'playwright';
|
||||
import { PaginationQueryDto, PaginatedResult } from '../common/dto/pagination.dto';
|
||||
|
||||
export type SessionOrderBy = 'id' | 'sessionName' | 'createdAt' | 'updatedAt';
|
||||
|
||||
@Injectable()
|
||||
export class SessionService {
|
||||
@@ -40,8 +43,18 @@ export class SessionService {
|
||||
return this.repo.findOneBy({ sessionName });
|
||||
}
|
||||
|
||||
findAll(): Promise<Pick<SessionEntity, 'id' | 'sessionName' | 'createdAt' | 'updatedAt'>[]> {
|
||||
return this.repo.find({ select: ['id', 'sessionName', 'createdAt', 'updatedAt'] });
|
||||
async findAll(query: PaginationQueryDto<SessionOrderBy> = {}): Promise<PaginatedResult<Pick<SessionEntity, 'id' | 'sessionName' | 'createdAt' | 'updatedAt'>>> {
|
||||
const page = query.page ?? 1;
|
||||
const limit = query.limit ?? 20;
|
||||
const orderBy = query.orderBy ?? 'id';
|
||||
const orderDir = query.orderDir ?? 'ASC';
|
||||
const [data, total] = await this.repo.findAndCount({
|
||||
select: ['id', 'sessionName', 'createdAt', 'updatedAt'],
|
||||
order: { [orderBy]: orderDir },
|
||||
skip: (page - 1) * limit,
|
||||
take: limit,
|
||||
});
|
||||
return { data, total, page, limit };
|
||||
}
|
||||
|
||||
async remove(id: number): Promise<void> {
|
||||
|
||||
Reference in new issue
Block a user