mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 18:56:22 +00:00
Merge branch 'dev' of https://github.com/SyncrowIOT/backend into feat/link-space-to-space-model
This commit is contained in:
@ -0,0 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { InviteUserEntity, InviteUserSpaceEntity } from './entities';
|
||||
|
||||
@Module({
|
||||
providers: [],
|
||||
exports: [],
|
||||
controllers: [],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([InviteUserEntity, InviteUserSpaceEntity]),
|
||||
],
|
||||
})
|
||||
export class InviteUserRepositoryModule {}
|
50
libs/common/src/modules/Invite-user/dtos/Invite-user.dto.ts
Normal file
50
libs/common/src/modules/Invite-user/dtos/Invite-user.dto.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||
import { UserStatusEnum } from '@app/common/constants/user-status.enum';
|
||||
import { IsEnum, IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class InviteUserDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public email: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public jobTitle: string;
|
||||
|
||||
@IsEnum(UserStatusEnum)
|
||||
@IsNotEmpty()
|
||||
public status: UserStatusEnum;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public firstName: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public lastName: string;
|
||||
|
||||
@IsEnum(RoleType)
|
||||
@IsNotEmpty()
|
||||
public invitedBy: RoleType;
|
||||
}
|
||||
export class InviteUserSpaceDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public inviteUserUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public spaceUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public invitationCode: string;
|
||||
}
|
1
libs/common/src/modules/Invite-user/dtos/index.ts
Normal file
1
libs/common/src/modules/Invite-user/dtos/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './Invite-user.dto';
|
@ -0,0 +1,120 @@
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
Unique,
|
||||
} from 'typeorm';
|
||||
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { RoleTypeEntity } from '../../role-type/entities';
|
||||
import { UserStatusEnum } from '@app/common/constants/user-status.enum';
|
||||
import { UserEntity } from '../../user/entities';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||
import { InviteUserDto, InviteUserSpaceDto } from '../dtos';
|
||||
|
||||
@Entity({ name: 'invite-user' })
|
||||
@Unique(['email', 'invitationCode'])
|
||||
export class InviteUserEntity extends AbstractEntity<InviteUserDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
unique: true,
|
||||
})
|
||||
email: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
jobTitle: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
enum: Object.values(UserStatusEnum),
|
||||
})
|
||||
status: string;
|
||||
|
||||
@Column()
|
||||
public firstName: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
public lastName: string;
|
||||
@Column({
|
||||
nullable: false,
|
||||
})
|
||||
public phoneNumber: string;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
default: true,
|
||||
})
|
||||
public isEnabled: boolean;
|
||||
|
||||
@Column({
|
||||
nullable: false,
|
||||
default: true,
|
||||
})
|
||||
public isActive: 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 })
|
||||
@JoinColumn({ name: 'user_uuid' })
|
||||
user: UserEntity;
|
||||
@OneToMany(
|
||||
() => InviteUserSpaceEntity,
|
||||
(inviteUserSpace) => inviteUserSpace.inviteUser,
|
||||
)
|
||||
spaces: InviteUserSpaceEntity[];
|
||||
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)
|
||||
@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);
|
||||
}
|
||||
}
|
1
libs/common/src/modules/Invite-user/entities/index.ts
Normal file
1
libs/common/src/modules/Invite-user/entities/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './Invite-user.entity';
|
1
libs/common/src/modules/Invite-user/index.ts
Normal file
1
libs/common/src/modules/Invite-user/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './Invite-user.repository.module';
|
@ -0,0 +1 @@
|
||||
export * from './invite-user.repository';
|
@ -0,0 +1,16 @@
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InviteUserEntity, InviteUserSpaceEntity } from '../entities';
|
||||
|
||||
@Injectable()
|
||||
export class InviteUserRepository extends Repository<InviteUserEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(InviteUserEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
@Injectable()
|
||||
export class InviteUserSpaceRepository extends Repository<InviteUserSpaceEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(InviteUserSpaceEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { ProjectDto } from '../dtos';
|
||||
import { CommunityEntity } from '../../community/entities';
|
||||
import { SpaceModelEntity } from '../../space-model';
|
||||
import { UserEntity } from '../../user/entities';
|
||||
|
||||
@Entity({ name: 'project' })
|
||||
@Unique(['name'])
|
||||
@ -28,6 +29,9 @@ export class ProjectEntity extends AbstractEntity<ProjectDto> {
|
||||
@OneToMany(() => CommunityEntity, (community) => community.project)
|
||||
communities: CommunityEntity[];
|
||||
|
||||
@OneToMany(() => UserEntity, (user) => user.project)
|
||||
public users: UserEntity[];
|
||||
|
||||
constructor(partial: Partial<ProjectEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
|
@ -2,7 +2,8 @@ import { Column, Entity, OneToMany, Unique } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { RoleTypeDto } from '../dtos/role.type.dto';
|
||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||
import { UserRoleEntity } from '../../user/entities';
|
||||
import { UserEntity } from '../../user/entities';
|
||||
import { InviteUserEntity } from '../../Invite-user/entities';
|
||||
|
||||
@Entity({ name: 'role-type' })
|
||||
@Unique(['type'])
|
||||
@ -12,10 +13,14 @@ export class RoleTypeEntity extends AbstractEntity<RoleTypeDto> {
|
||||
enum: Object.values(RoleType),
|
||||
})
|
||||
type: string;
|
||||
@OneToMany(() => UserRoleEntity, (role) => role.roleType, {
|
||||
@OneToMany(() => UserEntity, (inviteUser) => inviteUser.roleType, {
|
||||
nullable: true,
|
||||
})
|
||||
roles: UserRoleEntity[];
|
||||
users: UserEntity[];
|
||||
@OneToMany(() => InviteUserEntity, (inviteUser) => inviteUser.roleType, {
|
||||
nullable: true,
|
||||
})
|
||||
invitedUsers: InviteUserEntity[];
|
||||
constructor(partial: Partial<RoleTypeEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
|
@ -16,6 +16,7 @@ import { SpaceLinkEntity } from './space-link.entity';
|
||||
import { SpaceProductEntity } from './space-product.entity';
|
||||
import { SceneEntity } from '../../scene/entities';
|
||||
import { SpaceModelEntity } from '../../space-model';
|
||||
import { InviteUserSpaceEntity } from '../../Invite-user/entities';
|
||||
|
||||
@Entity({ name: 'space' })
|
||||
@Unique(['invitationCode'])
|
||||
@ -103,6 +104,11 @@ export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
||||
@JoinColumn({ name: 'space_model_uuid' })
|
||||
spaceModel?: SpaceModelEntity;
|
||||
|
||||
@OneToMany(
|
||||
() => InviteUserSpaceEntity,
|
||||
(inviteUserSpace) => inviteUserSpace.space,
|
||||
)
|
||||
invitedUsers: InviteUserSpaceEntity[];
|
||||
constructor(partial: Partial<SpaceEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
|
@ -58,20 +58,6 @@ export class UserOtpDto {
|
||||
public expiryTime: string;
|
||||
}
|
||||
|
||||
export class UserRoleDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public userUuid: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public roleTypeUuid: string;
|
||||
}
|
||||
|
||||
export class UserSpaceDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
|
@ -2,15 +2,16 @@ import {
|
||||
Column,
|
||||
DeleteDateColumn,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
OneToOne,
|
||||
Unique,
|
||||
} from 'typeorm';
|
||||
import {
|
||||
UserDto,
|
||||
UserNotificationDto,
|
||||
UserOtpDto,
|
||||
UserRoleDto,
|
||||
UserSpaceDto,
|
||||
} from '../dtos';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
@ -26,6 +27,8 @@ import { OtpType } from '../../../../src/constants/otp-type.enum';
|
||||
import { RoleTypeEntity } from '../../role-type/entities';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
import { VisitorPasswordEntity } from '../../visitor-password/entities';
|
||||
import { InviteUserEntity } from '../../Invite-user/entities';
|
||||
import { ProjectEntity } from '../../project/entities';
|
||||
|
||||
@Entity({ name: 'user' })
|
||||
export class UserEntity extends AbstractEntity<UserDto> {
|
||||
@ -100,10 +103,7 @@ export class UserEntity extends AbstractEntity<UserDto> {
|
||||
(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, {
|
||||
@ -116,6 +116,21 @@ export class UserEntity extends AbstractEntity<UserDto> {
|
||||
)
|
||||
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;
|
||||
constructor(partial: Partial<UserEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
@ -125,7 +140,7 @@ export class UserEntity extends AbstractEntity<UserDto> {
|
||||
@Entity({ name: 'user-notification' })
|
||||
@Unique(['user', 'subscriptionUuid'])
|
||||
export class UserNotificationEntity extends AbstractEntity<UserNotificationDto> {
|
||||
@ManyToOne(() => UserEntity, (user) => user.roles, {
|
||||
@ManyToOne(() => UserEntity, (user) => user.roleType, {
|
||||
nullable: false,
|
||||
})
|
||||
user: UserEntity;
|
||||
@ -178,25 +193,6 @@ export class UserOtpEntity extends AbstractEntity<UserOtpDto> {
|
||||
}
|
||||
}
|
||||
|
||||
@Entity({ name: 'user-role' })
|
||||
@Unique(['user', 'roleType'])
|
||||
export class UserRoleEntity extends AbstractEntity<UserRoleDto> {
|
||||
@ManyToOne(() => UserEntity, (user) => user.roles, {
|
||||
nullable: false,
|
||||
})
|
||||
user: UserEntity;
|
||||
|
||||
@ManyToOne(() => RoleTypeEntity, (roleType) => roleType.roles, {
|
||||
nullable: false,
|
||||
})
|
||||
roleType: RoleTypeEntity;
|
||||
|
||||
constructor(partial: Partial<UserRoleEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@Entity({ name: 'user-space' })
|
||||
@Unique(['user', 'space'])
|
||||
export class UserSpaceEntity extends AbstractEntity<UserSpaceDto> {
|
||||
|
@ -4,7 +4,6 @@ import {
|
||||
UserEntity,
|
||||
UserNotificationEntity,
|
||||
UserOtpEntity,
|
||||
UserRoleEntity,
|
||||
UserSpaceEntity,
|
||||
} from '../entities/';
|
||||
|
||||
@ -29,13 +28,6 @@ export class UserOtpRepository extends Repository<UserOtpEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class UserRoleRepository extends Repository<UserRoleEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
super(UserRoleEntity, dataSource.createEntityManager());
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class UserSpaceRepository extends Repository<UserSpaceEntity> {
|
||||
constructor(private dataSource: DataSource) {
|
||||
|
@ -4,7 +4,6 @@ import {
|
||||
UserEntity,
|
||||
UserNotificationEntity,
|
||||
UserOtpEntity,
|
||||
UserRoleEntity,
|
||||
UserSpaceEntity,
|
||||
} from './entities';
|
||||
|
||||
@ -17,7 +16,6 @@ import {
|
||||
UserEntity,
|
||||
UserNotificationEntity,
|
||||
UserOtpEntity,
|
||||
UserRoleEntity,
|
||||
UserSpaceEntity,
|
||||
]),
|
||||
],
|
||||
|
Reference in New Issue
Block a user