Update Submodules
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { FormularEntity } from './formular.entity';
|
||||
import { FormResultsEntity } from './results.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Formular, MyField } from 'src/dto/formular.dto';
|
||||
import { FieldEntity } from './fields.entity';
|
||||
import { FormResultEntity } from './result.entity';
|
||||
import { FormResultsEntity } from './results.entity';
|
||||
|
||||
@Injectable()
|
||||
export class FormularService {
|
||||
@@ -13,6 +14,10 @@ export class FormularService {
|
||||
private readonly formularRepository: Repository<FormularEntity>,
|
||||
@InjectRepository(FieldEntity)
|
||||
private readonly fieldRepository: Repository<FieldEntity>,
|
||||
@InjectRepository(FormResultsEntity)
|
||||
private readonly formularResultsRepository: Repository<FormResultsEntity>,
|
||||
@InjectRepository(FormResultEntity)
|
||||
private readonly formularResultRepository: Repository<FormResultEntity>
|
||||
){}
|
||||
|
||||
async getFormulare(): Promise<Formular[]>{
|
||||
@@ -24,8 +29,33 @@ export class FormularService {
|
||||
return await this.fieldRepository.findBy({formular: formularid});
|
||||
}
|
||||
async submit(
|
||||
formularid:number
|
||||
){
|
||||
formularid:number,
|
||||
names:string[],
|
||||
values:string[]
|
||||
): Promise<boolean>{
|
||||
|
||||
if(names.length!=values.length) return false;
|
||||
let formResult=await this.formularResultsRepository.create({
|
||||
formular: await this.formularRepository.findBy({id:formularid})[0],
|
||||
formularid: formularid
|
||||
} as FormResultsEntity);
|
||||
|
||||
await this.formularResultsRepository.save(formResult);
|
||||
|
||||
let entities=names.map((name,i)=>{
|
||||
return {
|
||||
name,
|
||||
value: values[i],
|
||||
parentobj: formResult,
|
||||
parentid: formResult.id
|
||||
} as FormResultEntity;
|
||||
});
|
||||
|
||||
const formularResult=this.formularResultRepository.create(entities);
|
||||
|
||||
|
||||
await this.formularResultRepository.save(formularResult);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user