mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 10:44:55 +00:00
Add invitedBy field to InviteUserDto and InviteUserEntity
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||||
import { UserStatusEnum } from '@app/common/constants/user-status.enum';
|
import { UserStatusEnum } from '@app/common/constants/user-status.enum';
|
||||||
import { IsEnum, IsNotEmpty, IsString } from 'class-validator';
|
import { IsEnum, IsNotEmpty, IsString } from 'class-validator';
|
||||||
|
|
||||||
@ -9,12 +10,15 @@ export class InviteUserDto {
|
|||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
public email: string;
|
public email: string;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
public jobTitle: string;
|
public jobTitle: string;
|
||||||
|
|
||||||
@IsEnum(UserStatusEnum)
|
@IsEnum(UserStatusEnum)
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
public status: UserStatusEnum;
|
public status: UserStatusEnum;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
public firstName: string;
|
public firstName: string;
|
||||||
@ -22,6 +26,10 @@ export class InviteUserDto {
|
|||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
public lastName: string;
|
public lastName: string;
|
||||||
|
|
||||||
|
@IsEnum(RoleType)
|
||||||
|
@IsNotEmpty()
|
||||||
|
public invitedBy: RoleType;
|
||||||
}
|
}
|
||||||
export class InviteUserSpaceDto {
|
export class InviteUserSpaceDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import { RoleTypeEntity } from '../../role-type/entities';
|
|||||||
import { UserStatusEnum } from '@app/common/constants/user-status.enum';
|
import { UserStatusEnum } from '@app/common/constants/user-status.enum';
|
||||||
import { UserEntity } from '../../user/entities';
|
import { UserEntity } from '../../user/entities';
|
||||||
import { SpaceEntity } from '../../space/entities';
|
import { SpaceEntity } from '../../space/entities';
|
||||||
|
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||||
|
|
||||||
@Entity({ name: 'invite-user' })
|
@Entity({ name: 'invite-user' })
|
||||||
@Unique(['email', 'invitationCode'])
|
@Unique(['email', 'invitationCode'])
|
||||||
@ -69,14 +70,20 @@ export class InviteUserEntity extends AbstractEntity<InviteUserDto> {
|
|||||||
unique: true,
|
unique: true,
|
||||||
})
|
})
|
||||||
public invitationCode: string;
|
public invitationCode: string;
|
||||||
// Relation with RoleTypeEntity
|
|
||||||
|
@Column({
|
||||||
|
nullable: false,
|
||||||
|
enum: Object.values(RoleType),
|
||||||
|
})
|
||||||
|
public invitedBy: string;
|
||||||
|
|
||||||
@ManyToOne(() => RoleTypeEntity, (roleType) => roleType.invitedUsers, {
|
@ManyToOne(() => RoleTypeEntity, (roleType) => roleType.invitedUsers, {
|
||||||
nullable: false,
|
nullable: false,
|
||||||
onDelete: 'CASCADE',
|
onDelete: 'CASCADE',
|
||||||
})
|
})
|
||||||
public roleType: RoleTypeEntity;
|
public roleType: RoleTypeEntity;
|
||||||
@OneToOne(() => UserEntity, (user) => user.inviteUser, { nullable: true })
|
@OneToOne(() => UserEntity, (user) => user.inviteUser, { nullable: true })
|
||||||
@JoinColumn({ name: 'user_uuid' }) // Foreign key in InviteUserEntity
|
@JoinColumn({ name: 'user_uuid' })
|
||||||
user: UserEntity;
|
user: UserEntity;
|
||||||
@OneToMany(
|
@OneToMany(
|
||||||
() => InviteUserSpaceEntity,
|
() => InviteUserSpaceEntity,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { InviteUserService } from '../services/invite-user.service';
|
import { InviteUserService } from '../services/invite-user.service';
|
||||||
import { Body, Controller, Post, UseGuards } from '@nestjs/common';
|
import { Body, Controller, Post, Req, UseGuards } from '@nestjs/common';
|
||||||
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||||
import { AddUserInvitationDto } from '../dtos/add.invite-user.dto';
|
import { AddUserInvitationDto } from '../dtos/add.invite-user.dto';
|
||||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||||
@ -26,9 +26,12 @@ export class InviteUserController {
|
|||||||
})
|
})
|
||||||
async createUserInvitation(
|
async createUserInvitation(
|
||||||
@Body() addUserInvitationDto: AddUserInvitationDto,
|
@Body() addUserInvitationDto: AddUserInvitationDto,
|
||||||
|
@Req() request: any,
|
||||||
): Promise<BaseResponseDto> {
|
): Promise<BaseResponseDto> {
|
||||||
|
const user = request.user;
|
||||||
return await this.inviteUserService.createUserInvitation(
|
return await this.inviteUserService.createUserInvitation(
|
||||||
addUserInvitationDto,
|
addUserInvitationDto,
|
||||||
|
user.role.type,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import { generateRandomString } from '@app/common/helper/randomString';
|
|||||||
import { IsNull, Not } from 'typeorm';
|
import { IsNull, Not } from 'typeorm';
|
||||||
import { DataSource } from 'typeorm';
|
import { DataSource } from 'typeorm';
|
||||||
import { UserEntity } from '@app/common/modules/user/entities';
|
import { UserEntity } from '@app/common/modules/user/entities';
|
||||||
|
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class InviteUserService {
|
export class InviteUserService {
|
||||||
@ -20,6 +21,7 @@ export class InviteUserService {
|
|||||||
|
|
||||||
async createUserInvitation(
|
async createUserInvitation(
|
||||||
dto: AddUserInvitationDto,
|
dto: AddUserInvitationDto,
|
||||||
|
roleType: RoleType,
|
||||||
): Promise<BaseResponseDto> {
|
): Promise<BaseResponseDto> {
|
||||||
const {
|
const {
|
||||||
firstName,
|
firstName,
|
||||||
@ -62,6 +64,7 @@ export class InviteUserService {
|
|||||||
roleType: { uuid: roleUuid },
|
roleType: { uuid: roleUuid },
|
||||||
status: UserStatusEnum.INVITED,
|
status: UserStatusEnum.INVITED,
|
||||||
invitationCode,
|
invitationCode,
|
||||||
|
invitedBy: roleType,
|
||||||
});
|
});
|
||||||
|
|
||||||
const invitedUser = await queryRunner.manager.save(inviteUser);
|
const invitedUser = await queryRunner.manager.save(inviteUser);
|
||||||
|
|||||||
Reference in New Issue
Block a user