replaced relations with foreign keys

This commit is contained in:
OkaykOrhmn 2025-07-23 15:11:27 +03:30
parent aeb7a73c4c
commit 64796fcdf7
22 changed files with 218 additions and 201 deletions

View File

@ -1,22 +1,14 @@
import { Column, Entity, ManyToOne } from 'typeorm'; import { Column, Entity } from 'typeorm';
import { BaseEntity } from 'src/_core/entity/_base.entity'; import { BaseEntity } from 'src/_core/entity/_base.entity';
import { Question } from '../../question/entity/question.entity';
@Entity({ name: 'answers' }) @Entity({ name: 'answers' })
export class Answer extends BaseEntity { export class Answer extends BaseEntity {
@Column({ @Column({ type: 'uuid' })
type: 'uuid',
})
participantId: string; participantId: string;
@Column({ @Column({ type: 'uuid' })
type: 'uuid',
})
questionId: string; questionId: string;
@Column() @Column()
value: string; value: string;
@ManyToOne(() => Question, question => question.answers)
question: Question;
} }

View File

@ -16,6 +16,5 @@ export class CreateAttachmentDto extends BaseDto {
storageUrl: string; storageUrl: string;
@IsUUID() @IsUUID()
@IsOptional() ownerId: string;
ownerId?: string;
} }

View File

