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 { IsEnum, IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
@ -9,12 +10,15 @@ export class InviteUserDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public email: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public jobTitle: string;
|
||||
|
||||
@IsEnum(UserStatusEnum)
|
||||
@IsNotEmpty()
|
||||
public status: UserStatusEnum;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public firstName: string;
|
||||
@ -22,6 +26,10 @@ export class InviteUserDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public lastName: string;
|
||||
|
||||
@IsEnum(RoleType)
|
||||
@IsNotEmpty()
|
||||
public invitedBy: RoleType;
|
||||
}
|
||||
export class InviteUserSpaceDto {
|
||||
@IsString()
|
||||
|
||||
@ -13,6 +13,7 @@ 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';
|
||||
|
||||
@Entity({ name: 'invite-user' })
|
||||
@Unique(['email', 'invitationCode'])
|
||||
@ -69,14 +70,20 @@ export class InviteUserEntity extends AbstractEntity<InviteUserDto> {
|
||||
unique: true,
|
||||
})
|
||||
public invitationCode: string;
|
||||
// Relation with RoleTypeEntity
|
||||
|
||||
@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' }) // Foreign key in InviteUserEntity
|
||||
@JoinColumn({ name: 'user_uuid' })
|
||||
user: UserEntity;
|
||||
@OneToMany(
|
||||
() => InviteUserSpaceEntity,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
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 { AddUserInvitationDto } from '../dtos/add.invite-user.dto';
|
||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||
@ -26,9 +26,12 @@ export class InviteUserController {
|
||||
})
|
||||
async createUserInvitation(
|
||||
@Body() addUserInvitationDto: AddUserInvitationDto,
|
||||
@Req() request: any,
|
||||
): Promise<BaseResponseDto> {
|
||||
const user = request.user;
|
||||
return await this.inviteUserService.createUserInvitation(
|
||||
addUserInvitationDto,
|
||||
user.role.type,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import { generateRandomString } from '@app/common/helper/randomString';
|
||||
import { IsNull, Not } from 'typeorm';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { UserEntity } from '@app/common/modules/user/entities';
|
||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||
|
||||
@Injectable()
|
||||
export class InviteUserService {
|
||||
@ -20,6 +21,7 @@ export class InviteUserService {
|
||||
|
||||
async createUserInvitation(
|
||||
dto: AddUserInvitationDto,
|
||||
roleType: RoleType,
|
||||
): Promise<BaseResponseDto> {
|
||||
const {
|
||||
firstName,
|
||||
@ -62,6 +64,7 @@ export class InviteUserService {
|
||||
roleType: { uuid: roleUuid },
|
||||
status: UserStatusEnum.INVITED,
|
||||
invitationCode,
|
||||
invitedBy: roleType,
|
||||
});
|
||||
|
||||
const invitedUser = await queryRunner.manager.save(inviteUser);
|
||||
|
||||
Reference in New Issue
Block a user