mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-14 18:05:48 +00:00
102 lines
2.7 KiB
TypeScript
102 lines
2.7 KiB
TypeScript
import { DeviceUserPermissionEntity } from '../../device-user-permission/entities/device.user.permission.entity';
|
|
import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
|
|
import { UserDto } from '../dtos';
|
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
|
import { UserSpaceEntity } from '../../user-space/entities';
|
|
import { UserRoleEntity } from '../../user-role/entities';
|
|
import { DeviceNotificationEntity } from '../../device-notification/entities';
|
|
import { UserNotificationEntity } from '../../user-notification/entities';
|
|
import { DeviceEntity } from '../../device/entities';
|
|
import { defaultProfilePicture } from '@app/common/constants/default.profile.picture';
|
|
import { RegionEntity } from '../../region/entities';
|
|
import { TimeZoneEntity } from '../../timezone/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;
|
|
|
|
@OneToMany(() => UserSpaceEntity, (userSpace) => userSpace.user)
|
|
userSpaces: UserSpaceEntity[];
|
|
|
|
@OneToMany(() => DeviceEntity, (userDevice) => userDevice.user)
|
|
userDevice: DeviceEntity[];
|
|
|
|
@OneToMany(
|
|
() => UserNotificationEntity,
|
|
(userNotification) => userNotification.user,
|
|
)
|
|
userNotification: UserNotificationEntity[];
|
|
@OneToMany(
|
|
() => DeviceUserPermissionEntity,
|
|
(userPermission) => userPermission.user,
|
|
)
|
|
userPermission: DeviceUserPermissionEntity[];
|
|
@OneToMany(
|
|
() => DeviceNotificationEntity,
|
|
(deviceUserNotification) => deviceUserNotification.user,
|
|
)
|
|
deviceUserNotification: DeviceNotificationEntity[];
|
|
@OneToMany(() => UserRoleEntity, (role) => role.user, {
|
|
nullable: true,
|
|
})
|
|
roles: UserRoleEntity[];
|
|
@ManyToOne(() => RegionEntity, (region) => region.users, { nullable: true })
|
|
region: RegionEntity;
|
|
@ManyToOne(() => TimeZoneEntity, (timezone) => timezone.users, {
|
|
nullable: true,
|
|
})
|
|
timezone: TimeZoneEntity;
|
|
constructor(partial: Partial<UserEntity>) {
|
|
super();
|
|
Object.assign(this, partial);
|
|
}
|
|
}
|