Parcourir la source

渠道全开/关

wuyi il y a 1 an
Parent
commit
c0fbd2c0fc
2 fichiers modifiés avec 21 ajouts et 2 suppressions
  1. 8 1
      src/channel/channel.controller.ts
  2. 13 1
      src/channel/channel.service.ts

+ 8 - 1
src/channel/channel.controller.ts

@@ -7,7 +7,8 @@ import { Channel } from './entities/channel.entities'
 @Controller('channel')
 @Public()
 export class ChannelController {
-    constructor(private readonly channelService: ChannelService) {}
+    constructor(private readonly channelService: ChannelService) {
+    }
 
     @Post('/')
     async findAll(@Body() page: PageRequest<Channel>) {
@@ -23,4 +24,10 @@ export class ChannelController {
     async delete(@Param('id') id: number) {
         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)
+    }
 }

+ 13 - 1
src/channel/channel.service.ts

@@ -10,7 +10,8 @@ export class ChannelService {
     constructor(
         @InjectRepository(Channel)
         private channelRepository: Repository<Channel>
-    ) {}
+    ) {
+    }
 
     async all() {
         return await this.channelRepository.find()
@@ -27,4 +28,15 @@ export class ChannelService {
     async delete(id: number): Promise<void> {
         await this.channelRepository.delete(id)
     }
+
+    async openAll(id: number, flag: number) {
+        const channel = await this.channelRepository.findOne({
+            where: { id }
+        })
+        channel.countryConfig.forEach(item => {
+            item.enabled = flag === 0
+        })
+        return await this.channelRepository.save(channel)
+    }
+
 }