mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 02:36:19 +00:00
community user relation
This commit is contained in:
@ -1,8 +1,16 @@
|
|||||||
import { Column, Entity, ManyToOne, OneToMany, Unique } from 'typeorm';
|
import {
|
||||||
|
Column,
|
||||||
|
Entity,
|
||||||
|
ManyToMany,
|
||||||
|
ManyToOne,
|
||||||
|
OneToMany,
|
||||||
|
Unique,
|
||||||
|
} from 'typeorm';
|
||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
import { CommunityDto } from '../dtos';
|
import { CommunityDto } from '../dtos';
|
||||||
import { RegionEntity } from '../../region/entities';
|
import { RegionEntity } from '../../region/entities';
|
||||||
import { SpaceEntity } from '../../space/entities';
|
import { SpaceEntity } from '../../space/entities';
|
||||||
|
import { UserEntity } from '../../user/entities';
|
||||||
|
|
||||||
@Entity({ name: 'community' })
|
@Entity({ name: 'community' })
|
||||||
@Unique(['name'])
|
@Unique(['name'])
|
||||||
@ -31,4 +39,7 @@ export class CommunityEntity extends AbstractEntity<CommunityDto> {
|
|||||||
|
|
||||||
@OneToMany(() => SpaceEntity, (space) => space.community)
|
@OneToMany(() => SpaceEntity, (space) => space.community)
|
||||||
spaces: SpaceEntity[];
|
spaces: SpaceEntity[];
|
||||||
|
|
||||||
|
@ManyToMany(() => UserEntity, (user) => user.communities)
|
||||||
|
users: UserEntity[];
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ import {
|
|||||||
Column,
|
Column,
|
||||||
DeleteDateColumn,
|
DeleteDateColumn,
|
||||||
Entity,
|
Entity,
|
||||||
|
JoinTable,
|
||||||
|
ManyToMany,
|
||||||
ManyToOne,
|
ManyToOne,
|
||||||
OneToMany,
|
OneToMany,
|
||||||
Unique,
|
Unique,
|
||||||
@ -26,6 +28,7 @@ import { OtpType } from '../../../../src/constants/otp-type.enum';
|
|||||||
import { RoleTypeEntity } from '../../role-type/entities';
|
import { RoleTypeEntity } from '../../role-type/entities';
|
||||||
import { SpaceEntity } from '../../space/entities';
|
import { SpaceEntity } from '../../space/entities';
|
||||||
import { VisitorPasswordEntity } from '../../visitor-password/entities';
|
import { VisitorPasswordEntity } from '../../visitor-password/entities';
|
||||||
|
import { CommunityEntity } from '../../community/entities';
|
||||||
|
|
||||||
@Entity({ name: 'user' })
|
@Entity({ name: 'user' })
|
||||||
export class UserEntity extends AbstractEntity<UserDto> {
|
export class UserEntity extends AbstractEntity<UserDto> {
|
||||||
@ -115,6 +118,15 @@ export class UserEntity extends AbstractEntity<UserDto> {
|
|||||||
(visitorPassword) => visitorPassword.user,
|
(visitorPassword) => visitorPassword.user,
|
||||||
)
|
)
|
||||||
public visitorPasswords: VisitorPasswordEntity[];
|
public visitorPasswords: VisitorPasswordEntity[];
|
||||||
|
|
||||||
|
@ManyToMany(() => CommunityEntity, (community) => community.users)
|
||||||
|
@JoinTable({
|
||||||
|
name: 'user_communities', // Join table to link users and communities
|
||||||
|
joinColumn: { name: 'user_id', referencedColumnName: 'uuid' },
|
||||||
|
inverseJoinColumn: { name: 'community_id', referencedColumnName: 'uuid' },
|
||||||
|
})
|
||||||
|
communities: CommunityEntity[];
|
||||||
|
|
||||||
constructor(partial: Partial<UserEntity>) {
|
constructor(partial: Partial<UserEntity>) {
|
||||||
super();
|
super();
|
||||||
Object.assign(this, partial);
|
Object.assign(this, partial);
|
||||||
|
Reference in New Issue
Block a user