|
|
@@ -0,0 +1,78 @@
|
|
|
+import { Injectable, InternalServerErrorException, NotFoundException } from '@nestjs/common'
|
|
|
+import { FindManyOptions, FindOptionsOrder, In, Repository, UpdateResult } from 'typeorm'
|
|
|
+import { InjectRepository } from '@nestjs/typeorm'
|
|
|
+import { paginate, Pagination } from 'nestjs-typeorm-paginate'
|
|
|
+import { PageRequest } from '../common/dto/page-request'
|
|
|
+import { Case } from './entities/case.entity'
|
|
|
+import { Web } from './entities/web.entity'
|
|
|
+import { HomeCase } from './entities/homeCase.entity'
|
|
|
+import { Question } from './entities/Question.entity'
|
|
|
+import { Ability } from './entities/ability.entity'
|
|
|
+import { Connect } from './entities/connect.entity'
|
|
|
+
|
|
|
+@Injectable()
|
|
|
+export class WebService {
|
|
|
+ constructor(
|
|
|
+ @InjectRepository(Case)
|
|
|
+ private readonly caseRepository: Repository<Case>,
|
|
|
+ @InjectRepository(Web)
|
|
|
+ private readonly webRepository: Repository<Web>,
|
|
|
+ @InjectRepository(Question)
|
|
|
+ private readonly questionRepository: Repository<Question>,
|
|
|
+ @InjectRepository(HomeCase)
|
|
|
+ private readonly homeCaseRepository: Repository<HomeCase>,
|
|
|
+ @InjectRepository(Ability)
|
|
|
+ private readonly abilityRepository: Repository<Ability>,
|
|
|
+ @InjectRepository(Connect)
|
|
|
+ private readonly connectRepository: Repository<Connect>
|
|
|
+ ) {}
|
|
|
+
|
|
|
+ async getCase() {
|
|
|
+ return await this.caseRepository.findBy({
|
|
|
+ del: 0
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ async getHomeCase() {
|
|
|
+ return await this.homeCaseRepository.findBy({
|
|
|
+ del: 0
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ async getBase() {
|
|
|
+ return await this.webRepository.find({
|
|
|
+ where: {
|
|
|
+ del: 0
|
|
|
+ },
|
|
|
+ order: { direction: 'ASC' }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ async getQuestion() {
|
|
|
+ return await this.questionRepository.findBy({
|
|
|
+ del: 0
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ async getAbility(webId: number) {
|
|
|
+ return await this.abilityRepository.findBy({
|
|
|
+ del: 0,
|
|
|
+ webId: webId
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ async saveConnect(connect: Partial<Connect>) {
|
|
|
+ try {
|
|
|
+ return await this.connectRepository.save(connect)
|
|
|
+ } catch (error) {
|
|
|
+ throw new InternalServerErrorException(error.message)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public async findConnect(req: PageRequest<Connect>) {
|
|
|
+ try {
|
|
|
+ return await paginate<Connect>(this.connectRepository, req.page, req.search)
|
|
|
+ } catch (error) {}
|
|
|
+ }
|
|
|
+}
|