mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
235 lines
5.5 KiB
TypeScript
235 lines
5.5 KiB
TypeScript
import {
|
|
Column,
|
|
DeleteDateColumn,
|
|
Entity,
|
|
JoinColumn,
|
|
ManyToOne,
|
|
OneToMany,
|
|
OneToOne,
|
|
Unique,
|
|
} from 'typeorm';
|
|
import {
|
|
UserDto,
|
|
UserNotificationDto,
|
|
UserOtpDto,
|
|
UserSpaceDto,
|
|
} from '../dtos';
|
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
|
import {
|
|
DeviceNotificationEntity,
|
|
DeviceUserPermissionEntity,
|
|
} from '../../device/entities';
|
|
import { defaultProfilePicture } from '@app/common/constants/default.profile.picture';
|
|
import { RegionEntity } from '../../region/entities';
|
|
import { TimeZoneEntity } from '../../timezone/entities';
|
|
import { OtpType } from '../../../../src/constants/otp-type.enum';
|
|
import { RoleTypeEntity } from '../../role-type/entities';
|
|
import { VisitorPasswordEntity } from '../../visitor-password/entities';
|
|
import { InviteUserEntity } from '../../Invite-user/entities';
|
|
import { ProjectEntity } from '../../project/entities';
|
|
import { SpaceEntity } from '../../space/entities/space.entity';
|
|
import { ClientEntity } from '../../client/entities';
|
|
|
|
@Entity({ name: 'user' })
|
|
export class UserEntity extends AbstractEntity<UserDto> {
|
|
@Column({
|
|
type: 'uuid',
|
|
default: () => 'gen_random_uuid()', // Use gen_random_uuid() for default value
|
|
nullable: false,
|
|
})
|
|
public uuid: string;
|
|
|
|
@Column({
|
|
nullable: true,
|
|
type: 'text',
|
|
default: defaultProfilePicture,
|
|
})
|
|
public profilePicture: string;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
unique: true,
|
|
})
|
|
email: string;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
})
|
|
public password: string;
|
|
|
|
@Column()
|
|
public firstName: string;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
})
|
|
public lastName: string;
|
|
|
|
@Column({
|
|
nullable: true,
|
|
})
|
|
public refreshToken: string;
|
|
|
|
@Column({
|
|
nullable: true,
|
|
default: false,
|
|
})
|
|
public isUserVerified: boolean;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
default: true,
|
|
})
|
|
public isActive: boolean;
|
|
|
|
@Column({ default: false })
|
|
hasAcceptedWebAgreement: boolean;
|
|
|
|
@Column({ default: false })
|
|
hasAcceptedAppAgreement: boolean;
|
|
|
|
@Column({ type: 'timestamp', nullable: true })
|
|
webAgreementAcceptedAt: Date;
|
|
|
|
@Column({ type: 'timestamp', nullable: true })
|
|
appAgreementAcceptedAt: Date;
|
|
|
|
@OneToMany(() => UserSpaceEntity, (userSpace) => userSpace.user)
|
|
userSpaces: UserSpaceEntity[];
|
|
|
|
@OneToMany(
|
|
() => UserNotificationEntity,
|
|
(userNotification) => userNotification.user,
|
|
)
|
|
userNotification: UserNotificationEntity[];
|
|
@OneToMany(
|
|
() => DeviceUserPermissionEntity,
|
|
(userPermission) => userPermission.user,
|
|
)
|
|
userPermission: DeviceUserPermissionEntity[];
|
|
@OneToMany(
|
|
() => DeviceNotificationEntity,
|
|
(deviceUserNotification) => deviceUserNotification.user,
|
|
)
|
|
deviceUserNotification: DeviceNotificationEntity[];
|
|
|
|
@ManyToOne(() => RegionEntity, (region) => region.users, { nullable: true })
|
|
region: RegionEntity;
|
|
@ManyToOne(() => TimeZoneEntity, (timezone) => timezone.users, {
|
|
nullable: true,
|
|
})
|
|
timezone: TimeZoneEntity;
|
|
@OneToMany(
|
|
() => VisitorPasswordEntity,
|
|
(visitorPassword) => visitorPassword.user,
|
|
)
|
|
public visitorPasswords: VisitorPasswordEntity[];
|
|
|
|
@ManyToOne(() => RoleTypeEntity, (roleType) => roleType.users, {
|
|
nullable: false,
|
|
})
|
|
public roleType: RoleTypeEntity;
|
|
@OneToOne(() => InviteUserEntity, (inviteUser) => inviteUser.user, {
|
|
nullable: true,
|
|
})
|
|
@JoinColumn({ name: 'invite_user_uuid' })
|
|
inviteUser: InviteUserEntity;
|
|
|
|
@ManyToOne(() => ProjectEntity, (project) => project.users, {
|
|
nullable: true,
|
|
})
|
|
@JoinColumn({ name: 'project_uuid' })
|
|
public project: ProjectEntity;
|
|
|
|
@ManyToOne(() => ClientEntity, (client) => client.users, {
|
|
nullable: true,
|
|
})
|
|
@JoinColumn({ name: 'client_uuid' })
|
|
public client: ClientEntity;
|
|
|
|
constructor(partial: Partial<UserEntity>) {
|
|
super();
|
|
Object.assign(this, partial);
|
|
}
|
|
}
|
|
|
|
@Entity({ name: 'user-notification' })
|
|
@Unique(['user', 'subscriptionUuid'])
|
|
export class UserNotificationEntity extends AbstractEntity<UserNotificationDto> {
|
|
@ManyToOne(() => UserEntity, (user) => user.roleType, {
|
|
nullable: false,
|
|
})
|
|
user: UserEntity;
|
|
@Column({
|
|
nullable: false,
|
|
})
|
|
subscriptionUuid: string;
|
|
|
|
@Column({
|
|
nullable: false,
|
|
default: true,
|
|
})
|
|
active: boolean;
|
|
constructor(partial: Partial<UserNotificationEntity>) {
|
|
super();
|
|
Object.assign(this, partial);
|
|
}
|
|
}
|
|
|
|
@Entity({ name: 'user-otp' })
|
|
export class UserOtpEntity extends AbstractEntity<UserOtpDto> {
|
|
@Column({
|
|
type: 'uuid',
|
|
default: () => 'gen_random_uuid()',
|
|
nullable: false,
|
|
})
|
|
public uuid: string;
|
|
|
|
@Column({ nullable: false })
|
|
email: string;
|
|
|
|
@Column({ nullable: false })
|
|
otpCode: string;
|
|
|
|
@Column({ nullable: false })
|
|
expiryTime: Date;
|
|
|
|
@Column({
|
|
type: 'enum',
|
|
enum: Object.values(OtpType),
|
|
})
|
|
type: OtpType;
|
|
|
|
@DeleteDateColumn({ nullable: true })
|
|
deletedAt?: Date;
|
|
|
|
constructor(partial: Partial<UserOtpEntity>) {
|
|
super();
|
|
Object.assign(this, partial);
|
|
}
|
|
}
|
|
|
|
@Entity({ name: 'user-space' })
|
|
@Unique(['user', 'space'])
|
|
export class UserSpaceEntity extends AbstractEntity<UserSpaceDto> {
|
|
@Column({
|
|
type: 'uuid',
|
|
default: () => 'gen_random_uuid()', // Use gen_random_uuid() for default value
|
|
nullable: false,
|
|
})
|
|
public uuid: string;
|
|
|
|
@ManyToOne(() => UserEntity, (user) => user.userSpaces, { nullable: false })
|
|
user: UserEntity;
|
|
|
|
@ManyToOne(() => SpaceEntity, (space) => space.userSpaces, {
|
|
nullable: false,
|
|
})
|
|
space: SpaceEntity;
|
|
|
|
constructor(partial: Partial<UserSpaceEntity>) {
|
|
super();
|
|
Object.assign(this, partial);
|
|
}
|
|
}
|