Skip to content

Commit

Permalink
feat: ecosystem ms setup (#104)
Browse files Browse the repository at this point in the history
* worked on the master table json file and .env sample refractoring

Signed-off-by: @nishad.shirsat <[email protected]>

* merge dev branch to main (#77)

* fix: Changed the passkey approch

Signed-off-by: KulkarniShashank <[email protected]>

* feat/fix: Implemented Add passkey for existing users

Signed-off-by: tipusinghaw <[email protected]>

* feat:implemented add passke

Signed-off-by: tipusinghaw <[email protected]>

* fix: login error message

Signed-off-by: tipusinghaw <[email protected]>

---------

Signed-off-by: KulkarniShashank <[email protected]>
Signed-off-by: tipusinghaw <[email protected]>

* Included credebl-master-table json file in the .gitignore

Signed-off-by: @nishad.shirsat <[email protected]>

* Create ecosystem monorepo

Signed-off-by: KulkarniShashank <[email protected]>

* feat: Implemented ecosystem microservice

Signed-off-by: tipusinghaw <[email protected]>

* feat: changed controller name

Signed-off-by: tipusinghaw <[email protected]>

---------

Signed-off-by: tipusinghaw <[email protected]>
Signed-off-by: @nishad.shirsat <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>
Co-authored-by: Nishad Shirsat <[email protected]>
Co-authored-by: @nishad.shirsat <[email protected]>
Co-authored-by: Shashank Kulkarni <[email protected]>
Co-authored-by: KulkarniShashank <[email protected]>
Signed-off-by: tipusinghaw <[email protected]>
  • Loading branch information
5 people committed Oct 5, 2023
1 parent d49acd2 commit cc4b82c
Show file tree
Hide file tree
Showing 15 changed files with 310 additions and 2 deletions.
4 changes: 3 additions & 1 deletion apps/api-gateway/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { SchemaModule } from './schema/schema.module';
import { commonNatsOptions } from 'libs/service/nats.options';
import { UserModule } from './user/user.module';
import { ConnectionModule } from './connection/connection.module';
import { EcosystemModule } from './ecosystem/ecosystem.module';

@Module({
imports: [
Expand All @@ -40,7 +41,8 @@ import { ConnectionModule } from './connection/connection.module';
OrganizationModule,
UserModule,
ConnectionModule,
IssuanceModule
IssuanceModule,
EcosystemModule
],
controllers: [AppController],
providers: [AppService]
Expand Down
36 changes: 36 additions & 0 deletions apps/api-gateway/src/ecosystem/dtos/create-organization-dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ApiExtraModels, ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsNotEmpty, IsOptional, IsString, MaxLength, MinLength } from 'class-validator';

import { Transform } from 'class-transformer';
import { trim } from '@credebl/common/cast.helper';

@ApiExtraModels()
export class CreateEcosystemDto {

@ApiProperty()
@Transform(({ value }) => trim(value))
@IsNotEmpty({ message: 'Organization name is required.' })
@MinLength(2, { message: 'Organization name must be at least 2 characters.' })
@MaxLength(50, { message: 'Organization name must be at most 50 characters.' })
@IsString({ message: 'Organization name must be in string format.' })
name: string;

@ApiPropertyOptional()
@Transform(({ value }) => trim(value))
@MinLength(2, { message: 'Description must be at least 2 characters.' })
@MaxLength(255, { message: 'Description must be at most 255 characters.' })
@IsString({ message: 'Description must be in string format.' })
description: string;

@ApiPropertyOptional()
@IsOptional()
@Transform(({ value }) => trim(value))
@IsString({ message: 'logo must be in string format.' })
logo: string;

@ApiPropertyOptional()
@IsOptional()
@Transform(({ value }) => trim(value))
website?: string;

}
43 changes: 43 additions & 0 deletions apps/api-gateway/src/ecosystem/ecosystem.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { ApiBearerAuth, ApiForbiddenResponse, ApiOperation, ApiResponse, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger';
import { Controller, UseGuards, UseFilters } from '@nestjs/common';
import { EcosystemService } from './ecosystem.service';
import { Post } from '@nestjs/common';
import { Body } from '@nestjs/common';
import { Res } from '@nestjs/common';
import { CreateEcosystemDto } from './dtos/create-organization-dto';
import IResponseType from '@credebl/common/interfaces/response.interface';
import { HttpStatus } from '@nestjs/common';
import { Response } from 'express';
import { ApiResponseDto } from '../dtos/apiResponse.dto';
import { UnauthorizedErrorDto } from '../dtos/unauthorized-error.dto';
import { ForbiddenErrorDto } from '../dtos/forbidden-error.dto';
import { AuthGuard } from '@nestjs/passport';
import { ResponseMessages } from '@credebl/common/response-messages';
import { CustomExceptionFilter } from 'apps/api-gateway/common/exception-handler';


@UseFilters(CustomExceptionFilter)
@Controller('ecosystem')
@ApiTags('ecosystem')
@ApiUnauthorizedResponse({ status: 401, description: 'Unauthorized', type: UnauthorizedErrorDto })
@ApiForbiddenResponse({ status: 403, description: 'Forbidden', type: ForbiddenErrorDto })
export class EcosystemController {
constructor(
private readonly ecosystemService: EcosystemService
) { }


@Post('/')
@ApiOperation({ summary: 'Create a new ecosystem', description: 'Create an ecosystem' })
@ApiResponse({ status: 201, description: 'Success', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'))
@ApiBearerAuth()
async createOrganization(@Body() createOrgDto: CreateEcosystemDto, @Res() res: Response): Promise<Response> {
await this.ecosystemService.createEcosystem(createOrgDto);
const finalResponse: IResponseType = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.ecosystem.success.create
};
return res.status(HttpStatus.CREATED).json(finalResponse);
}
}
29 changes: 29 additions & 0 deletions apps/api-gateway/src/ecosystem/ecosystem.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { CommonModule, CommonService } from '@credebl/common';

import { ClientsModule, Transport } from '@nestjs/microservices';
import { ConfigModule } from '@nestjs/config';
import { HttpModule } from '@nestjs/axios';
import { Module } from '@nestjs/common';
import { EcosystemController } from './ecosystem.controller';
import { EcosystemService } from './ecosystem.service';

@Module({
imports: [
HttpModule,
ConfigModule.forRoot(),
ClientsModule.register([
{
name: 'NATS_CLIENT',
transport: Transport.NATS,
options: {
servers: [`${process.env.NATS_URL}`]
}
},
CommonModule
])
],
controllers: [EcosystemController],
providers: [EcosystemService, CommonService]
})
export class EcosystemModule { }

23 changes: 23 additions & 0 deletions apps/api-gateway/src/ecosystem/ecosystem.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Inject } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';
import { BaseService } from 'libs/service/base.service';


@Injectable()
export class EcosystemService extends BaseService {
constructor(@Inject('NATS_CLIENT') private readonly serviceProxy: ClientProxy) {
super('EcosystemService');
}

/**
*
* @param createEcosystemDto
* @returns Ecosystem creation success
*/
async createEcosystem(createEcosystemDto): Promise<object> {
const payload = { createEcosystemDto };
return this.sendNats(this.serviceProxy, 'create-ecosystem', payload);
}

}
22 changes: 22 additions & 0 deletions apps/ecosystem/src/ecosystem.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Test, TestingModule } from '@nestjs/testing';
import { EcosystemController } from './ecosystem.controller';
import { EcosystemService } from './ecosystem.service';

describe('EcosystemController', () => {
let ecosystemController: EcosystemController;

beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [EcosystemController],
providers: [EcosystemService]
}).compile();

ecosystemController = app.get<EcosystemController>(EcosystemController);
});

describe('root', () => {
it('should return "Hello World!"', () => {
expect(ecosystemController.getHello()).toBe('Hello World!');
});
});
});
24 changes: 24 additions & 0 deletions apps/ecosystem/src/ecosystem.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Controller, Logger } from '@nestjs/common';

