diff --git a/README.md b/README.md index ce0cda6..b9bf735 100644 --- a/README.md +++ b/README.md @@ -237,7 +237,7 @@ Then, navigate to https://localhost:4430 - For both + Utils POST @@ -249,6 +249,32 @@ Then, navigate to https://localhost:4430 + + GET + /rooms
get room list in system + + + + + + + diff --git a/src/apis/master.ts b/src/apis/master.ts index ea7a916..1d2a929 100644 --- a/src/apis/master.ts +++ b/src/apis/master.ts @@ -7,6 +7,13 @@ import { import { RouteConfig, getDataSource } from '../utils/index.js'; export default [ + { + method: 'GET', + url: '/rooms', + handler: (data) => { + return new RoomService(getDataSource()).getList(data); + }, + }, { method: 'POST', url: '/rooms', diff --git a/src/services/room.ts b/src/services/room.ts index 3a6e445..6454a9f 100644 --- a/src/services/room.ts +++ b/src/services/room.ts @@ -39,6 +39,28 @@ export class RoomService extends BaseService { throw new ServiceError(404, 'Room not found'); } + async getList({ + page = 1, + pageSize = 30, + orderBy = '-createDate', + }: { + pageSize?: number; + page?: number; + orderBy?: string; + }) { + const [items, total] = await this.dataSource + .getRepository(MediaRoom) + .findAndCount({ + take: Math.max(pageSize, 100), + skip: (page - 1) * pageSize, + order: { [orderBy.slice(1)]: orderBy[0] === '-' ? 'DESC' : 'ASC' }, + }); + return { + items, + pagination: { page, pageSize, total }, + }; + } + async close(data: { roomId: string }) { const room = await this.get(data); await this.closeRouters({ roomId: room.id });