@ -1,8 +1,5 @@
import { Column, Entity, ManyToOne } from 'typeorm'; import { Column, Entity } from 'typeorm';
import { BaseEntity } from 'src/_core/entity/_base.entity'; import { BaseEntity } from 'src/_core/entity/_base.entity';
import { Question } from 'src/question/entity/question.entity';
import { FormSection } from '../../formSection/entity/formSection.entity';
import { Form } from '../../form/entity/form.entity';
@Entity({ name: 'attachments' }) @Entity({ name: 'attachments' })
export class Attachment extends BaseEntity { export class Attachment extends BaseEntity {
@ -21,17 +18,6 @@ export class Attachment extends BaseEntity {
@Column() @Column()
storageUrl: string; storageUrl: string;
@Column({ @Column({ type: 'uuid' })
type: 'uuid',
})
ownerId: string; ownerId: string;
@ManyToOne(() => Question, (question) => question.attachments)
question: Question;
@ManyToOne(() => FormSection, formSection => formSection.attachments)
formSection: FormSection;
@ManyToOne(() => Form, form => form.attachments)
form: Form;
} }

View File

@ -1,9 +1,5 @@
import { IsString, IsOptional, ValidateNested, IsArray } from 'class-validator'; import { IsString, IsOptional, IsArray, IsUUID, IsBoolean } from 'class-validator';
import { Type } from 'class-transformer';
import { BaseDto } from '../../_core/dto/base.dto'; import { BaseDto } from '../../_core/dto/base.dto';
import { CreateFormPageDto } from '../../formPage/dto/create-formPage.dto';
import { CreateParticipantDto } from '../../participant/dto/create-participant.dto';
import { CreateAttachmentDto } from '../../attachment/dto/create_attachment.dto';
export class CreateFormDto extends BaseDto { export class CreateFormDto extends BaseDto {
@IsString() @IsString()
@ -12,21 +8,25 @@ export class CreateFormDto extends BaseDto {
@IsString() @IsString()
description: string; description: string;
@IsArray() @IsBoolean()
@ValidateNested({ each: true }) isEnded: boolean;
@Type(() => CreateAttachmentDto)
@IsOptional()
attachments?: CreateAttachmentDto[]; // Keep if attachments are still part of the DTO
@IsArray()
@ValidateNested({ each: true })
@Type(() => CreateFormPageDto)
@IsOptional() @IsOptional()
pages?: CreateFormPageDto[]; @IsArray()
@IsUUID('4', { each: true })
pageIds?: string[];
@IsArray()
@ValidateNested({ each: true })
@Type(() => CreateParticipantDto)
@IsOptional() @IsOptional()
participants?: CreateParticipantDto[]; @IsArray()
} @IsUUID('4', { each: true })
participantIds?: string[];
@IsOptional()
@IsArray()
@IsUUID('4', { each: true })
attachmentIds?: string[];
@IsOptional()
@IsUUID('4')
formResultId?: string;
}

View File

@ -1,11 +1,7 @@
import { Entity, Column, OneToMany, ManyToOne } from 'typeorm'; import { Entity, Column } from 'typeorm';
import { BaseEntity } from '../../_core/entity/_base.entity'; import { BaseEntity } from '../../_core/entity/_base.entity';
import { FormPage } from '../../formPage/entity/formPage.entity';
import { Participant } from '../../participant/entity/participant.entity';
import { Realm } from '../../realm/entity/realm.entity';
import { Attachment } from '../../attachment/entity/attachment.entity';
@Entity() @Entity({ name: 'forms' })
export class Form extends BaseEntity { export class Form extends BaseEntity {
@Column() @Column()
title: string; title: string;
@ -13,20 +9,18 @@ export class Form extends BaseEntity {
@Column() @Column()
description: string; description: string;
// One-to-Many relationship with FormPage @Column({ default: false })
@OneToMany(() => FormPage, formPage => formPage.form, { cascade: true, eager: true }) isEnded: boolean;
pages: FormPage[];
// One-to-Many relationship with Participant @Column('simple-array', { nullable: true })
@OneToMany(() => Participant, participant => participant.form, { cascade: true, eager: true }) pageIds: string[];
participants: Participant[];
@Column('simple-array', { nullable: true })
participantIds: string[];
// One-to-Many relationship with Attachment @Column('simple-array', { nullable: true })
@OneToMany(() => Attachment, attachment => attachment.form, { cascade: true, eager: true }) attachmentIds: string[];
attachments: Attachment[];
@ManyToOne(() => Realm, realm => realm.forms, { /*cascade: true, eager: true */}) @Column({ type: 'uuid', nullable: true })
realm: Realm; formResultId: string;
}
}

View File

@ -1,7 +1,5 @@
import { IsString, ValidateNested, IsArray } from 'class-validator'; import { IsString, IsArray, IsOptional, IsUUID } from 'class-validator';
import { Type } from 'class-transformer';
import { BaseDto } from '../../_core/dto/base.dto'; import { BaseDto } from '../../_core/dto/base.dto';
import { CreateFormSectionDto } from '../../formSection/dto/create-formSection.dto';
export class CreateFormPageDto extends BaseDto { export class CreateFormPageDto extends BaseDto {
@IsString() @IsString()
@ -10,8 +8,8 @@ export class CreateFormPageDto extends BaseDto {
@IsString() @IsString()
description: string; description: string;
@IsOptional()
@IsArray() @IsArray()
@ValidateNested({ each: true }) @IsUUID('4', { each: true })
@Type(() => CreateFormSectionDto) formSectionIds?: string[];
formSections: CreateFormSectionDto[];
} }

View File

@ -1,7 +1,6 @@
import { Entity, Column, OneToMany, ManyToOne } from 'typeorm'; import { Entity, Column } from 'typeorm';
import { BaseEntity } from '../../_core/entity/_base.entity'; import { BaseEntity } from '../../_core/entity/_base.entity';
import { FormSection } from '../../formSection/entity/formSection.entity';
import { Form } from '../../form/entity/form.entity';
@Entity() @Entity()
export class FormPage extends BaseEntity { export class FormPage extends BaseEntity {
@ -11,12 +10,6 @@ export class FormPage extends BaseEntity {
@Column() @Column()
description: string; description: string;
// One-to-Many relationship with FormSection @Column('simple-array', { nullable: true })
@OneToMany(() => FormSection, formSection => formSection.formPage, { cascade: true, eager: true }) formSectionIds: string[];
formSections: FormSection[];
// Many-to-One relationship with Form
@ManyToOne(() => Form, form => form.pages) // Ensure 'pages' matches the property name in Form entity
form: Form;
} }

View File

@ -1,5 +1,7 @@
import { Entity, Column } from 'typeorm'; import { Entity, Column, ManyToOne, OneToOne } from 'typeorm';
import { BaseEntity } from '../../_core/entity/_base.entity'; import { BaseEntity } from '../../_core/entity/_base.entity';
import { Realm } from '../../realm/entity/realm.entity';
import { Form } from '../../form/entity/form.entity';
// Options class (embedded) // Options class (embedded)
export class Options { export class Options {
@ -24,6 +26,9 @@ export class Opinion {
@Entity() @Entity()
export class FormResult extends BaseEntity { export class FormResult extends BaseEntity {
@OneToOne(() => Form, form => form.formResult, { /*cascade: true, eager: true */})
form: Form;
@Column({ type: 'int', default: 0 }) @Column({ type: 'int', default: 0 })
numParticipants: number; numParticipants: number;

View File

@ -43,4 +43,11 @@ export class FormResultController {
async remove(@Param('id', new ParseUUIDPipe()) id: string): Promise<void> { async remove(@Param('id', new ParseUUIDPipe()) id: string): Promise<void> {
return this.formResultService.remove(id); return this.formResultService.remove(id);
} }
@Get('form/:formId/statistics')
async getFormStatistics(
@Param('formId', new ParseUUIDPipe()) formId: string,
): Promise<FormResult> {
return this.formResultService.getFormStatistics(formId);
}
} }

View File

@ -3,12 +3,13 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { FormResultService } from './formResult.service'; import { FormResultService } from './formResult.service';
import { FormResultController } from './formResult.controller'; import { FormResultController } from './formResult.controller';
import { FormResult } from './entity/formResult.entity'; import { FormResult } from './entity/formResult.entity';
import { Form } from '../form/entity/form.entity';
import { Question } from '../question/entity/question.entity';
import { Answer } from '../answer/entity/answer.entity';
@Module({ @Module({
imports: [ imports: [
TypeOrmModule.forFeature([ TypeOrmModule.forFeature([FormResult, Form, Question, Answer]),
FormResult,
]),
], ],
controllers: [FormResultController], controllers: [FormResultController],
providers: [FormResultService], providers: [FormResultService],

View File

@ -4,12 +4,21 @@ import { Repository } from 'typeorm';
import { FormResult } from './entity/formResult.entity'; import { FormResult } from './entity/formResult.entity';
import { CreateFormResultDto } from './dto/create-formResult.dto'; import { CreateFormResultDto } from './dto/create-formResult.dto';
import { UpdateFormResultDto } from './dto/update-formResult.dto'; import { UpdateFormResultDto } from './dto/update-formResult.dto';
import { Answer } from 'src/answer/entity/answer.entity';
import { Question } from '../question/entity/question.entity';
import { Form } from '../form/entity/form.entity';
@Injectable() @Injectable()
export class FormResultService { export class FormResultService {
constructor( constructor(
@InjectRepository(Form)
private readonly formRepository: Repository<Form>,
@InjectRepository(FormResult) @InjectRepository(FormResult)
private readonly formResultRepo: Repository<FormResult>, private readonly formResultRepo: Repository<FormResult>,
@InjectRepository(Question)
private readonly questionRepository: Repository<Question>,
@InjectRepository(Answer)
private readonly answerRepository: Repository<Answer>,
) {} ) {}
async create(data: CreateFormResultDto): Promise<FormResult> { async create(data: CreateFormResultDto): Promise<FormResult> {
@ -85,4 +94,90 @@ export class FormResultService {
throw new NotFoundException(`FormResult with ID "${id}" not found`); throw new NotFoundException(`FormResult with ID "${id}" not found`);
} }
} }
async getFormStatistics(formId: string): Promise<FormResult> {
// 1. Find the Form entity
const form = await this.formRepository.findOne({ where: { id: formId } });
if (!form) {
throw new NotFoundException(`Form with ID "${formId}" not found`);
}
// 2. Compute numQuestions
const numQuestions = await this.questionRepository.count({
where: {
formSection: {
formPage: {
form: { id: formId },
},
},
},
});
// 3. Compute numParticipants
const numParticipantsResult = await this.answerRepository
.createQueryBuilder('answer')
.select('COUNT(DISTINCT answer.participantId)', 'count')
.innerJoin('answer.question', 'question')
.innerJoin('question.formSection', 'formSection')
.innerJoin('formSection.formPage', 'formPage')
.where('formPage.formId = :formId', { formId })
.getRawOne();
const numParticipants = numParticipantsResult ? Number(numParticipantsResult.count) : 0;
// 4. Compute numAnswers
const numAnswers = await this.answerRepository.count({
where: {
question: {
formSection: {
formPage: {
form: { id: formId },
},
},
},
},
});
// 5. Compute numCompleteParticipants
const subQuery = this.answerRepository
.createQueryBuilder('answer')
.select('answer.participantId')
.innerJoin('answer.question', 'question')
.innerJoin('question.formSection', 'formSection')
.innerJoin('formSection.formPage', 'formPage')
.where('formPage.formId = :formId', { formId })
.groupBy('answer.participantId')
.having('COUNT(DISTINCT answer.questionId) = :numQuestions', { numQuestions });
const numCompleteParticipantsResult = await this.answerRepository.manager
.createQueryBuilder()
.select('COUNT(*)', 'count')
.from(`(${subQuery.getQuery()})`, 'subquery')
.setParameters(subQuery.getParameters())
.getRawOne();
const numCompleteParticipants = numCompleteParticipantsResult ? Number(numCompleteParticipantsResult.count) : 0;
// 6. Find or create FormResult for the Form
let formResult = await this.formResultRepo.findOne({ where: { form: { id: formId } }, relations: ['form'] });
if (!formResult) {
formResult = this.formResultRepo.create({
form, // Link to the Form entity
numQuestions,
numParticipants,
numAnswers,
numComplete: numCompleteParticipants,
opinions: [], // Initialize as empty or compute if needed
status: 'active',
});
} else {
formResult.numQuestions = numQuestions;
formResult.numParticipants = numParticipants;
formResult.numAnswers = numAnswers;
formResult.numComplete = numCompleteParticipants;
// Preserve existing opinions or update if needed
}
// 7. Save and return the FormResult
return await this.formResultRepo.save(formResult);
}
} }

View File

@ -1,21 +1,19 @@
import { IsString, IsOptional, IsUUID, ValidateNested, IsArray, IsEnum, IsDateString } from 'class-validator'; import { IsString, IsOptional, IsUUID, ValidateNested, IsArray, IsEnum } from 'class-validator';
import { Type } from 'class-transformer'; import { Type } from 'class-transformer';
import { BaseDto } from '../../_core/dto/base.dto'; import { BaseDto } from '../../_core/dto/base.dto';
import { CreateAttachmentDto } from '../../attachment/dto/create_attachment.dto';
import { CreateQuestionDto } from '../../question/dto/create-question.dto';
// DTO for DisplayCondition // DTO for DisplayCondition
export class CreateDisplayConditionDto { export class CreateDisplayConditionDto {
@IsUUID() @IsUUID('4')
answer: string; answer: string; // UUID referencing Answer.id
@IsUUID() @IsUUID('4')
question: string; question: string; // UUID referencing Question.id
@IsEnum(['equal', 'contains', 'not_equal', 'not_contains']) @IsEnum(['equal', 'contains', 'not_equal', 'not_contains'])
relation: 'equal' | 'contains' | 'not_equal' | 'not_contains'; relation: 'equal' | 'contains' | 'not_equal' | 'not_contains';
} }
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
export class CreateFormSectionDto extends BaseDto { export class CreateFormSectionDto extends BaseDto {
@IsString() @IsString()
title: string; title: string;
@ -23,19 +21,19 @@ export class CreateFormSectionDto extends BaseDto {
@IsString() @IsString()
description: string; description: string;
@IsArray()
@ValidateNested({ each: true })
@Type(() => CreateAttachmentDto)
@IsOptional() @IsOptional()
attachments?: CreateAttachmentDto[]; @IsArray()
@IsUUID('4', { each: true })
attachmentIds?: string[];
@IsOptional()
@IsArray()
@IsUUID('4', { each: true })
questionIds?: string[];
@IsOptional()
@IsArray() @IsArray()
@ValidateNested({ each: true }) @ValidateNested({ each: true })
@Type(() => CreateDisplayConditionDto) @Type(() => CreateDisplayConditionDto)
displayCondition: CreateDisplayConditionDto[]; displayCondition?: CreateDisplayConditionDto[];
}
@IsArray()
@ValidateNested({ each: true })
@Type(() => CreateQuestionDto)
questions: CreateQuestionDto[];
}

View File

@ -1,12 +1,8 @@
// src/formSection/entity/formSection.entity.ts import { Entity, Column } from 'typeorm'; // Removed Embeddable import
import { Entity, Column, OneToMany, ManyToOne } from 'typeorm'; // Removed Embeddable import
import { BaseEntity } from '../../_core/entity/_base.entity'; import { BaseEntity } from '../../_core/entity/_base.entity';
import { Attachment } from '../../attachment/entity/attachment.entity';
import { Question } from '../../question/entity/question.entity';
import { FormPage } from 'src/formPage/entity/formPage.entity';
// DisplayCondition is now a regular class, embedded using @Column(() => DisplayCondition) // DisplayCondition is now a regular class, embedded using @Column(() => DisplayCondition)
export class DisplayCondition { export class DisplayCondition { // needs clarification
@Column() @Column()
answer: string; // Assuming this is an ID reference to an Answer entity answer: string; // Assuming this is an ID reference to an Answer entity
@ -28,19 +24,12 @@ export class FormSection extends BaseEntity {
@Column() @Column()
description: string; description: string;
// One-to-Many relationship with Attachment @Column('simple-array', { nullable: true })
@OneToMany(() => Attachment, attachment => attachment.formSection, { cascade: true, eager: true }) attachmentIds: string[];
attachments: Attachment[];
// Using @Column(() => DisplayCondition) for embedded array of objects @Column('simple-array', { nullable: true })
@Column(() => DisplayCondition) questionIds: string[];
@Column(() => DisplayCondition) // needs to be checked
displayCondition: DisplayCondition[]; displayCondition: DisplayCondition[];
// One-to-Many relationship with Question
@OneToMany(() => Question, question => question.formSection, { cascade: true, eager: true })
questions: Question[];
// Many-to-One relationship with FormPage
@ManyToOne(() => FormPage, formPage => formPage.formSections)
formPage: FormPage;
} }

View File

@ -6,9 +6,4 @@ import { Question } from 'src/question/entity/question.entity';
export class Option extends BaseEntity { export class Option extends BaseEntity {
@Column() @Column()
text: string; text: string;
@ManyToOne(() => Question, (question) => question.options)
question: Question;
} }

View File

@ -1,9 +1,10 @@
import { IsString, IsEnum, IsOptional, IsUUID, ValidateNested } from 'class-validator'; import { IsString, IsEnum, IsOptional, IsUUID } from 'class-validator';
import { Type } from 'class-transformer';
import { MetadataDto } from '../../_core/dto/metadataEntry.dto';
import { BaseDto } from '../../_core/dto/base.dto'; import { BaseDto } from '../../_core/dto/base.dto';
export class CreateParticipantDto extends BaseDto { export class CreateParticipantDto extends BaseDto {
@IsUUID('4')
userId: string;
@IsString() @IsString()
displayName: string; displayName: string;

View File

@ -1,7 +1,5 @@
import { Column, Entity, ManyToOne } from 'typeorm'; import { Column, Entity } from 'typeorm';
import { BaseEntity } from 'src/_core/entity/_base.entity'; import { BaseEntity } from 'src/_core/entity/_base.entity';
import { Form } from 'src/form/entity/form.entity';
import { Realm } from '../../realm/entity/realm.entity';
@Entity({ name: 'participants' }) @Entity({ name: 'participants' })
export class Participant extends BaseEntity { export class Participant extends BaseEntity {
@ -20,12 +18,4 @@ export class Participant extends BaseEntity {
@Column() @Column()
displayName: string; displayName: string;
// Many-to-One relationship with Form
@ManyToOne(() => Form, form => form.participants)
form: Form;
// Many-to-One relationship with Realm (if a participant belongs to a realm)
@ManyToOne(() => Realm, realm => realm.participants)
realm: Realm;
} }

View File

@ -1,6 +1,4 @@
import { IsString, IsEnum, IsOptional, IsUUID, ValidateNested } from 'class-validator'; import { IsString, IsEnum } from 'class-validator';
import { Type } from 'class-transformer';
import { MetadataDto } from '../../_core/dto/metadataEntry.dto';
import { BaseDto } from '../../_core/dto/base.dto'; import { BaseDto } from '../../_core/dto/base.dto';
export class CreateParticipantGroupDto extends BaseDto{ export class CreateParticipantGroupDto extends BaseDto{

View File

@ -1,9 +1,6 @@
import { import {
Entity, Entity,
PrimaryGeneratedColumn,
Column, Column,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm'; } from 'typeorm';
import { BaseEntity } from '../../_core/entity/_base.entity'; import { BaseEntity } from '../../_core/entity/_base.entity';

View File

@ -4,12 +4,9 @@ import {
IsOptional, IsOptional,
IsArray, IsArray,
IsEnum, IsEnum,
ValidateNested, IsUUID,
} from 'class-validator'; } from 'class-validator';
import { Type } from 'class-transformer';
import { BaseDto } from '../../_core/dto/base.dto'; import { BaseDto } from '../../_core/dto/base.dto';
import { CreateOptionDto } from '../../option/dto/create-option.dto';
import { CreateAttachmentDto } from '../../attachment/dto/create_attachment.dto';
export class CreateQuestionDto extends BaseDto { export class CreateQuestionDto extends BaseDto {
@IsString() @IsString()
@ -32,13 +29,11 @@ export class CreateQuestionDto extends BaseDto {
@IsOptional() @IsOptional()
@IsArray() @IsArray()
@ValidateNested({ each: true }) @IsUUID('4', { each: true })
@Type(() => CreateOptionDto) optionIds?: string[];
options?: CreateOptionDto[];
@IsOptional() @IsOptional()
@IsArray() @IsArray()
@ValidateNested({ each: true }) @IsUUID('4', { each: true })
@Type(() => CreateAttachmentDto) attachmentIds?: string[];
attachments?: CreateAttachmentDto[]; }
}

View File

@ -35,15 +35,9 @@ export class Question extends BaseEntity {
}) })
validationRules?: string; validationRules?: string;
@OneToMany(() => Option, (option) => option.question, { cascade: true }) @Column('simple-array', { nullable: true })
options: Option[]; optionIds: string[];
@OneToMany(() => Attachment, (attachment) => attachment.question, { cascade: true }) @Column('simple-array', { nullable: true })
attachments: Attachment[]; attachmentIds: string[];
@OneToMany(() => Answer, answer => answer.question, { cascade: true })
answers: Answer[]; // Answers to this question
@ManyToOne(() => FormSection, formSection => formSection.questions)
formSection: FormSection;
} }

View File

@ -1,8 +1,5 @@
import { IsString, IsOptional, ValidateNested, IsArray } from 'class-validator'; import { IsString, IsOptional, IsArray, IsUUID } from 'class-validator';
import { Type } from 'class-transformer';
import { BaseDto } from '../../_core/dto/base.dto'; import { BaseDto } from '../../_core/dto/base.dto';
import { CreateFormDto } from '../../form/dto/create-form.dto';
import { CreateParticipantDto } from '../../participant/dto/create-participant.dto';
export class CreateRealmDto extends BaseDto { export class CreateRealmDto extends BaseDto {
@IsString() @IsString()
@ -11,19 +8,16 @@ export class CreateRealmDto extends BaseDto {
@IsString() @IsString()
description: string; description: string;
@IsArray()
@ValidateNested({ each: true })
@Type(() => CreateFormDto)
@IsOptional() @IsOptional()
forms?: CreateFormDto[];
@IsArray() @IsArray()
@ValidateNested({ each: true }) @IsUUID('4', { each: true })
@Type(() => CreateParticipantDto) formIds?: string[];
@IsOptional()
participants?: CreateParticipantDto[];
// @ValidateNested() // Not IsArray, as it's a single owner @IsOptional()
// @Type(() => CreateParticipantDto) @IsArray()
// owner: CreateParticipantDto; @IsUUID('4', { each: true }) // I'd say it's not needed, cause form has participants
} participantIds?: string[];
@IsUUID('4')
ownerId: string;
}

View File

@ -1,7 +1,5 @@
import { Entity, Column, OneToMany, OneToOne, JoinColumn} from 'typeorm'; import { Entity, Column } from 'typeorm';
import { BaseEntity } from '../../_core/entity/_base.entity'; import { BaseEntity } from '../../_core/entity/_base.entity';
import { Form } from '../../form/entity/form.entity';
import { Participant } from '../../participant/entity/participant.entity';
@Entity() @Entity()
export class Realm extends BaseEntity { export class Realm extends BaseEntity {
@ -11,14 +9,12 @@ export class Realm extends BaseEntity {
@Column() @Column()
description: string; description: string;
@OneToMany(() => Form, form => form.realm, { cascade: true, eager: true }) @Column('simple-array', { nullable: true })
forms: Form[]; formIds: string[];
@OneToMany(() => Participant, participant => participant.realm, { cascade: true, eager: true }) @Column('simple-array', { nullable: true }) // I'd say it's not needed, cause form has participants
participants: Participant[]; participantIds: string[];
@OneToOne(() => Participant, { cascade: true, eager: true }) @Column({ type: 'uuid' })
@JoinColumn({ name: 'ownerId', referencedColumnName: 'userId' }) // be explicit ownerId: string;
owner: Participant; }
}