import { MessagePattern } from '@nestjs/microservices';
import { EcosystemService } from './ecosystem.service';
import { Body } from '@nestjs/common';

@Controller()
export class EcosystemController {
constructor(private readonly ecosystemService: EcosystemService) {}
private readonly logger = new Logger('EcosystemController');

/**
* Description: create new ecosystem
* @param payload Registration Details
* @returns Get created ecosystem details
*/

@MessagePattern({ cmd: 'create-ecosystem' })
async createEcosystem(@Body() payload: { createOrgDto; userId }): Promise<string> {
this.logger.log(`EcosystemPayload : ${payload}`);
return this.ecosystemService.createEcosystem();
}

}
26 changes: 26 additions & 0 deletions apps/ecosystem/src/ecosystem.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Logger, Module } from '@nestjs/common';
import { EcosystemController } from './ecosystem.controller';
import { EcosystemService } from './ecosystem.service';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { CommonModule } from '@credebl/common';
// import { ConnectionRepository } from './connection.repository';
import { PrismaService } from '@credebl/prisma-service';

@Module({
imports: [
ClientsModule.register([
{
name: 'NATS_CLIENT',
transport: Transport.NATS,
options: {
servers: [`${process.env.NATS_URL}`]
}
}
]),

CommonModule
],
controllers: [EcosystemController],
providers: [EcosystemService, PrismaService, Logger]
})
export class EcosystemModule { }
20 changes: 20 additions & 0 deletions apps/ecosystem/src/ecosystem.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// eslint-disable-next-line camelcase
import { Injectable} from '@nestjs/common';

