panhui 2 лет назад
Родитель
Сommit
1761914e21
2 измененных файлов с 211 добавлено и 1 удалено
  1. 101 0
      src/web/web.controller.ts
  2. 110 1
      src/web/web.service.ts

+ 101 - 0
src/web/web.controller.ts

@@ -5,6 +5,11 @@ import { PageRequest } from 'src/common/dto/page-request'
 import { number } from 'yup'
 import { Public } from 'src/auth/public.decorator'
 import { Connect } from './entities/connect.entity'
+import { Case } from './entities/case.entity'
+import { HomeCase } from './entities/homeCase.entity'
+import { Web } from './entities/web.entity'
+import { Question } from './entities/Question.entity'
+import { Ability } from './entities/ability.entity'
 
 @ApiTags('web')
 @ApiBearerAuth()
@@ -18,30 +23,126 @@ export class WebController {
         return await this.webService.getCase()
     }
 
+    @Post('/cases/list')
+    public async findCases(@Body() page: PageRequest<Case>) {
+        return await this.webService.findCases(page)
+    }
+
+    @Put('/cases/save')
+    public async saveCases(@Body() connect: Partial<Case>) {
+        return await this.webService.saveCases(connect)
+    }
+
+    @Put('/cases/save/:id')
+    public async updateCases(@Body() connect: Partial<Case>) {
+        return await this.webService.saveCases(connect)
+    }
+
+    @Delete('/cases/del/:id')
+    public async delCase(@Param('id') id: string) {
+        return await this.webService.delCase(Number(id))
+    }
+
     @Get('/homeCases')
     @Public()
     public async getHomeCase() {
         return await this.webService.getHomeCase()
     }
 
+    @Post('/homeCases')
+    public async findHomeCases(@Body() page: PageRequest<HomeCase>) {
+        return await this.webService.findHomeCases(page)
+    }
+
+    @Post('/homeCases/save')
+    public async saveHomeCases(@Body() connect: Partial<HomeCase>) {
+        return await this.webService.saveHomeCases(connect)
+    }
+
+    @Put('/homeCases/save/:id')
+    public async updateHomeCases(@Body() connect: Partial<HomeCase>) {
+        return await this.webService.saveHomeCases(connect)
+    }
+
+    @Delete('/homeCases/del/:id')
+    public async delHomeCase(@Param('id') id: string) {
+        return await this.webService.delHomeCase(Number(id))
+    }
+
     @Get('/base')
     @Public()
     public async getBase() {
         return await this.webService.getBase()
     }
 
+    @Post('/base')
+    public async findBase(@Body() page: PageRequest<Web>) {
+        return await this.webService.findBase(page)
+    }
+
+    @Put('/base/save')
+    public async saveBase(@Body() connect: Partial<Web>) {
+        return await this.webService.updateBase(connect)
+    }
+
+    @Put('/base/save/:id')
+    public async updateBase(@Body() connect: Partial<Web>) {
+        return await this.webService.updateBase(connect)
+    }
+
     @Get('/question')
     @Public()
     public async getQuestion() {
         return await this.webService.getQuestion()
     }
 
+    @Post('/question')
+    public async findQuestion(@Body() page: PageRequest<Question>) {
+        return await this.webService.findQuestion(page)
+    }
+
+    @Put('/question/save')
+    public async saveQuestion(@Body() connect: Partial<Question>) {
+        return await this.webService.saveQuestion(connect)
+    }
+
+
+    @Put('/question/save/:id')
+    public async updateQuestion(@Body() connect: Partial<Question>) {
+        return await this.webService.saveQuestion(connect)
+    }
+
+    @Delete('/question/del/:id')
+    public async delQuestion(@Param('id') id: string) {
+        return await this.webService.delQuestion(Number(id))
+    }
+
     @Get('/ability/:id')
     @Public()
     public async getAbility(@Param('id') id: string) {
         return await this.webService.getAbility(Number(id))
     }
 
