Skip to content

Commit

Permalink
fix: validation on pagination (#433)
Browse files Browse the repository at this point in the history
* fix:validation issue for pagination

Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com>

* fix:validation issue for pagination

Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com>

* fix:sonacloud issues

Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com>

* refactor:get invitations

Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com>

* refactor:excluded delete org api

Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com>

* refactor:delete org invitations api

Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com>

* fix:pagination validation

Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com>

* changes in interface files

Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com>

---------

Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com>
Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>
  • Loading branch information
pranalidhanavade authored and KulkarniShashank committed Sep 11, 2024
1 parent bd0d6f9 commit ff4e93f
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 158 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiExtraModels, ApiProperty } from '@nestjs/swagger';
import { IsArray, IsEmail, IsNotEmpty, IsString, ValidateNested } from 'class-validator';
import { IsArray, IsEmail, IsNotEmpty, IsString, IsUUID, ValidateNested } from 'class-validator';
import { Transform, Type } from 'class-transformer';
import { trim } from '@credebl/common/cast.helper';

Expand All @@ -16,6 +16,7 @@ export class SendInvitationDto {
@ApiProperty({ example: [2, 1, 3] })
@IsNotEmpty({ message: 'Please provide valid orgRoleId' })
@IsArray()
@IsUUID('4', { each: true, message: 'Invalid format of orgRoleId' })
orgRoleId: string[];

}
Expand Down
14 changes: 9 additions & 5 deletions apps/api-gateway/src/organization/dtos/update-user-roles.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsArray, IsNotEmpty} from 'class-validator';
import { ArrayNotEmpty, IsArray, IsNotEmpty, IsUUID, MinLength} from 'class-validator';

import { ApiProperty } from '@nestjs/swagger';

Expand All @@ -8,10 +8,14 @@ export class UpdateUserRolesDto {
userId: string;

@ApiProperty({
example: [2, 1, 3]
example: ['2', '1', '3']
})

// @IsNotEmpty()
@IsArray()
@IsNotEmpty({ message: 'orgRoleId is required' })
@ArrayNotEmpty()
@MinLength(0, {each: true})
@IsNotEmpty({each: true})
@IsUUID('4', { each: true, message: 'Invalid format of orgRoleId' })
orgRoleId: string[];

}
}
34 changes: 19 additions & 15 deletions apps/api-gateway/src/organization/organization.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ import { OrgRolesGuard } from '../authz/guards/org-roles.guard';
import { Roles } from '../authz/decorators/roles.decorator';
import { OrgRoles } from 'libs/org-roles/enums';
import { UpdateUserRolesDto } from './dtos/update-user-roles.dto';
import { GetAllOrganizationsDto } from './dtos/get-all-organizations.dto';
import { GetAllSentInvitationsDto } from './dtos/get-all-sent-invitations.dto';
import { UpdateOrganizationDto } from './dtos/update-organization-dto';
import { CustomExceptionFilter } from 'apps/api-gateway/common/exception-handler';
import { IUserRequestInterface } from '../interfaces/IUserRequestInterface';
import { GetAllUsersDto } from '../user/dto/get-all-users.dto';
import { ImageServiceService } from '@credebl/image-service';
import { PaginationDto } from '@credebl/common/dtos/pagination.dto';

