Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:Bhutan-NDI/ngotag-platform into …
Browse files Browse the repository at this point in the history
…pipeline-implementation
  • Loading branch information
Sheetal-ayanworks committed Apr 29, 2024
2 parents 9e7f052 + 5b09ffe commit 6ab4912
Show file tree
Hide file tree
Showing 17 changed files with 390 additions and 63 deletions.
18 changes: 18 additions & 0 deletions apps/api-gateway/src/ecosystem/dtos/add-organizations.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ApiProperty } from '@nestjs/swagger';
import { ArrayNotEmpty, ArrayUnique, IsArray, IsString, IsUUID } from 'class-validator';

export class AddOrganizationsDto {
@ApiProperty({
example: ['32f54163-7166-48f1-93d8-ff217bdb0653']
})
@IsArray()
@ArrayNotEmpty({ message: 'Organization Ids array must not be empty' })
@IsUUID('4', { each: true })
@ArrayUnique({ message: 'Duplicate Organization Ids are not allowed' })
@IsString({ each: true, message: 'Each organization Id in the array should be a string' })
organizationIds: string[];

ecosystemId: string;

orgId: string;
}
41 changes: 41 additions & 0 deletions apps/api-gateway/src/ecosystem/ecosystem.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { GetAllEndorsementsDto } from './dtos/get-all-endorsements.dto';
import { CreateEcosystemDto } from './dtos/create-ecosystem-dto';
import { PaginationDto } from '@credebl/common/dtos/pagination.dto';
import { IEcosystemInvitations, IEditEcosystem, IEndorsementTransaction } from 'apps/ecosystem/interfaces/ecosystem.interfaces';
import { AddOrganizationsDto } from './dtos/add-organizations.dto';


@UseFilters(CustomExceptionFilter)
Expand Down Expand Up @@ -305,6 +306,7 @@ export class EcosystemController {
return res.status(HttpStatus.OK).json(finalResponse);
}


@Post('/:ecosystemId/:orgId/transaction/schema')
@ApiOperation({ summary: 'Request new schema', description: 'Create request for new schema' })
@ApiResponse({ status: HttpStatus.CREATED, description: 'Created', type: ApiResponseDto })
Expand Down Expand Up @@ -447,6 +449,45 @@ export class EcosystemController {

}

/**
*
* @param orgId
* @param ecosystemId
*/
@Post('/:ecosystemId/:orgId/orgs')
@ApiOperation({
summary: 'Add multiple organizations of ecosystem owner in ecosystem',
description: 'Add multiple organizations of ecosystem owner under the same ecosystem'
})
@ApiResponse({ status: HttpStatus.CREATED, description: 'Created', type: ApiResponseDto })
@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'), OrgRolesGuard, EcosystemRolesGuard)
@EcosystemsRoles(EcosystemRoles.ECOSYSTEM_OWNER, EcosystemRoles.ECOSYSTEM_LEAD)
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN)
async addOrganizationsInEcosystem(
@Body() addOrganizationsDto: AddOrganizationsDto,
@Param('ecosystemId', new ParseUUIDPipe({exceptionFactory: (): Error => { throw new BadRequestException(ResponseMessages.ecosystem.error.invalidEcosystemId); }})) ecosystemId: string,
@Param('orgId', new ParseUUIDPipe({exceptionFactory: (): Error => { throw new BadRequestException(ResponseMessages.organisation.error.invalidOrgId); }})) orgId: string,
@User() user: user,
@Res() res: Response
): Promise<Response> {

addOrganizationsDto.ecosystemId = ecosystemId;
addOrganizationsDto.orgId = orgId;

const addOrganizations = await this.ecosystemService.addOrganizationsInEcosystem(addOrganizationsDto, user.id);
const { results, statusCode, message } = addOrganizations;

const finalResponse: IResponse = {
statusCode,
message,
data: results
};

return res.status(statusCode).json(finalResponse);
}


/**
*
* @param res
Expand Down
11 changes: 11 additions & 0 deletions apps/api-gateway/src/ecosystem/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { EditEcosystemDto } from './dtos/edit-ecosystem-dto';
import { IEcosystemDashboard, IEcosystemInvitation, IEcosystemInvitations, IEcosystem, IEditEcosystem, IEndorsementTransaction, ISchemaResponse } from 'apps/ecosystem/interfaces/ecosystem.interfaces';
import { PaginationDto } from '@credebl/common/dtos/pagination.dto';
import { IEcosystemDetails } from '@credebl/common/interfaces/ecosystem.interface';
import { AddOrganizationsDto } from './dtos/add-organizations.dto';

@Injectable()
export class EcosystemService extends BaseService {
Expand Down Expand Up @@ -78,6 +79,16 @@ export class EcosystemService extends BaseService {
return this.sendNatsMessage(this.serviceProxy, 'send-ecosystem-invitation', payload);
}

/**
*
* @param orgId
* @param ecosystemId
*/
async addOrganizationsInEcosystem(addOrganizationsDto: AddOrganizationsDto, userId: string): Promise<{ results: { statusCode: number, message: string, error?: string, data?: { orgId: string } }[], statusCode: number, message: string }> {
const payload = { ...addOrganizationsDto, userId };
return this.sendNatsMessage(this.serviceProxy, 'add-organization-in-ecosystem', payload);
}