@Injectable()
export class EcosystemService {
constructor(
) { }

/**
*
* @param registerOrgDto
* @returns
*/

// eslint-disable-next-line camelcase
async createEcosystem():Promise<string> {
return "test";
}

}
23 changes: 23 additions & 0 deletions apps/ecosystem/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { NestFactory } from '@nestjs/core';
import { EcosystemModule } from './ecosystem.module';
import { HttpExceptionFilter } from 'libs/http-exception.filter';
import { Logger } from '@nestjs/common';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';

const logger = new Logger();

async function bootstrap(): Promise<void> {

const app = await NestFactory.createMicroservice<MicroserviceOptions>(EcosystemModule, {
transport: Transport.NATS,
options: {
servers: [`${process.env.NATS_URL}`]
}
});

app.useGlobalFilters(new HttpExceptionFilter());

await app.listen();
logger.log('Ecosystem microservice is listening to NATS ');
}
bootstrap();
24 changes: 24 additions & 0 deletions apps/ecosystem/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { EcosystemModule } from './../src/ecosystem.module';

describe('EcosystemController (e2e)', () => {
let app: INestApplication;

beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [EcosystemModule]
}).compile();

app = moduleFixture.createNestApplication();
await app.init();
});

it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
});
});
9 changes: 9 additions & 0 deletions apps/ecosystem/test/jest-e2e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".e2e-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}
9 changes: 9 additions & 0 deletions apps/ecosystem/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"declaration": false,
"outDir": "../../dist/apps/ecosystem"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
}
11 changes: 10 additions & 1 deletion libs/common/src/response-messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,14 @@ export const ResponseMessages = {
platformConfigNotFound: 'Platform config not found',
emailSend: 'Unable to send email to the user'
}
}
},
ecosystem: {
success: {
create: 'Ecosystem created successfully',
},
error: {

}

},
};
9 changes: 9 additions & 0 deletions nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,15 @@
"compilerOptions": {
"tsConfigPath": "libs/supabase/tsconfig.lib.json"
}
},
"ecosystem": {
"type": "application",
"root": "apps/ecosystem",
"entryFile": "main",
"sourceRoot": "apps/ecosystem/src",
"compilerOptions": {
"tsConfigPath": "apps/ecosystem/tsconfig.app.json"
}
}
}
}

0 comments on commit cc4b82c

Please sign in to comment.