mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 09:04:55 +00:00
Add permission and role management features
This commit is contained in:
1
src/invite-user/controllers/index.ts
Normal file
1
src/invite-user/controllers/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './invite-user.controller';
|
||||
34
src/invite-user/controllers/invite-user.controller.ts
Normal file
34
src/invite-user/controllers/invite-user.controller.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { InviteUserService } from '../services/invite-user.service';
|
||||
import { Body, Controller, Post, 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';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { PermissionsGuard } from 'src/guards/permissions.guard';
|
||||
import { Permissions } from 'src/decorators/permissions.decorator';
|
||||
|
||||
@ApiTags('Invite User Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
path: ControllerRoute.INVITE_USER.ROUTE,
|
||||
})
|
||||
export class InviteUserController {
|
||||
constructor(private readonly inviteUserService: InviteUserService) {}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard)
|
||||
@Permissions('USER_ADD')
|
||||
@Post()
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.INVITE_USER.ACTIONS.CREATE_USER_INVITATION_SUMMARY,
|
||||
description:
|
||||
ControllerRoute.INVITE_USER.ACTIONS.CREATE_USER_INVITATION_DESCRIPTION,
|
||||
})
|
||||
async createUserInvitation(
|
||||
@Body() addUserInvitationDto: AddUserInvitationDto,
|
||||
): Promise<BaseResponseDto> {
|
||||
return await this.inviteUserService.createUserInvitation(
|
||||
addUserInvitationDto,
|
||||
);
|
||||
}
|
||||
}
|
||||
75
src/invite-user/dtos/add.invite-user.dto.ts
Normal file
75
src/invite-user/dtos/add.invite-user.dto.ts
Normal file
@ -0,0 +1,75 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import {
|
||||
ArrayMinSize,
|
||||
IsArray,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString,
|
||||
} from 'class-validator';
|
||||
|
||||
export class AddUserInvitationDto {
|
||||
@ApiProperty({
|
||||
description: 'The first name of the user',
|
||||
example: 'John',
|
||||
required: true,
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public firstName: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'The last name of the user',
|
||||
example: 'Doe',
|
||||
required: true,
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public lastName: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'The email of the user',
|
||||
example: 'OqM9A@example.com',
|
||||
required: true,
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public email: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'The job title of the user',
|
||||
example: 'Software Engineer',
|
||||
required: true,
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public jobTitle: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'The phone number of the user',
|
||||
example: '+1234567890',
|
||||
required: true,
|
||||
})
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
public phoneNumber?: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'The role uuid of the user',
|
||||
example: 'd290f1ee-6c54-4b01-90e6-d701748f0851',
|
||||
required: true,
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public roleUuid: string;
|
||||
@ApiProperty({
|
||||
description: 'The array of space UUIDs (at least one required)',
|
||||
example: ['b5f3c9d2-58b7-4377-b3f7-60acb711d5d9'],
|
||||
required: true,
|
||||
})
|
||||
@IsArray()
|
||||
@ArrayMinSize(1)
|
||||
public spaceUuids: string[];
|
||||
constructor(dto: Partial<AddUserInvitationDto>) {
|
||||
Object.assign(this, dto);
|
||||
}
|
||||
}
|
||||
1
src/invite-user/dtos/index.ts
Normal file
1
src/invite-user/dtos/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './add.invite-user.dto';
|
||||
23
src/invite-user/invite-user.module.ts
Normal file
23
src/invite-user/invite-user.module.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { InviteUserService } from './services/invite-user.service';
|
||||
import { InviteUserController } from './controllers/invite-user.controller';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import {
|
||||
InviteUserRepository,
|
||||
InviteUserSpaceRepository,
|
||||
} from '@app/common/modules/Invite-user/repositories';
|
||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||
import { InviteUserRepositoryModule } from '@app/common/modules/Invite-user/Invite-user.repository.module';
|
||||
|
||||
@Module({
|
||||
imports: [ConfigModule, InviteUserRepositoryModule],
|
||||
controllers: [InviteUserController],
|
||||
providers: [
|
||||
InviteUserService,
|
||||
InviteUserRepository,
|
||||
UserRepository,
|
||||
InviteUserSpaceRepository,
|
||||
],
|
||||
exports: [InviteUserService],
|
||||
})
|
||||
export class InviteUserModule {}
|
||||
1
src/invite-user/services/index.ts
Normal file
1
src/invite-user/services/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './invite-user.service';
|
||||
Reference in New Issue
Block a user