async getInvitationsByEcosystemId(
ecosystemId: string,
paginationDto: PaginationDto,
Expand Down
14 changes: 14 additions & 0 deletions apps/api-gateway/src/organization/dtos/get-organizations.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { trim } from '@credebl/common/cast.helper';
import { PaginationDto } from '@credebl/common/dtos/pagination.dto';
import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsEnum, IsOptional } from 'class-validator';
import { OrgRoles } from 'libs/org-roles/enums';

export class GetAllOrganizationsDto extends PaginationDto {
@ApiProperty({ required: false, enum: OrgRoles })
@Transform(({ value }) => trim(value))
@IsOptional()
@IsEnum(OrgRoles)
role: string;
}
23 changes: 3 additions & 20 deletions apps/api-gateway/src/organization/organization.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { ClientCredentialsDto } from './dtos/client-credentials.dto';
import { PaginationDto } from '@credebl/common/dtos/pagination.dto';
import { validate as isValidUUID } from 'uuid';
import { UserAccessGuard } from '../authz/guards/user-access-guard';
import { GetAllOrganizationsDto } from './dtos/get-organizations.dto';
import { PrimaryDid } from './dtos/set-primary-did.dto';

@UseFilters(CustomExceptionFilter)
Expand Down Expand Up @@ -215,27 +216,9 @@ export class OrganizationController {
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'), UserAccessGuard)
@ApiBearerAuth()
@ApiQuery({
name: 'pageNumber',
example: '1',
type: Number,
required: false
})
@ApiQuery({
name: 'pageSize',
example: '10',
type: Number,
required: false
})
@ApiQuery({
name: 'search',
example: '',
type: String,
required: false
})
async getOrganizations(@Query() paginationDto: PaginationDto, @Res() res: Response, @User() reqUser: user): Promise<Response> {
async getOrganizations(@Query() organizationDto: GetAllOrganizationsDto, @Res() res: Response, @User() reqUser: user): Promise<Response> {

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

const finalResponse: IResponse = {
statusCode: HttpStatus.OK,
Expand Down
5 changes: 3 additions & 2 deletions apps/api-gateway/src/organization/organization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ClientCredentialsDto } from './dtos/client-credentials.dto';
import { IAccessTokenData } from '@credebl/common/interfaces/interface';
import { PaginationDto } from '@credebl/common/dtos/pagination.dto';
import { IClientRoles } from '@credebl/client-registration/interfaces/client.interface';
import { GetAllOrganizationsDto } from './dtos/get-organizations.dto';
import { PrimaryDid } from './dtos/set-primary-did.dto';

@Injectable()
Expand Down Expand Up @@ -79,8 +80,8 @@ export class OrganizationService extends BaseService {
* @returns Organizations details
*/

async getOrganizations(paginationDto: PaginationDto, userId: string): Promise<IGetOrganization> {
const payload = { userId, ...paginationDto };
async getOrganizations(organizationDto: GetAllOrganizationsDto, userId: string): Promise<IGetOrganization> {
const payload = { userId, ...organizationDto };
const fetchOrgs = await this.sendNatsMessage(this.serviceProxy, 'get-organizations', payload);
return fetchOrgs;
}
Expand Down
28 changes: 28 additions & 0 deletions apps/ecosystem/interfaces/ecosystem.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,31 @@ export interface IEcosystemList {
pageSize: number;
search: string;
}

export interface IEcosystemLeadOrgs {
organizationIds: string[];
ecosystemId: string;
orgId: string;
userId: string;
}

export interface IEcosystemOrgs {
orgId: string,
ecosystemId: string,
ecosystemRoleId: string,
status: string,
deploymentMode: string,
createdBy: string,
lastChangedBy: string
}
export interface IEcosystemOrgsData extends IEcosystemOrgs {
id: string;
createDateTime: Date;
lastChangedDateTime: Date;
deletedAt: Date;
}

export interface IEcosystemOrgDetails {
count: Prisma.BatchPayload;
ecosystemOrgs: IEcosystemOrgsData[];
}
16 changes: 15 additions & 1 deletion apps/ecosystem/src/ecosystem.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { AcceptRejectEcosystemInvitationDto } from '../dtos/accept-reject-ecosys
import { FetchInvitationsPayload } from '../interfaces/invitations.interface';
import { EcosystemMembersPayload } from '../interfaces/ecosystemMembers.interface';
import { GetEndorsementsPayload, ISchemasResponse } from '../interfaces/endorsements.interface';
import { IEcosystemDashboard, RequestCredDeffEndorsement, RequestSchemaEndorsement, IEcosystem, IEcosystemInvitation, IEcosystemInvitations, IEditEcosystem, IEndorsementTransaction, IEcosystemList } from '../interfaces/ecosystem.interfaces';
import { IEcosystemDashboard, RequestCredDeffEndorsement, RequestSchemaEndorsement, IEcosystem, IEcosystemInvitation, IEcosystemInvitations, IEditEcosystem, IEndorsementTransaction, IEcosystemList, IEcosystemLeadOrgs } from '../interfaces/ecosystem.interfaces';
import { IEcosystemDetails } from '@credebl/common/interfaces/ecosystem.interface';
// eslint-disable-next-line camelcase

@Controller()
export class EcosystemController {
Expand Down Expand Up @@ -98,6 +99,19 @@ export class EcosystemController {
return this.ecosystemService.createInvitation(payload.bulkInvitationDto, payload.userId, payload.userEmail, payload.orgId);
}


/**
*
* @param orgId
* @param ecosystemId
*/
@MessagePattern({ cmd: 'add-organization-in-ecosystem' })
async addOrganizationsInEcosystem(
ecosystemLeadOrgs: IEcosystemLeadOrgs
): Promise<{ results: { statusCode: number, message: string, error?: string, data?: { orgId: string } }[], statusCode: number, message: string }> {
return this.ecosystemService.addOrganizationsInEcosystem(ecosystemLeadOrgs);
}

/**
*
* @param payload
Expand Down
77 changes: 74 additions & 3 deletions apps/ecosystem/src/ecosystem.repository.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BadRequestException, Injectable, InternalServerErrorException, Logger } from '@nestjs/common';
import { PrismaService } from '@credebl/prisma-service';
// eslint-disable-next-line camelcase
import { credential_definition, ecosystem, ecosystem_config, ecosystem_invitations, ecosystem_orgs, ecosystem_roles, endorsement_transaction, org_agents, platform_config, schema } from '@prisma/client';
import { Prisma, credential_definition, ecosystem, ecosystem_config, ecosystem_invitations, ecosystem_orgs, ecosystem_roles, endorsement_transaction, org_agents, organisation, platform_config, schema } from '@prisma/client';
import { DeploymentModeType, EcosystemInvitationStatus, EcosystemOrgStatus, EcosystemRoles, endorsementTransactionStatus, endorsementTransactionType } from '../enums/ecosystem.enum';
import { updateEcosystemOrgsDto } from '../dtos/update-ecosystemOrgs.dto';
import { CreateEcosystem, IEcosystemInvitation, SaveSchema, SchemaTransactionResponse, saveCredDef } from '../interfaces/ecosystem.interfaces';
import { CreateEcosystem, IEcosystemInvitation, IEcosystemOrgs, IEcosystemOrgsData, SaveSchema, SchemaTransactionResponse, saveCredDef } from '../interfaces/ecosystem.interfaces';
import { ResponseMessages } from '@credebl/common/response-messages';
import { NotFoundException } from '@nestjs/common';
import { CommonConstants } from '@credebl/common/common.constant';
Expand Down Expand Up @@ -87,6 +87,72 @@ export class EcosystemRepository {
}
}

//eslint-disable-next-line camelcase
async addOrganizationInEcosystem(orgs: IEcosystemOrgs[]): Promise<Prisma.BatchPayload> {
try {

const result = await this.prisma.ecosystem_orgs.createMany({
data: orgs
});

return result;

} catch (error) {
this.logger.error(`Error in add organization ecosystem: ${error.message}`);
throw error;
}
}

async getEcosystemOrgs(orgIds: string[], ecosystemId: string): Promise<IEcosystemOrgsData[]> {
try {
const result = await this.prisma.ecosystem_orgs.findMany({
where: {
orgId: {
in: orgIds
},
ecosystemId
}
});

return result;

} catch (error) {
this.logger.error(`Error in fetch ecosystem orgs: ${error.message}`);
throw error;
}
}

async checkOrgExists(orgId: string): Promise<organisation> {
try {
const isOrgExists = await this.prisma.organisation.findUnique({
where: {
id: orgId
}
});
return isOrgExists;
} catch (error) {
this.logger.error(`error: ${JSON.stringify(error)}`);
throw new InternalServerErrorException(error);
}
}


// eslint-disable-next-line camelcase
async checkOrgExistsInEcosystem(orgId: string, ecosystemId: string): Promise<ecosystem_orgs> {
try {
const existingOrgs = await this.prisma.ecosystem_orgs.findFirst({
where: {
ecosystemId,
orgId
}
});
return existingOrgs;
} catch (error) {
this.logger.error(`error: ${JSON.stringify(error)}`);
throw new InternalServerErrorException(error);
}
}

/**
* Description: Edit ecosystem by Id
* @param editEcosystemDto
Expand Down Expand Up @@ -539,7 +605,12 @@ export class EcosystemRepository {
name: true,
orgSlug: true,
// eslint-disable-next-line camelcase
org_agents: true
org_agents: true,
userOrgRoles: {
select: {
userId: true
}
}
}
}
},
Expand Down
Loading

0 comments on commit 6ab4912

Please sign in to comment.