From 8e957f0837e75e218d1b84642cc43e4ad0c1328c Mon Sep 17 00:00:00 2001 From: BatuhanIlhan Date: Tue, 14 Nov 2023 12:58:50 +0300 Subject: [PATCH] BE-284: Create many to many relation between users --- app/backend/src/user/entities/user.entity.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/backend/src/user/entities/user.entity.ts b/app/backend/src/user/entities/user.entity.ts index be76c1f4..9496c1aa 100644 --- a/app/backend/src/user/entities/user.entity.ts +++ b/app/backend/src/user/entities/user.entity.ts @@ -8,6 +8,8 @@ import { BeforeUpdate, OneToMany, Relation, + JoinTable, + ManyToMany, } from 'typeorm'; const SALT_ROUNDS = 10; @@ -38,6 +40,14 @@ export class User { @OneToMany(() => Poll, poll => poll.creator) polls: Relation; + @ManyToMany(type => User, user => user.followings) + @JoinTable() + followers: User[]; + + @ManyToMany(type => User, user => user.followers) + followings: User[]; + + @BeforeInsert() async hashPasswordBeforeInsert() { if (this.password) {