Skip to content

Commit

Permalink
feat: get room list api
Browse files Browse the repository at this point in the history
  • Loading branch information
woody146 committed Jun 30, 2023
1 parent 9445504 commit 1bbcbb3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ Then, navigate to https://localhost:4430
<td></td>
</tr>
<tr>
<th colspan="4" align="center">For both</th>
<th colspan="4" align="center">Utils</th>
</tr>
<tr>
<td>POST</td>
Expand All @@ -249,6 +249,32 @@ Then, navigate to https://localhost:4430
</td>
<td></td>
</tr>
<tr>
<td>GET</td>
<td>/rooms<br /><i>get room list in system</i></td>
<td>
<ul>
<li>page?: number</li>
<li>pageSize?: number</li>
<li>orderBy?: string</li>
</ul>
</td>
<td>
<ul>
<li>items: array of room object</li>
<ul>
<li>id: string</li>
<li>createDate: Date</li>
</ul>
<li>pagination</li>
<ul>
<li>page: number</li>
<li>pageSize: number</li>
<li>total: number</li>
</ul>
</ul>
</td>
</tr>
</tbody>
</table>

Expand Down
7 changes: 7 additions & 0 deletions src/apis/master.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
22 changes: 22 additions & 0 deletions src/services/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit 1bbcbb3

Please sign in to comment.