mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 07:07:21 +00:00
132 lines
3.0 KiB
TypeScript
132 lines
3.0 KiB
TypeScript
import {
|
|
Column,
|
|
Entity,
|
|
JoinColumn,
|
|
ManyToOne,
|
|
OneToMany,
|
|
OneToOne,
|
|
Unique,
|
|
} from 'typeorm';
|
|
|
|
import { RoleType } from '@app/common/constants/role.type.enum';
|
|
import { UserStatusEnum } from '@app/common/constants/user-status.enum';
|
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
|
import { ProjectEntity } from '../../project/entities';
|
|
import { RoleTypeEntity } from '../../role-type/entities';
|
|
import { SpaceEntity } from '../../space/entities/space.entity';
|
|
import { UserEntity } from '../../user/entities';
|
|
import { InviteUserDto, InviteUserSpaceDto } from '../dtos';
|
|
|
|
@Entity({ name: 'invite-user' })
|
|
@Unique(['email', 'project'])
|
|
export class InviteUserEntity extends AbstractEntity<InviteUserDto> {
|
|
@Column({
|
|
type: 'uuid',
|
|
default: () => 'gen_random_uuid()',
|
|
nullable: false,
|
|
})
|
|
public uuid: string;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
})
|
|
email: string;
|
|
|
|
@Column({
|
|
nullable: true,
|
|
})
|
|
jobTitle: string;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
enum: Object.values(UserStatusEnum),
|
|
})
|
|
status: string;
|
|
|
|
@Column()
|
|
public firstName: string;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
})
|
|
public lastName: string;
|
|
@Column({
|
|
nullable: true,
|
|
})
|
|
public phoneNumber: string;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
default: true,
|
|
})
|
|
public isActive: boolean;
|
|
@Column({
|
|
nullable: false,
|
|
default: true,
|
|
})
|
|
public isEnabled: boolean;
|
|
@Column({
|
|
nullable: false,
|
|
unique: true,
|
|
})
|
|
public invitationCode: string;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
enum: Object.values(RoleType),
|
|
})
|
|
public invitedBy: string;
|
|
|
|
@ManyToOne(() => RoleTypeEntity, (roleType) => roleType.invitedUsers, {
|
|
nullable: false,
|
|
onDelete: 'CASCADE',
|
|
})
|
|
public roleType: RoleTypeEntity;
|
|
@OneToOne(() => UserEntity, (user) => user.inviteUser, {
|
|
nullable: true,
|
|
onDelete: 'CASCADE',
|
|
})
|
|
@JoinColumn({ name: 'user_uuid' })
|
|
user: UserEntity;
|
|
@OneToMany(
|
|
() => InviteUserSpaceEntity,
|
|
(inviteUserSpace) => inviteUserSpace.inviteUser,
|
|
)
|
|
spaces: InviteUserSpaceEntity[];
|
|
|
|
@ManyToOne(() => ProjectEntity, (project) => project.invitedUsers, {
|
|
nullable: true,
|
|
})
|
|
@JoinColumn({ name: 'project_uuid' })
|
|
public project: ProjectEntity;
|
|
|
|
constructor(partial: Partial<InviteUserEntity>) {
|
|
super();
|
|
Object.assign(this, partial);
|
|
}
|
|
}
|
|
@Entity({ name: 'invite-user-space' })
|
|
@Unique(['inviteUser', 'space'])
|
|
export class InviteUserSpaceEntity extends AbstractEntity<InviteUserSpaceDto> {
|
|
@Column({
|
|
type: 'uuid',
|
|
default: () => 'gen_random_uuid()',
|
|
nullable: false,
|
|
})
|
|
public uuid: string;
|
|
|
|
@ManyToOne(() => InviteUserEntity, (inviteUser) => inviteUser.spaces, {
|
|
onDelete: 'CASCADE',
|
|
})
|
|
@JoinColumn({ name: 'invite_user_uuid' })
|
|
public inviteUser: InviteUserEntity;
|
|
|
|
@ManyToOne(() => SpaceEntity, (space) => space.invitedUsers)
|
|
@JoinColumn({ name: 'space_uuid' })
|
|
public space: SpaceEntity;
|
|
constructor(partial: Partial<InviteUserSpaceEntity>) {
|
|
super();
|
|
Object.assign(this, partial);
|
|
}
|
|
}
|