|
|
@@ -1,28 +1,26 @@
|
|
|
-import {
|
|
|
- Injectable, NotFoundException
|
|
|
-} from '@nestjs/common'
|
|
|
+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 { Form } from './entities/form.entity'
|
|
|
import { FormDto } from './dto/form.dto'
|
|
|
+import { Field } from './entities/filed.entity'
|
|
|
|
|
|
@Injectable()
|
|
|
export class FormService {
|
|
|
-
|
|
|
constructor(
|
|
|
@InjectRepository(Form)
|
|
|
- private readonly formRepository: Repository<Form>
|
|
|
- ) { }
|
|
|
+ private readonly formRepository: Repository<Form>,
|
|
|
+ @InjectRepository(Field)
|
|
|
+ private readonly filedRepository: Repository<Field>
|
|
|
+ ) {}
|
|
|
|
|
|
public async create(formDto: FormDto) {
|
|
|
return await this.formRepository.save(formDto)
|
|
|
}
|
|
|
|
|
|
- public async createAll(list: Form[]) {
|
|
|
-
|
|
|
- }
|
|
|
+ public async createAll(list: Form[]) {}
|
|
|
|
|
|
public async findById(id: number): Promise<Form> {
|
|
|
const form = await this.formRepository.findOneBy({
|
|
|
@@ -36,6 +34,41 @@ export class FormService {
|
|
|
return form
|
|
|
}
|
|
|
|
|
|
+ public async findAll(req: PageRequest<Form>) {
|
|
|
+ try {
|
|
|
+ return await paginate<Form>(this.formRepository, req.page, req.search)
|
|
|
+ } catch (error) {}
|
|
|
+ }
|
|
|
+
|
|
|
+ public async findAllFileds(req: PageRequest<Field>){
|
|
|
+ try {
|
|
|
+ return await paginate<Field>(this.filedRepository, req.page, req.search)
|
|
|
+ } catch (error) {}
|
|
|
+ }
|
|
|
|
|
|
+ async save(form: Partial<Form>) {
|
|
|
+ try {
|
|
|
+ return await this.formRepository.save(form)
|
|
|
+ } catch (error) {
|
|
|
+ throw new InternalServerErrorException(error.message)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
-}
|
|
|
+ async update(form: Partial<Form>) {
|
|
|
+ try {
|
|
|
+ return await this.formRepository.save(form)
|
|
|
+ } catch (error) {
|
|
|
+ throw new InternalServerErrorException(error.message)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async getFilds(formId: string) {
|
|
|
+ return await this.filedRepository.findBy({
|
|
|
+ formId: formId
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ async delete(id: number) {
|
|
|
+ await this.formRepository.delete(id)
|
|
|
+ }
|
|
|
+}
|