feat: added complaintAttachment entity
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { BaseEntity } from "src/common/entities/base.entity";
|
||||
import { Column, Entity } from "typeorm";
|
||||
import { Column, Entity, OneToOne } from "typeorm";
|
||||
import { AttachmentType } from "../enums/attachment-type.enum";
|
||||
import { ComplaintAttachment } from "src/complaint/entities/complaint-attachment.entity";
|
||||
|
||||
@Entity('attachments')
|
||||
export class Attachment extends BaseEntity{
|
||||
@@ -20,4 +21,7 @@ export class Attachment extends BaseEntity{
|
||||
type: 'text'
|
||||
})
|
||||
filepath: string;
|
||||
|
||||
@OneToOne(() => ComplaintAttachment, (ca) => ca.attachment)
|
||||
complaint: ComplaintAttachment;
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@ import { ComplaintController } from './complaint.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Complaint } from './entities/complaint.entity';
|
||||
import { ComplaintRepository } from './repositories/complaint.repository';
|
||||
import { ComplaintAttachment } from './entities/complaint-attachment.entity';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Complaint])],
|
||||
imports: [TypeOrmModule.forFeature([Complaint, ComplaintAttachment])],
|
||||
controllers: [ComplaintController],
|
||||
providers: [ComplaintService, ComplaintRepository],
|
||||
})
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { BaseEntity } from "src/common/entities/base.entity";
|
||||
import { Entity, JoinColumn, ManyToOne, OneToOne, Unique } from "typeorm";
|
||||
import { Complaint } from "./complaint.entity";
|
||||
import { Attachment } from "src/attachment/entities/attachment.entity";
|
||||
|
||||
@Entity('complaint_attachments')
|
||||
@Unique(['attachment'])
|
||||
export class ComplaintAttachment extends BaseEntity {
|
||||
@ManyToOne(() => Complaint, (complaint) => complaint.attachments)
|
||||
complaint: Complaint;
|
||||
|
||||
@OneToOne(() => Attachment, (a) => a.complaint, {
|
||||
cascade: true,
|
||||
onDelete: 'CASCADE'
|
||||
})
|
||||
@JoinColumn()
|
||||
attachment: Attachment;
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
import { Column, Entity, JoinColumn, ManyToOne, OneToOne } from 'typeorm';
|
||||
import { Column, Entity, JoinColumn, ManyToOne, OneToMany, OneToOne } from 'typeorm';
|
||||
import { ComplaintStatus } from '../enums/complaint.enum';
|
||||
import { User } from 'src/users/entities/user.entity';
|
||||
import { Organ } from 'src/organ/entities/organ.entity';
|
||||
import { BaseEntity } from 'src/common/entities/base.entity';
|
||||
import { ComplaintAttachment } from './complaint-attachment.entity';
|
||||
|
||||
@Entity('complaints')
|
||||
export class Complaint extends BaseEntity {
|
||||
@@ -41,4 +42,7 @@ export class Complaint extends BaseEntity {
|
||||
name: 'organId'
|
||||
})
|
||||
organ: Organ;
|
||||
|
||||
@OneToMany(() => ComplaintAttachment, (ca) => ca.complaint)
|
||||
attachments: ComplaintAttachment[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user