wuyi hace 1 año
padre
commit
ae25dde577

+ 3 - 1
src/app.module.ts

@@ -18,6 +18,7 @@ import { TaskModule } from './task/task.module'
 import { PhoneListModule } from './phone-list/phone-list.module'
 import { PhoneListModule } from './phone-list/phone-list.module'
 import { DeviceModule } from './device/device.module'
 import { DeviceModule } from './device/device.module'
 import { BalanceModule } from './balance/balance.module'
 import { BalanceModule } from './balance/balance.module'
+import { ChannelModule } from './channel/channel.module'
 
 
 @Module({
 @Module({
     imports: [
     imports: [
@@ -75,7 +76,8 @@ import { BalanceModule } from './balance/balance.module'
         TaskModule,
         TaskModule,
         PhoneListModule,
         PhoneListModule,
         DeviceModule,
         DeviceModule,
-        BalanceModule
+        BalanceModule,
+        ChannelModule
     ],
     ],
     controllers: [],
     controllers: [],
     providers: [
     providers: [

+ 28 - 0
src/channel/channel.controller.ts

@@ -0,0 +1,28 @@
+import { Public } from '../auth/public.decorator'
+import { Body, Controller, Post, Put } from '@nestjs/common'
+import { ChannelService } from './channel.service'
+import { PageRequest } from '../common/dto/page-request'
+import { Channel } from './entities/channel.entities'
+
+@Controller('channel')
+@Public()
+export class ChannelController {
+    constructor(private readonly channelService: ChannelService) {
+    }
+
+    @Post('/')
+    async findAll(@Body() page: PageRequest<Channel>) {
+        return await this.channelService.findAll(page)
+    }
+
+    @Put('/')
+    async create(@Body() body: any) {
+        return await this.channelService.create(body)
+    }
+
+    @Post('/delete')
+    async delete(@Body() id: number) {
+        return await this.channelService.delete(id)
+    }
+
+}

+ 18 - 0
src/channel/channel.module.ts

@@ -0,0 +1,18 @@
+import { Module } from '@nestjs/common'
+import { TypeOrmModule } from '@nestjs/typeorm'
+import { Channel } from './entities/channel.entities'
+import { TaskModule } from '../task/task.module'
+import { ChannelController } from './channel.controller'
+import { ChannelService } from './channel.service'
+
+@Module({
+    imports: [
+        TypeOrmModule.forFeature([Channel]),
+        TaskModule
+    ],
+    controllers: [ChannelController],
+    providers: [ChannelService],
+    exports: [ChannelService]
+})
+export class ChannelModule {
+}

+ 29 - 0
src/channel/channel.service.ts

@@ -0,0 +1,29 @@
+import { Injectable } from '@nestjs/common'
+import { Repository } from 'typeorm'
+import { Channel } from './entities/channel.entities'
+import { InjectRepository } from '@nestjs/typeorm'
+import { PageRequest } from '../common/dto/page-request'
+import { paginate, Pagination } from 'nestjs-typeorm-paginate'
+
+@Injectable()
+export class ChannelService {
+
+    constructor(
+        @InjectRepository(Channel)
+        private channelRepository: Repository<Channel>
+    ) {
+    }
+
+    async findAll(req: PageRequest<Channel>): Promise<Pagination<Channel>> {
+        return await paginate<Channel>(this.channelRepository, req.page, req.search)
+    }
+
+    async create(channel: Channel): Promise<Channel> {
+        return await this.channelRepository.save(channel)
+    }
+
+    async delete(id: number): Promise<void> {
+        await this.channelRepository.delete(id)
+    }
+
+}

+ 26 - 0
src/channel/entities/channel.entities.ts

@@ -0,0 +1,26 @@
+import { Column, CreateDateColumn, Entity, PrimaryGeneratedColumn } from 'typeorm'
+
+@Entity()
+export class Channel {
+    @PrimaryGeneratedColumn()
+    id: number
+
+    @Column()
+    mcc: string
+
+    @Column()
+    mnc: string
+
+    @Column()
+    country: string
+
+    @Column()
+    operator: string
+
+    @CreateDateColumn()
+    createdAt: Date
+
+    @Column({ nullable: true })
+    remark: string
+
+}

+ 3 - 0
src/task/entities/task.entity.ts

@@ -45,4 +45,7 @@ export class Task {
 
 
     @Column()
     @Column()
     successRate: string
     successRate: string
+
+    @Column({ nullable: false })
+    channelId: number
 }
 }