Browse Source

feat(channel): 添加频道列表接口并优化频道相关功能

- 新增 getChannelList 接口,用于获取频道列表
- 优化 findAll 方法,设置默认分页大小为 50
wui 1 year ago
parent
commit
f356b5450b
2 changed files with 18 additions and 6 deletions
  1. 9 3
      src/channel/channel.controller.ts
  2. 9 3
      src/channel/channel.service.ts

+ 9 - 3
src/channel/channel.controller.ts

@@ -3,15 +3,17 @@ import { Body, Controller, Delete, Get, Param, Post, Put } from '@nestjs/common'
 import { ChannelService } from './channel.service'
 import { PageRequest } from '../common/dto/page-request'
 import { Channel } from './entities/channel.entities'
+import { HasRoles } from '../auth/roles.decorator'
+import { Role } from '../model/role.enum'
 
 @Controller('channel')
 @Public()
 export class ChannelController {
-    constructor(private readonly channelService: ChannelService) {
-    }
+    constructor(private readonly channelService: ChannelService) {}
 
     @Post('/')
     async findAll(@Body() page: PageRequest<Channel>) {
+        page.page.limit = 50
         return await this.channelService.findAll(page)
     }
 
@@ -25,9 +27,13 @@ export class ChannelController {
         return await this.channelService.delete(id)
     }
 
-
     @Get('/:id/open/:flag')
     async openAll(@Param('id') id: number, @Param('flag') flag: number) {
         return await this.channelService.openAll(id, flag)
     }
+
+    @Get('/channelList')
+    async getChannelList() {
+        return await this.channelService.getChannelList()
+    }
 }

+ 9 - 3
src/channel/channel.service.ts

@@ -10,8 +10,7 @@ export class ChannelService {
     constructor(
         @InjectRepository(Channel)
         private channelRepository: Repository<Channel>
-    ) {
-    }
+    ) {}
 
     async all() {
         return await this.channelRepository.find()
@@ -33,10 +32,17 @@ export class ChannelService {
         const channel = await this.channelRepository.findOne({
             where: { id }
         })
-        channel.countryConfig.forEach(item => {
+        channel.countryConfig.forEach((item) => {
             item.enabled = flag === 0
         })
         return await this.channelRepository.save(channel)
     }
 
+    async getChannelList() {
+        const channels = await this.channelRepository.find()
+        return channels.map((item) => ({
+            value: item.source,
+            label: item.source
+        }))
+    }
 }