+    @Post('/ability')
+    public async findAbility(@Body() page: PageRequest<Ability>) {
+        return await this.webService.findAbility(page)
+    }
+
+    @Post('/ability/save')
+    public async saveAbility(@Body() connect: Partial<Ability>) {
+        return await this.webService.saveAbility(connect)
+    }
+
+    @Put('/ability/save/:id')
+    public async updateAbility(@Body() connect: Partial<Ability>) {
+        return await this.webService.saveAbility(connect)
+    }
+
+    @Delete('/ability/del/:id')
+    public async delAbility(@Param('id') id: string) {
+        return await this.webService.delAbility(Number(id))
+    }
+
     @Post('/connect/save')
     @Public()
     public async createConnect(@Body() connect: Partial<Connect>) {

+ 110 - 1
src/web/web.service.ts

@@ -69,10 +69,119 @@ export class WebService {
         }
     }
 
-
     public async findConnect(req: PageRequest<Connect>) {
         try {
             return await paginate<Connect>(this.connectRepository, req.page, req.search)
         } catch (error) {}
     }
+
+    async saveCases(connect: Partial<Case>) {
+        try {
+            return await this.caseRepository.save(connect)
+        } catch (error) {
+            throw new InternalServerErrorException(error.message)
+        }
+    }
+
+    public async findCases(req: PageRequest<Case>) {
+        try {
+            return await paginate<Case>(this.caseRepository, req.page, req.search)
+        } catch (error) {}
+    }
+
+    public async delCase(id: number) {
+        const _case = await this.caseRepository.findOneBy({
+            id: id
+        })
+        await this.caseRepository.save({
+            ..._case,
+            del: 1
+        })
+    }
+
+    async saveHomeCases(connect: Partial<HomeCase>) {
+        try {
+            return await this.homeCaseRepository.save(connect)
+        } catch (error) {
+            throw new InternalServerErrorException(error.message)
+        }
+    }
+
+    public async findHomeCases(req: PageRequest<HomeCase>) {
+        try {
+            return await paginate<HomeCase>(this.homeCaseRepository, req.page, req.search)
+        } catch (error) {}
+    }
+
+    public async delHomeCase(id: number) {
+        const _homeCase = await this.homeCaseRepository.findOneBy({
+            id: id
+        })
+        await this.homeCaseRepository.save({
+            ..._homeCase,
+            del: 1
+        })
+    }
+
+    async updateBase(connect: Partial<Web>) {
+        try {
+            return await this.webRepository.save(connect)
+        } catch (error) {
+            throw new InternalServerErrorException(error.message)
+        }
+    }
+
+    public async findBase(req: PageRequest<Web>) {
+        try {
+            return await paginate<Web>(this.webRepository, req.page, req.search)
+        } catch (error) {}
+    }
+
+    async saveQuestion(connect: Partial<Question>) {
+        try {
+            return await this.questionRepository.save(connect)
+        } catch (error) {
+            throw new InternalServerErrorException(error.message)
+        }
+    }
+
+    public async findQuestion(req: PageRequest<Question>) {
+        try {
+            return await paginate<Question>(this.questionRepository, req.page, req.search)
+        } catch (error) {}
+    }
+
+    public async delQuestion(id: number) {
+        const _question = await this.questionRepository.findOneBy({
+            id: id
+        })
+        await this.questionRepository.save({
+            ..._question,
+            del: 1
+        })
+    }
+
+    async saveAbility(connect: Partial<Ability>) {
+        try {
+            return await this.abilityRepository.save(connect)
+        } catch (error) {
+            throw new InternalServerErrorException(error.message)
+        }
+    }
+
+    public async findAbility(req: PageRequest<Ability>) {
+        try {
+            return await paginate<Ability>(this.abilityRepository, req.page, req.search)
+        } catch (error) {}
+    }
+
+    public async delAbility(id: number) {
+        const _ability = await this.abilityRepository.findOneBy({
+            id: id
+        })
+        await this.abilityRepository.save({
+            ..._ability,
+            del: 1
+        })
+    }
 }