@UseFilters(CustomExceptionFilter)
@Controller('orgs')
Expand Down Expand Up @@ -79,9 +77,9 @@ export class OrganizationController {
type: String,
required: false
})
async get(@Query() getAllUsersDto: GetAllOrganizationsDto, @Res() res: Response): Promise<Response> {
async get(@Query() paginationDto: PaginationDto, @Res() res: Response): Promise<Response> {

const users = await this.organizationService.getPublicOrganizations(getAllUsersDto);
const users = await this.organizationService.getPublicOrganizations(paginationDto);
const finalResponse: IResponse = {
statusCode: HttpStatus.OK,
message: ResponseMessages.organisation.success.getOrganizations,
Expand Down Expand Up @@ -195,9 +193,9 @@ export class OrganizationController {
required: false
})
@Roles(OrgRoles.OWNER, OrgRoles.SUPER_ADMIN, OrgRoles.ADMIN, OrgRoles.ISSUER, OrgRoles.VERIFIER, OrgRoles.MEMBER)
async getInvitationsByOrgId(@Param('orgId') orgId: string, @Query() getAllInvitationsDto: GetAllSentInvitationsDto, @Res() res: Response): Promise<Response> {
async getInvitationsByOrgId(@Param('orgId') orgId: string, @Query() paginationDto: PaginationDto, @Res() res: Response): Promise<Response> {

const getInvitationById = await this.organizationService.getInvitationsByOrgId(orgId, getAllInvitationsDto);
const getInvitationById = await this.organizationService.getInvitationsByOrgId(orgId, paginationDto);

const finalResponse: IResponse = {
statusCode: HttpStatus.OK,
Expand Down Expand Up @@ -231,9 +229,9 @@ export class OrganizationController {
type: String,
required: false
})
async getOrganizations(@Query() getAllOrgsDto: GetAllOrganizationsDto, @Res() res: Response, @User() reqUser: user): Promise<Response> {
async getOrganizations(@Query() paginationDto: PaginationDto, @Res() res: Response, @User() reqUser: user): Promise<Response> {

const getOrganizations = await this.organizationService.getOrganizations(getAllOrgsDto, reqUser.id);
const getOrganizations = await this.organizationService.getOrganizations(paginationDto, reqUser.id);

const finalResponse: IResponse = {
statusCode: HttpStatus.OK,
Expand Down Expand Up @@ -291,8 +289,8 @@ export class OrganizationController {
type: String,
required: false
})
async getOrganizationUsers(@User() user: IUserRequestInterface, @Query() getAllUsersDto: GetAllUsersDto, @Param('orgId') orgId: string, @Res() res: Response): Promise<Response> {
const users = await this.organizationService.getOrgUsers(orgId, getAllUsersDto);
async getOrganizationUsers(@User() user: IUserRequestInterface, @Query() paginationDto: PaginationDto, @Param('orgId') orgId: string, @Res() res: Response): Promise<Response> {
const users = await this.organizationService.getOrgUsers(orgId, paginationDto);
const finalResponse: IResponse = {
statusCode: HttpStatus.OK,
message: ResponseMessages.user.success.fetchUsers,
Expand Down Expand Up @@ -350,7 +348,7 @@ export class OrganizationController {
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@ApiOperation({ summary: 'Update user roles', description: 'update user roles' })
async updateUserRoles(@Body() updateUserDto: UpdateUserRolesDto, @Param('orgId') orgId: string, @Param('userId') userId: string, @Res() res: Response): Promise<Response> {
async updateUserRoles(@Body() updateUserDto: UpdateUserRolesDto, @Param('orgId') orgId: string, @Param('userId', new ParseUUIDPipe({exceptionFactory: (): Error => { throw new BadRequestException(ResponseMessages.organisation.error.invalidUserId); }})) userId: string, @Res() res: Response): Promise<Response> {

updateUserDto.orgId = orgId;
updateUserDto.userId = userId;
Expand Down Expand Up @@ -387,12 +385,17 @@ export class OrganizationController {
/**
* @returns Boolean
*/
//Todo
@Delete('/:orgId')
@ApiOperation({ summary: 'Delete Organization', description: 'Delete an organization' })
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@ApiExcludeEndpoint()
@ApiResponse({ status: HttpStatus.ACCEPTED, description: 'Success', type: ApiResponseDto })
@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'))
async deleteOrganization(@Param('orgId') orgId: number, @Res() res: Response): Promise<Response> {
async deleteOrganization(
@Param('orgId') orgId: string,
@Res() res: Response
): Promise<Response> {

await this.organizationService.deleteOrganization(orgId);

Expand All @@ -403,6 +406,7 @@ export class OrganizationController {
return res.status(HttpStatus.ACCEPTED).json(finalResponse);
}


@Delete('/:orgId/invitations/:invitationId')
@ApiOperation({ summary: 'Delete organization invitation', description: 'Delete organization invitation' })
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
Expand All @@ -411,7 +415,7 @@ export class OrganizationController {
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
async deleteOrganizationInvitation(
@Param('orgId') orgId: string,
@Param('invitationId') invitationId: string,
@Param('invitationId', new ParseUUIDPipe({exceptionFactory: (): Error => { throw new BadRequestException(ResponseMessages.organisation.error.invalidInvitationId); }})) invitationId: string,
@Res() res: Response
): Promise<Response> {
await this.organizationService.deleteOrganizationInvitation(orgId, invitationId);
Expand Down
30 changes: 14 additions & 16 deletions apps/api-gateway/src/organization/organization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ import { Injectable } from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';
import { BaseService } from 'libs/service/base.service';
import { CreateOrganizationDto } from './dtos/create-organization-dto';
import { GetAllOrganizationsDto } from './dtos/get-all-organizations.dto';
import { GetAllSentInvitationsDto } from './dtos/get-all-sent-invitations.dto';
import { BulkSendInvitationDto } from './dtos/send-invitation.dto';
import { UpdateUserRolesDto } from './dtos/update-user-roles.dto';
import { UpdateOrganizationDto } from './dtos/update-organization-dto';
import { GetAllUsersDto } from '../user/dto/get-all-users.dto';
import { IOrgRoles } from 'libs/org-roles/interfaces/org-roles.interface';
import { organisation } from '@prisma/client';
import { IGetOrgById, IGetOrganization } from 'apps/organization/interfaces/organization.interface';
import { IOrganizationInvitations } from '@credebl/common/interfaces/organizations.interface';
import { IOrganizationInvitations, IOrganizationDashboard} from '@credebl/common/interfaces/organization.interface';
import { IOrgUsers } from 'apps/user/interfaces/user.interface';
import { IOrganizationDashboard } from '@credebl/common/interfaces/organization.interface';
import { PaginationDto } from '@credebl/common/dtos/pagination.dto';

@Injectable()
export class OrganizationService extends BaseService {
Expand Down Expand Up @@ -48,9 +45,9 @@ export class OrganizationService extends BaseService {
* @returns Organizations details
*/

async getOrganizations(getAllOrgsDto: GetAllOrganizationsDto, userId: string): Promise<IGetOrganization> {
const payload = { userId, ...getAllOrgsDto };
const fetchOrgs = await this.sendNats(this.serviceProxy, 'get-organizations', payload);
async getOrganizations(paginationDto: PaginationDto, userId: string): Promise<IGetOrganization> {
const payload = { userId, ...paginationDto };
const fetchOrgs = await this.sendNatsMessage(this.serviceProxy, 'get-organizations', payload);
return fetchOrgs;
}

Expand All @@ -59,9 +56,10 @@ export class OrganizationService extends BaseService {
* @param
* @returns Public organizations list
*/
async getPublicOrganizations(getAllOrgsDto: GetAllOrganizationsDto): Promise<IGetOrganization> {
const payload = { ...getAllOrgsDto };
return this.sendNats(this.serviceProxy, 'get-public-organizations', payload);
async getPublicOrganizations(paginationDto: PaginationDto): Promise<IGetOrganization> {
const payload = { ...paginationDto };
const PublicOrg = this.sendNatsMessage(this.serviceProxy, 'get-public-organizations', payload);
return PublicOrg;
}

async getPublicProfile(orgSlug: string): Promise<IGetOrgById> {
Expand Down Expand Up @@ -90,9 +88,9 @@ export class OrganizationService extends BaseService {
*/
async getInvitationsByOrgId(
orgId: string,
getAllInvitationsDto: GetAllSentInvitationsDto
pagination: PaginationDto
): Promise<IOrganizationInvitations> {
const { pageNumber, pageSize, search } = getAllInvitationsDto;
const { pageNumber, pageSize, search } = pagination;
const payload = { orgId, pageNumber, pageSize, search };
return this.sendNats(this.serviceProxy, 'get-invitations-by-orgId', payload);
}
Expand Down Expand Up @@ -136,9 +134,9 @@ export class OrganizationService extends BaseService {

async getOrgUsers(
orgId: string,
getAllUsersDto: GetAllUsersDto
paginationDto: PaginationDto
): Promise<IOrgUsers> {
const { pageNumber, pageSize, search } = getAllUsersDto;
const { pageNumber, pageSize, search } = paginationDto;
const payload = { orgId, pageNumber, pageSize, search };

return this.sendNats(this.serviceProxy, 'fetch-organization-user', payload);
Expand All @@ -153,7 +151,7 @@ export class OrganizationService extends BaseService {
}

async deleteOrganization(
orgId: number
orgId: string
): Promise<boolean> {
const payload = { orgId };

Expand Down
25 changes: 4 additions & 21 deletions apps/api-gateway/src/user/dto/get-all-invitations.dto.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
import { IsOptional, IsString } from 'class-validator';
import { Transform, Type } from 'class-transformer';
import { toNumber } from '@credebl/common/cast.helper';
import { IsOptional, IsString} from 'class-validator';


import { ApiProperty } from '@nestjs/swagger';
import { Invitation } from '@credebl/enum/enum';
import { PaginationDto } from '@credebl/common/dtos/pagination.dto';

export class GetAllInvitationsDto {
@ApiProperty({ required: false })
@IsOptional()
@Type(() => Number)
@Transform(({ value }) => toNumber(value))
pageNumber = 1;

@ApiProperty({ required: false })
@IsOptional()
@Type(() => String)
search = '';

@ApiProperty({ required: false })
@IsOptional()
@Type(() => Number)
@Transform(({ value }) => toNumber(value))
pageSize = 8;

export class GetAllInvitationsDto extends PaginationDto {
@ApiProperty({ required: false })
@IsOptional()
@IsString()
Expand Down
26 changes: 0 additions & 26 deletions apps/api-gateway/src/user/dto/get-all-users.dto.ts

This file was deleted.

8 changes: 4 additions & 4 deletions apps/api-gateway/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import { AcceptRejectInvitationDto } from './dto/accept-reject-invitation.dto';
import { Invitation } from '@credebl/enum/enum';
import { IUserRequestInterface } from './interfaces';
import { GetAllInvitationsDto } from './dto/get-all-invitations.dto';
import { GetAllUsersDto } from './dto/get-all-users.dto';
import { UpdateUserProfileDto } from './dto/update-user-profile.dto';
import { CustomExceptionFilter } from 'apps/api-gateway/common/exception-handler';
import { AddPasskeyDetailsDto } from './dto/add-user.dto';
Expand All @@ -50,6 +49,7 @@ import { OrgRolesGuard } from '../authz/guards/org-roles.guard';
import { OrgRoles } from 'libs/org-roles/enums';
import { CreateUserCertificateDto } from './dto/share-certificate.dto';
import { AwsService } from '@credebl/aws/aws.service';
import { PaginationDto } from '@credebl/common/dtos/pagination.dto';

@UseFilters(CustomExceptionFilter)
@Controller('users')
Expand Down Expand Up @@ -91,10 +91,10 @@ export class UserController {
})
async get(
@User() user: IUserRequestInterface,
@Query() getAllUsersDto: GetAllUsersDto,
@Query() paginationDto: PaginationDto,
@Res() res: Response
): Promise<Response> {
const users = await this.userService.get(getAllUsersDto);
const users = await this.userService.get(paginationDto);
const finalResponse: IResponse = {
statusCode: HttpStatus.OK,
message: ResponseMessages.user.success.fetchUsers,
Expand Down Expand Up @@ -224,7 +224,7 @@ export class UserController {
required: false
})
async invitations(
@Query() getAllInvitationsDto: GetAllInvitationsDto,
@Query() getAllInvitationsDto: GetAllInvitationsDto,
@User() reqUser: user,
@Res() res: Response
): Promise<Response> {
Expand Down
6 changes: 3 additions & 3 deletions apps/api-gateway/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ClientProxy } from '@nestjs/microservices';
import { BaseService } from 'libs/service/base.service';
import { AcceptRejectInvitationDto } from './dto/accept-reject-invitation.dto';
import { GetAllInvitationsDto } from './dto/get-all-invitations.dto';
import { GetAllUsersDto } from './dto/get-all-users.dto';
import { UpdateUserProfileDto } from './dto/update-user-profile.dto';
import { AddPasskeyDetailsDto } from './dto/add-user.dto';
import { UpdatePlatformSettingsDto } from './dto/update-platform-settings.dto';
Expand All @@ -13,6 +12,7 @@ import { IUsersProfile, ICheckUserDetails } from 'apps/user/interfaces/user.inte
import { IUsersActivity } from 'libs/user-activity/interface';
import { IUserInvitations } from '@credebl/common/interfaces/user.interface';
import { user } from '@prisma/client';
import { PaginationDto } from '@credebl/common/dtos/pagination.dto';

@Injectable()
export class UserService extends BaseService {
Expand Down Expand Up @@ -78,9 +78,9 @@ export class UserService extends BaseService {
}

async get(
getAllUsersDto: GetAllUsersDto
paginationDto:PaginationDto
): Promise<object> {
const { pageNumber, pageSize, search } = getAllUsersDto;
const { pageNumber, pageSize, search } = paginationDto;
const payload = { pageNumber, pageSize, search };
return this.sendNatsMessage(this.serviceProxy, 'fetch-users', payload);
}
Expand Down
Loading

0 comments on commit ff4e93f

Please sign in to comment.