From aff4cf76a83bc68ef37c8b6e27fa795e923ddf6b Mon Sep 17 00:00:00 2001 From: Konstantin Tsabolov <1006564+tsabolov@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:26:06 +0100 Subject: [PATCH] chore: apply new ESLint config to attestation-manager --- apps/attestation-manager/.eslintrc.cjs | 42 ---------- apps/attestation-manager/package.json | 6 +- apps/attestation-manager/src/app.module.ts | 7 +- .../src/client/nats.client.ts | 9 ++- .../src/client/rest.client.ts | 8 +- .../src/client/tests/__mocks__/tsa.client.ts | 3 +- .../src/client/tests/rest.client.spec.ts | 7 +- .../src/client/tests/stubs/nats-response.ts | 1 + .../src/client/tsa.client.ts | 5 +- .../src/common/exception.handler.ts | 11 +-- .../credentialDef/controller/controller.ts | 18 +++-- .../entities/credentialDef-entity.ts | 30 ++++---- .../entities/credentialDefLedger-entity.ts | 6 +- .../entities/credentialDefReq.dto.ts | 26 +++---- .../src/credentialDef/module.ts | 2 + .../repository/credentialDef.respository.ts | 12 +-- .../src/credentialDef/services/service.ts | 32 ++++---- .../credentialDef/tests/controller.spec.ts | 22 +++--- .../src/credentialDef/tests/module.spec.ts | 6 +- .../src/credentialDef/tests/service.spec.ts | 8 +- .../credentialDef/tests/stubs/credDef.stub.ts | 2 +- .../src/health/health.controller.ts | 7 +- .../health/tests/health.controller.spec.ts | 7 +- .../issue-credential/controller/controller.ts | 60 +++++++++------ .../entities/credential.entity.ts | 18 ++--- .../entities/credential.state.entity.ts | 12 +-- .../entities/credentialType.entity.ts | 6 +- .../src/issue-credential/entities/entity.ts | 14 ++-- .../entities/get-issue-credentials.dto.ts | 2 +- .../entities/get.credential.params.ts | 2 +- .../entities/get.credential.query.ts | 28 +++---- .../entities/propose-credential.dto.ts | 10 +-- .../entities/updatecredDefIdByType.entity.ts | 2 +- .../src/issue-credential/module.ts | 2 + .../repository/credential.repository.ts | 18 +++-- .../repository/credentialType.repository.ts | 18 +++-- .../src/issue-credential/services/service.ts | 69 +++++++++-------- .../issue-credential/tests/controller.spec.ts | 26 ++++--- .../src/issue-credential/tests/module.spec.ts | 6 +- .../issue-credential/tests/service.spec.ts | 10 ++- .../tests/stubs/credential-dto.ts | 3 +- .../tests/stubs/credential-state-dto.ts | 4 +- .../tests/stubs/credential-type-dto.ts | 3 +- .../tests/stubs/offer-credential-dto.ts | 4 +- apps/attestation-manager/src/main.ts | 76 +++++++++---------- .../src/middleware/auth.middleware.ts | 10 ++- .../src/prisma/prisma.module.ts | 1 + .../src/prisma/prisma.service.ts | 10 ++- .../src/prisma/tests/prisma.module.spec.ts | 12 ++- .../src/prisma/tests/prisma.service.spec.ts | 9 ++- .../src/schemas/controller/controller.ts | 22 ++++-- .../src/schemas/entities/schema-entity.ts | 24 +++--- .../attestation-manager/src/schemas/module.ts | 2 + .../schemas/repository/schema.respository.ts | 14 ++-- .../src/schemas/services/service.ts | 26 ++++--- .../src/schemas/tests/controller.spec.ts | 28 ++++--- .../src/schemas/tests/module.spec.ts | 6 +- .../src/schemas/tests/service.spec.ts | 10 ++- .../src/schemas/tests/stubs/schema-dto.ts | 2 +- .../src/tests/app.module.spec.ts | 7 +- .../src/userInfo/controller/controller.ts | 7 +- .../userInfo/entities/update-unserInfo.dto.ts | 8 +- .../src/userInfo/entities/userInfo.entity.ts | 6 +- .../src/userInfo/module.ts | 2 + .../repository/userInfo.respository.ts | 12 +-- .../src/userInfo/services/service.ts | 14 ++-- .../tests/stubs/user-info-dto.stub.ts | 3 +- .../src/utils/exceptionsFilter.ts | 17 ++--- apps/attestation-manager/src/utils/logger.ts | 10 ++- apps/attestation-manager/test/app.e2e-spec.ts | 7 +- 70 files changed, 513 insertions(+), 426 deletions(-) delete mode 100644 apps/attestation-manager/.eslintrc.cjs diff --git a/apps/attestation-manager/.eslintrc.cjs b/apps/attestation-manager/.eslintrc.cjs deleted file mode 100644 index e0c3a4c..0000000 --- a/apps/attestation-manager/.eslintrc.cjs +++ /dev/null @@ -1,42 +0,0 @@ -module.exports = { - root: true, - parser: '@typescript-eslint/parser', - parserOptions: { - sourceType: 'module', - ecmaVersion: 2021, - }, - env: { - node: true, - }, - plugins: ['prettier', '@typescript-eslint/eslint-plugin', 'jest'], - extends: [ - 'prettier', - 'plugin:@typescript-eslint/recommended', - 'plugin:jest/recommended', - ], - ignorePatterns: ['.eslintrc.js'], - overrides: [], - settings: { - jest: { - version: '29', - }, - }, - rules: { - 'no-unused-vars': 0, - '@typescript-eslint/no-unused-vars': [1, { argsIgnorePattern: '^_' }], - }, - overrides: [ - { - files: [ - '*.spec.ts', - '*.e2e-spec.ts', - '__mocks__/*.ts', - '__mocks__/**/*.ts', - ], - rules: { - '@typescript-eslint/no-explicit-any': 0, - 'jest/no-mocks-import': 0, - }, - }, - ], -}; diff --git a/apps/attestation-manager/package.json b/apps/attestation-manager/package.json index 9be54b8..06ce573 100644 --- a/apps/attestation-manager/package.json +++ b/apps/attestation-manager/package.json @@ -38,6 +38,7 @@ "@prisma/client": "^5.6.0", "class-transformer": "^0.5.1", "class-validator": "^0.14.0", + "express": "^4.17.3", "joi": "^17.11.0", "jsonwebtoken": "^9.0.2", "jwks-rsa": "^3.1.0", @@ -63,13 +64,8 @@ "@types/jsonwebtoken": "^9.0.5", "@types/node": "^20.9.0", "@types/supertest": "^2.0.16", - "@typescript-eslint/eslint-plugin": "^6.11.0", - "@typescript-eslint/parser": "^6.11.0", "dotenv-cli": "^7.3.0", "eslint": "^8.53.0", - "eslint-config-prettier": "^9.0.0", - "eslint-plugin-jest": "^27.6.0", - "eslint-plugin-prettier": "^5.0.1", "husky": "^8.0.3", "jest": "^29.7.0", "node-mocks-http": "^1.13.0", diff --git a/apps/attestation-manager/src/app.module.ts b/apps/attestation-manager/src/app.module.ts index d7551e8..2ab9898 100644 --- a/apps/attestation-manager/src/app.module.ts +++ b/apps/attestation-manager/src/app.module.ts @@ -1,12 +1,13 @@ import { - MiddlewareConsumer, Module, - NestModule, RequestMethod, + type MiddlewareConsumer, + type NestModule, } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { APP_FILTER } from '@nestjs/core'; import { TerminusModule } from '@nestjs/terminus'; + import ExceptionHandler from './common/exception.handler.js'; import config from './config/config.js'; import validationSchema from './config/validation.js'; @@ -39,7 +40,7 @@ import UserInfoModule from './userInfo/module.js'; ], }) export default class AppModule implements NestModule { - configure(consumer: MiddlewareConsumer) { + public configure(consumer: MiddlewareConsumer) { // eslint-disable-line consumer .apply(AuthMiddleware) diff --git a/apps/attestation-manager/src/client/nats.client.ts b/apps/attestation-manager/src/client/nats.client.ts index c232a1b..9946c3b 100644 --- a/apps/attestation-manager/src/client/nats.client.ts +++ b/apps/attestation-manager/src/client/nats.client.ts @@ -1,15 +1,16 @@ import { Inject, Injectable } from '@nestjs/common'; import { ClientProxy } from '@nestjs/microservices'; import { lastValueFrom } from 'rxjs'; + import { Connection, NATSServices } from '../common/constants.js'; @Injectable() export default class NatsClientService { - constructor( + public constructor( @Inject(NATSServices.SERVICE_NAME) private natsClient: ClientProxy, ) {} - getConnectionById(connectionId: string) { + public getConnectionById(connectionId: string) { const pattern = { endpoint: `${Connection.NATS_ENDPOINT}/${Connection.GET_CONNECTION_BY_ID}`, }; @@ -17,7 +18,7 @@ export default class NatsClientService { return lastValueFrom(this.natsClient.send(pattern, payload)); } - connectionTrusted(connectionId: string) { + public connectionTrusted(connectionId: string) { const pattern = { endpoint: `${Connection.NATS_ENDPOINT}/${Connection.MAKE_CONNECTION_TRUSTED}`, }; @@ -25,7 +26,7 @@ export default class NatsClientService { return lastValueFrom(this.natsClient.send(pattern, payload)); } - getReceivedConnections() { + public getReceivedConnections() { const pattern = { endpoint: `${Connection.NATS_ENDPOINT}/${Connection.GET_RECEIVED_CONNECTIONS}`, }; diff --git a/apps/attestation-manager/src/client/rest.client.ts b/apps/attestation-manager/src/client/rest.client.ts index edd52e1..6dce06d 100644 --- a/apps/attestation-manager/src/client/rest.client.ts +++ b/apps/attestation-manager/src/client/rest.client.ts @@ -4,15 +4,15 @@ import { lastValueFrom, map } from 'rxjs'; @Injectable() export default class RestClientService { - constructor(private readonly httpService: HttpService) {} + public constructor(private readonly httpService: HttpService) {} - async delete(url: string) { + public async delete(url: string) { return lastValueFrom( this.httpService.delete(url).pipe(map((response) => response.data)), ); } - async post(url: string, payload: object) { + public async post(url: string, payload: object) { return lastValueFrom( this.httpService .post(url, payload) @@ -20,7 +20,7 @@ export default class RestClientService { ); } - async get(url: string) { + public async get(url: string) { return lastValueFrom( this.httpService.get(url).pipe(map((response) => response.data)), ); diff --git a/apps/attestation-manager/src/client/tests/__mocks__/tsa.client.ts b/apps/attestation-manager/src/client/tests/__mocks__/tsa.client.ts index 7368ee8..eceacef 100644 --- a/apps/attestation-manager/src/client/tests/__mocks__/tsa.client.ts +++ b/apps/attestation-manager/src/client/tests/__mocks__/tsa.client.ts @@ -1,5 +1,6 @@ +import type { PolicyReturnType } from '../../tsa.client.js'; + import { TSAService } from '../../../common/constants.js'; -import { PolicyReturnType } from '../../tsa.client.js'; const TSAClientServiceMock = jest.fn().mockReturnValue({ getPolicy: jest.fn().mockImplementation((url: string) => { diff --git a/apps/attestation-manager/src/client/tests/rest.client.spec.ts b/apps/attestation-manager/src/client/tests/rest.client.spec.ts index 6a38cdc..49f5a82 100644 --- a/apps/attestation-manager/src/client/tests/rest.client.spec.ts +++ b/apps/attestation-manager/src/client/tests/rest.client.spec.ts @@ -1,5 +1,8 @@ +import type { TestingModule } from '@nestjs/testing'; + import { HttpModule, HttpService } from '@nestjs/axios'; -import { Test, TestingModule } from '@nestjs/testing'; +import { Test } from '@nestjs/testing'; + import HttpServiceMock from '../../tests/__mocks__/http-service.js'; import RestClientService from '../rest.client.js'; @@ -25,7 +28,7 @@ describe('RestClientService', () => { }); describe('post()', () => { - let restClientResponse: any; + let restClientResponse: unknown; beforeEach(async () => { restClientResponse = await restClient.post('test_url', {}); diff --git a/apps/attestation-manager/src/client/tests/stubs/nats-response.ts b/apps/attestation-manager/src/client/tests/stubs/nats-response.ts index 776bf54..218547f 100644 --- a/apps/attestation-manager/src/client/tests/stubs/nats-response.ts +++ b/apps/attestation-manager/src/client/tests/stubs/nats-response.ts @@ -1,4 +1,5 @@ import type { ResponseType } from '../../../common/response.js'; + import AttestationService from '../../../issue-credential/services/service.js'; const natsAgentResponse: ResponseType = { diff --git a/apps/attestation-manager/src/client/tsa.client.ts b/apps/attestation-manager/src/client/tsa.client.ts index b0476f3..5f7dcf8 100644 --- a/apps/attestation-manager/src/client/tsa.client.ts +++ b/apps/attestation-manager/src/client/tsa.client.ts @@ -1,4 +1,5 @@ import { Injectable } from '@nestjs/common'; + import RestClientService from './rest.client.js'; export interface PolicyReturnType { @@ -13,9 +14,9 @@ export interface PolicyResult { @Injectable() export default class TSAClientService { - constructor(private readonly restClient: RestClientService) {} + public constructor(private readonly restClient: RestClientService) {} - async getPolicy(policyUrl: string) { + public async getPolicy(policyUrl: string) { try { const policyResponse: PolicyResult = await this.restClient.get(policyUrl); diff --git a/apps/attestation-manager/src/common/exception.handler.ts b/apps/attestation-manager/src/common/exception.handler.ts index 4064f23..4e977c8 100644 --- a/apps/attestation-manager/src/common/exception.handler.ts +++ b/apps/attestation-manager/src/common/exception.handler.ts @@ -1,19 +1,20 @@ +import type { ResponseType } from './response.js'; + import { - ArgumentsHost, Catch, - ExceptionFilter, HttpException, HttpStatus, + type ArgumentsHost, + type ExceptionFilter, } from '@nestjs/common'; import { HttpAdapterHost } from '@nestjs/core'; -import { ResponseType } from './response.js'; @Catch() export default class ExceptionHandler implements ExceptionFilter { - constructor(private readonly httpAdapterHost: HttpAdapterHost) {} + public constructor(private readonly httpAdapterHost: HttpAdapterHost) {} // eslint-disable-next-line @typescript-eslint/no-explicit-any - catch(exception: any, host: ArgumentsHost): void { + public catch(exception: any, host: ArgumentsHost): void { // In certain situations `httpAdapter` might not be available in the // constructor method, thus we should resolve it here. const { httpAdapter } = this.httpAdapterHost; diff --git a/apps/attestation-manager/src/credentialDef/controller/controller.ts b/apps/attestation-manager/src/credentialDef/controller/controller.ts index efb4adc..c644d0f 100644 --- a/apps/attestation-manager/src/credentialDef/controller/controller.ts +++ b/apps/attestation-manager/src/credentialDef/controller/controller.ts @@ -1,3 +1,6 @@ +import type { ResponseType } from '../../common/response.js'; +import type CredentialDefLedgerDto from '../entities/credentialDefLedger-entity.js'; + import { Body, Controller, @@ -19,17 +22,18 @@ import { ApiTags, } from '@nestjs/swagger'; import { Prisma } from '@prisma/client'; -import type { Response } from 'express'; -import { ResponseType } from '../../common/response.js'; +import { Response } from 'express'; + import logger from '../../utils/logger.js'; import CredentialDefDto from '../entities/credentialDef-entity.js'; -import CredentialDefLedgerDto from '../entities/credentialDefLedger-entity.js'; import CredentialDefService from '../services/service.js'; @ApiTags('Credential Definitions') @Controller('credentialDef') export default class CredentialDefController { - constructor(private readonly credentialDefService: CredentialDefService) {} + public constructor( + private readonly credentialDefService: CredentialDefService, + ) {} @Version(['1']) @ApiQuery({ name: 'page', required: false }) @@ -124,7 +128,7 @@ export default class CredentialDefController { }, }, }) - async findCredentialDef( + public async findCredentialDef( @Query() query: { pageSize: string; @@ -244,7 +248,7 @@ export default class CredentialDefController { }, }, }) - async findCredentialDefById( + public async findCredentialDefById( @Param('id') id: string, @Res() response: Response, ) { @@ -390,7 +394,7 @@ export default class CredentialDefController { }, }, }) - async createCredentialDef( + public async createCredentialDef( @Body() credentialDefDto: CredentialDefDto, @Res() response: Response, ) { diff --git a/apps/attestation-manager/src/credentialDef/entities/credentialDef-entity.ts b/apps/attestation-manager/src/credentialDef/entities/credentialDef-entity.ts index d6d373b..1b57a39 100644 --- a/apps/attestation-manager/src/credentialDef/entities/credentialDef-entity.ts +++ b/apps/attestation-manager/src/credentialDef/entities/credentialDef-entity.ts @@ -1,56 +1,56 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; -import { IsString, IsNotEmpty, IsBoolean } from 'class-validator'; +import { IsBoolean, IsNotEmpty, IsString } from 'class-validator'; export default class CredentialDefDto { @IsString() - id: string; + public id: string; @IsString() @IsNotEmpty() @ApiProperty() - schemaID: string; + public schemaID: string; @IsString() @IsNotEmpty() @ApiProperty() - name: string; + public name: string; @IsString() - credDefId: string; + public credDefId: string; @IsBoolean() - supportRevocation?: boolean; + public supportRevocation?: boolean; @IsBoolean() @ApiProperty() - isRevokable: boolean; + public isRevokable: boolean; @IsBoolean() @ApiProperty() - isAutoIssue: boolean; + public isAutoIssue: boolean; @IsString() @ApiProperty() // Number of hours of Credential validity - expiryHours: string; + public expiryHours: string; @IsString() @ApiProperty() - createdBy: string; + public createdBy: string; @IsString() - createdDate: Date; + public createdDate: Date; @IsString() - updatedBy: string; + public updatedBy: string; @IsString() - updatedDate: Date; + public updatedDate: Date; @IsString() - tag?: string; + public tag?: string; @IsString() @ApiPropertyOptional() - type?: string; + public type?: string; } diff --git a/apps/attestation-manager/src/credentialDef/entities/credentialDefLedger-entity.ts b/apps/attestation-manager/src/credentialDef/entities/credentialDefLedger-entity.ts index 347ea56..2eb6767 100644 --- a/apps/attestation-manager/src/credentialDef/entities/credentialDefLedger-entity.ts +++ b/apps/attestation-manager/src/credentialDef/entities/credentialDefLedger-entity.ts @@ -2,11 +2,11 @@ import { IsString, IsBoolean } from 'class-validator'; export default class CredentialDefLedgerDto { @IsString() - schemaId: string; + public schemaId: string; @IsBoolean() - supportRevocation?: boolean; + public supportRevocation?: boolean; @IsString() - tag?: string; + public tag?: string; } diff --git a/apps/attestation-manager/src/credentialDef/entities/credentialDefReq.dto.ts b/apps/attestation-manager/src/credentialDef/entities/credentialDefReq.dto.ts index f839068..0c0aac3 100644 --- a/apps/attestation-manager/src/credentialDef/entities/credentialDefReq.dto.ts +++ b/apps/attestation-manager/src/credentialDef/entities/credentialDefReq.dto.ts @@ -3,50 +3,50 @@ import { IsString, IsNotEmpty, IsBoolean } from 'class-validator'; export default class CredentialDefReqDto { @IsString() - id: string; + public id: string; @IsString() @IsNotEmpty() @ApiProperty() - schemaID: string; + public schemaID: string; @IsString() @IsNotEmpty() @ApiProperty() - name: string; + public name: string; @IsString() - credDefId: string; + public credDefId: string; @IsBoolean() - supportRevocation?: boolean; + public supportRevocation?: boolean; @IsBoolean() @ApiProperty() - isRevokable: boolean; + public isRevokable: boolean; @IsBoolean() @ApiProperty() - isAutoIssue: boolean; + public isAutoIssue: boolean; @IsString() @ApiProperty() // Number of hours of Credential validity - expiryHours: string; + public expiryHours: string; @IsString() @ApiProperty() - createdBy: string; + public createdBy: string; @IsString() - createdDate: Date; + public createdDate: Date; @IsString() - updatedBy: string; + public updatedBy: string; @IsString() - updatedDate: Date; + public updatedDate: Date; @IsString() - tag?: string; + public tag?: string; } diff --git a/apps/attestation-manager/src/credentialDef/module.ts b/apps/attestation-manager/src/credentialDef/module.ts index 2d5834f..663e839 100644 --- a/apps/attestation-manager/src/credentialDef/module.ts +++ b/apps/attestation-manager/src/credentialDef/module.ts @@ -1,12 +1,14 @@ import { HttpModule } from '@nestjs/axios'; import { Module } from '@nestjs/common'; import { ClientsModule, Transport } from '@nestjs/microservices'; + import NatsClientService from '../client/nats.client.js'; import RestClientService from '../client/rest.client.js'; import { NATSServices } from '../common/constants.js'; import config from '../config/config.js'; import PrismaService from '../prisma/prisma.service.js'; import SchemasService from '../schemas/services/service.js'; + import CredentialDefController from './controller/controller.js'; import CredentialDefService from './services/service.js'; diff --git a/apps/attestation-manager/src/credentialDef/repository/credentialDef.respository.ts b/apps/attestation-manager/src/credentialDef/repository/credentialDef.respository.ts index c1af9e3..2a0b1ae 100644 --- a/apps/attestation-manager/src/credentialDef/repository/credentialDef.respository.ts +++ b/apps/attestation-manager/src/credentialDef/repository/credentialDef.respository.ts @@ -1,12 +1,14 @@ +import type { Prisma } from '@prisma/client'; + import { Injectable } from '@nestjs/common'; -import { Prisma } from '@prisma/client'; + import PrismaService from '../../prisma/prisma.service.js'; @Injectable() export default class CredentialDefRepository { - constructor(private readonly prismaService: PrismaService) {} + public constructor(private readonly prismaService: PrismaService) {} - async createCredDef(data: Prisma.CredentialDefCreateInput) { + public async createCredDef(data: Prisma.CredentialDefCreateInput) { const credDef = await this.prismaService.credentialDef.create({ data, }); @@ -27,7 +29,7 @@ export default class CredentialDefRepository { return credDef; } - async findCredentialDef(params: { + public async findCredentialDef(params: { skip?: number; take?: number; cursor?: Prisma.CredentialDefWhereUniqueInput; @@ -49,7 +51,7 @@ export default class CredentialDefRepository { ]); } - async findUniqueCredentialDef(params: { + public async findUniqueCredentialDef(params: { where: Prisma.CredentialDefWhereUniqueInput; }) { const { where } = params; diff --git a/apps/attestation-manager/src/credentialDef/services/service.ts b/apps/attestation-manager/src/credentialDef/services/service.ts index 5dd5622..1de9a74 100644 --- a/apps/attestation-manager/src/credentialDef/services/service.ts +++ b/apps/attestation-manager/src/credentialDef/services/service.ts @@ -1,16 +1,18 @@ +import type SchemaDto from '../../schemas/entities/schema-entity.js'; +import type CredentialDefDto from '../entities/credentialDef-entity.js'; +import type CredentialDefLedgerDto from '../entities/credentialDefLedger-entity.js'; +import type { Prisma } from '@prisma/client'; + import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; -import { Prisma } from '@prisma/client'; + import RestClientService from '../../client/rest.client.js'; +import CredentialTypeRepository from '../../issue-credential/repository/credentialType.repository.js'; import PrismaService from '../../prisma/prisma.service.js'; -import SchemaDto from '../../schemas/entities/schema-entity.js'; import SchemasService from '../../schemas/services/service.js'; import logger from '../../utils/logger.js'; import pagination from '../../utils/pagination.js'; -import CredentialDefDto from '../entities/credentialDef-entity.js'; -import CredentialDefLedgerDto from '../entities/credentialDefLedger-entity.js'; import CredentialDefRepository from '../repository/credentialDef.respository.js'; -import CredentialTypeRepository from '../../issue-credential/repository/credentialType.repository.js'; @Injectable() export default class CredentialDefService { @@ -18,7 +20,7 @@ export default class CredentialDefService { private credentialTypeRepository: CredentialTypeRepository; - constructor( + public constructor( private readonly prismaService: PrismaService, private readonly restClient: RestClientService, private readonly configService: ConfigService, @@ -33,7 +35,7 @@ export default class CredentialDefService { ); } - async createCredDef(credentialDefDtoPar: CredentialDefDto) { + public async createCredDef(credentialDefDtoPar: CredentialDefDto) { const credentialDefDto: CredentialDefDto = credentialDefDtoPar; const schema = await this.schemaService.findBySchemaId( credentialDefDto.schemaID, @@ -73,7 +75,11 @@ export default class CredentialDefService { return this.credentialDefRepository.createCredDef(credentialDefDto); } - async findCredentialDef(pageSize: number, page: number, getSchemaID: string) { + public async findCredentialDef( + pageSize: number, + page: number, + getSchemaID: string, + ) { let query: { skip?: number; take?: number; @@ -90,7 +96,7 @@ export default class CredentialDefService { return this.credentialDefRepository.findCredentialDef(query); } - async findCredentialDefBySchemaIdAndCredDefId(data: { + public async findCredentialDefBySchemaIdAndCredDefId(data: { schemaID: string; credDefId: string; }) { @@ -99,7 +105,7 @@ export default class CredentialDefService { }); } - async findCredentialDefBySchemaIdDesc(data: { schemaID: string }) { + public async findCredentialDefBySchemaIdDesc(data: { schemaID: string }) { return this.credentialDefRepository.findCredentialDef({ where: data, orderBy: { @@ -108,13 +114,13 @@ export default class CredentialDefService { }); } - async findCredentialDefById(id: string) { + public async findCredentialDefById(id: string) { return this.credentialDefRepository.findCredentialDef({ where: { credDefId: id }, }); } - async checkCredDefByNameAndSchemaID(createSchema: CredentialDefDto) { + public async checkCredDefByNameAndSchemaID(createSchema: CredentialDefDto) { return this.credentialDefRepository.findCredentialDef({ where: { schemaID: { @@ -127,7 +133,7 @@ export default class CredentialDefService { }); } - async createCredDefOnLedger(credentialDefDto: CredentialDefLedgerDto) { + public async createCredDefOnLedger(credentialDefDto: CredentialDefLedgerDto) { const agentUrl = this.configService.get('agent.AGENT_URL'); return this.restClient.post( `${agentUrl}/credential-definitions/`, diff --git a/apps/attestation-manager/src/credentialDef/tests/controller.spec.ts b/apps/attestation-manager/src/credentialDef/tests/controller.spec.ts index a24aed4..0615c1c 100644 --- a/apps/attestation-manager/src/credentialDef/tests/controller.spec.ts +++ b/apps/attestation-manager/src/credentialDef/tests/controller.spec.ts @@ -1,10 +1,14 @@ +import type { TestingModule } from '@nestjs/testing'; +import type { Response } from 'express'; + import { HttpStatus } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; -import { Test, TestingModule } from '@nestjs/testing'; -import { Response } from 'express'; -import httpMocks from 'node-mocks-http'; +import { Test } from '@nestjs/testing'; +import { createResponse } from 'node-mocks-http'; + import CredentialDefController from '../controller/controller.js'; import CredentialDefService from '../services/service.js'; + import CredentialDefServiceMock from './__mocks__/service.js'; import credDefStub from './stubs/credDef.stub.js'; @@ -41,7 +45,7 @@ describe('CredentialDefController', () => { page: string; schemaID: string; }; - let credDefResponse: Response<string, Record<string, any>>; + let credDefResponse: Response<string, Record<string, unknown>>; beforeEach(async () => { query = { @@ -50,7 +54,7 @@ describe('CredentialDefController', () => { schemaID: credDefStub().schemaID, }; - const response = httpMocks.createResponse(); + const response = createResponse(); credDefResponse = await credentialDefController.findCredentialDef( query, response, @@ -78,12 +82,12 @@ describe('CredentialDefController', () => { describe('findCredentialDefById()', () => { let credDefID: string; - let credDef: Response<string, Record<string, any>>; + let credDef: Response<string, Record<string, unknown>>; beforeEach(async () => { credDefID = credDefStub().id; - const response = httpMocks.createResponse(); + const response = createResponse(); credDef = await credentialDefController.findCredentialDefById( credDefID, response, @@ -107,10 +111,10 @@ describe('CredentialDefController', () => { }); describe('createCredDef()', () => { - let credDef: Response<string, Record<string, any>>; + let credDef: Response<string, Record<string, unknown>>; beforeEach(async () => { - const response = httpMocks.createResponse(); + const response = createResponse(); credDef = await credentialDefController.createCredentialDef( credDefStub(), response, diff --git a/apps/attestation-manager/src/credentialDef/tests/module.spec.ts b/apps/attestation-manager/src/credentialDef/tests/module.spec.ts index 9b152df..12da65f 100644 --- a/apps/attestation-manager/src/credentialDef/tests/module.spec.ts +++ b/apps/attestation-manager/src/credentialDef/tests/module.spec.ts @@ -1,5 +1,8 @@ +import type { TestingModule } from '@nestjs/testing'; + import { HttpModule } from '@nestjs/axios'; -import { Test, TestingModule } from '@nestjs/testing'; +import { Test } from '@nestjs/testing'; + import NatsClientService from '../../client/nats.client.js'; import RestClientService from '../../client/rest.client.js'; import NatsClientServiceMock from '../../client/tests/__mocks__/nats.client.js'; @@ -8,6 +11,7 @@ import PrismaService from '../../prisma/prisma.service.js'; import PrismaServiceMock from '../../prisma/tests/__mocks__/prisma.service.js'; import CredentialDefModule from '../module.js'; import CredentialDefService from '../services/service.js'; + import CredentialDefServiceMock from './__mocks__/service.js'; describe('CredentialDefModule', () => { diff --git a/apps/attestation-manager/src/credentialDef/tests/service.spec.ts b/apps/attestation-manager/src/credentialDef/tests/service.spec.ts index ab1ea92..eeeb9ac 100644 --- a/apps/attestation-manager/src/credentialDef/tests/service.spec.ts +++ b/apps/attestation-manager/src/credentialDef/tests/service.spec.ts @@ -1,7 +1,10 @@ +import type { TestingModule } from '@nestjs/testing'; +import type { CredentialDef } from '@prisma/client'; + import { HttpModule } from '@nestjs/axios'; import { ConfigService } from '@nestjs/config'; -import { Test, TestingModule } from '@nestjs/testing'; -import { CredentialDef } from '@prisma/client'; +import { Test } from '@nestjs/testing'; + import NatsClientService from '../../client/nats.client.js'; import RestClientService from '../../client/rest.client.js'; import NatsClientServiceMock from '../../client/tests/__mocks__/nats.client.js'; @@ -11,6 +14,7 @@ import PrismaServiceMock from '../../prisma/tests/__mocks__/prisma.service.js'; import SchemasService from '../../schemas/services/service.js'; import SchemasServiceMock from '../../schemas/tests/__mocks__/service.js'; import CredentialDefService from '../services/service.js'; + import credDefStub from './stubs/credDef.stub.js'; describe('CredentialDefService', () => { diff --git a/apps/attestation-manager/src/credentialDef/tests/stubs/credDef.stub.ts b/apps/attestation-manager/src/credentialDef/tests/stubs/credDef.stub.ts index 47de079..609a440 100644 --- a/apps/attestation-manager/src/credentialDef/tests/stubs/credDef.stub.ts +++ b/apps/attestation-manager/src/credentialDef/tests/stubs/credDef.stub.ts @@ -1,4 +1,4 @@ -import CredentialDefDto from '../../entities/credentialDef-entity.js'; +import type CredentialDefDto from '../../entities/credentialDef-entity.js'; const credDefStub = (): CredentialDefDto => ({ diff --git a/apps/attestation-manager/src/health/health.controller.ts b/apps/attestation-manager/src/health/health.controller.ts index e8deabc..95f4367 100644 --- a/apps/attestation-manager/src/health/health.controller.ts +++ b/apps/attestation-manager/src/health/health.controller.ts @@ -1,10 +1,11 @@ +import type { ResponseType } from '../common/response.js'; + import { Controller, Get, HttpStatus, Version } from '@nestjs/common'; import { ApiOperation, ApiResponse } from '@nestjs/swagger'; -import { ResponseType } from '../common/response.js'; @Controller('health') export default class HealthController { - res: ResponseType; + public res: ResponseType; @Version(['1']) @Get() @@ -31,7 +32,7 @@ export default class HealthController { }, }, }) - getHealth() { + public getHealth() { this.res = { statusCode: HttpStatus.OK, message: `${new Date()}`, diff --git a/apps/attestation-manager/src/health/tests/health.controller.spec.ts b/apps/attestation-manager/src/health/tests/health.controller.spec.ts index 1d7863a..ead02b5 100644 --- a/apps/attestation-manager/src/health/tests/health.controller.spec.ts +++ b/apps/attestation-manager/src/health/tests/health.controller.spec.ts @@ -1,6 +1,9 @@ +import type { ResponseType } from '../../common/response.js'; +import type { TestingModule } from '@nestjs/testing'; + import { HttpStatus } from '@nestjs/common'; -import { Test, TestingModule } from '@nestjs/testing'; -import { ResponseType } from '../../common/response.js'; +import { Test } from '@nestjs/testing'; + import HealthController from '../health.controller.js'; describe('HealthController', () => { diff --git a/apps/attestation-manager/src/issue-credential/controller/controller.ts b/apps/attestation-manager/src/issue-credential/controller/controller.ts index 1939b26..c3fb696 100644 --- a/apps/attestation-manager/src/issue-credential/controller/controller.ts +++ b/apps/attestation-manager/src/issue-credential/controller/controller.ts @@ -1,3 +1,7 @@ +import type { ResponseType } from '../../common/response.js'; +import type CredentialDto from '../entities/credential.entity.js'; +import type CredentialStateDto from '../entities/credential.state.entity.js'; + import { BadRequestException, Body, @@ -26,19 +30,17 @@ import { ApiTags, } from '@nestjs/swagger'; import { Prisma } from '@prisma/client'; -import type { Response } from 'express'; +import { Response } from 'express'; + import { Abstraction, NATSServices, PrismaErrorCode, } from '../../common/constants.js'; -import { ResponseType } from '../../common/response.js'; import CredentialDefService from '../../credentialDef/services/service.js'; import SchemasService from '../../schemas/services/service.js'; import UserInfoService from '../../userInfo/services/service.js'; import logger from '../../utils/logger.js'; -import CredentialDto from '../entities/credential.entity.js'; -import CredentialStateDto from '../entities/credential.state.entity.js'; import CredentialTypeDto from '../entities/credentialType.entity.js'; import OfferCredentialDto from '../entities/entity.js'; import GetIssueCredentialsDto from '../entities/get-issue-credentials.dto.js'; @@ -51,9 +53,9 @@ import AttestationService from '../services/service.js'; @ApiTags('Credentials') @Controller() export default class AttestationController { - name: string; + public name: string; - constructor( + public constructor( private readonly attestationService: AttestationService, private readonly credentialDefService: CredentialDefService, private readonly userInfoService: UserInfoService, @@ -213,7 +215,7 @@ export default class AttestationController { }, }, }) - async createOfferCredential( + public async createOfferCredential( @Body() connectionCreate: OfferCredentialDto, @Res() response: Response, ) { @@ -392,7 +394,7 @@ export default class AttestationController { }, }, }) - async createProposeCredential( + public async createProposeCredential( @Body() connectionCreate: ProposeCredentialDto, @Res() response: Response, ) { @@ -428,7 +430,9 @@ export default class AttestationController { description: 'Accept a credential request as issuer (by sending a credential message) to the connection associated with the credential record.', }) - async acceptOfferCredential(@Param() params: { credentialId: string }) { + public async acceptOfferCredential( + @Param() params: { credentialId: string }, + ) { try { const res: ResponseType = { statusCode: HttpStatus.ACCEPTED, @@ -450,7 +454,9 @@ export default class AttestationController { description: 'Accept a credential proposal as issuer (by sending a credential offer message) to the connection associated with the credential record.', }) - async acceptProposeCredential(@Param() params: { credentialId: string }) { + public async acceptProposeCredential( + @Param() params: { credentialId: string }, + ) { try { if (!params.credentialId) { throw new BadRequestException('Invalid credential ID'); @@ -479,7 +485,9 @@ export default class AttestationController { description: 'Accept a credential offer as holder (by sending a credential request message) to the connection associated with the credential record.', }) - async acceptCredentialOffer(@Param() params: { credentialId: string }) { + public async acceptCredentialOffer( + @Param() params: { credentialId: string }, + ) { try { if (!params.credentialId) { throw new BadRequestException('Invalid credential ID'); @@ -508,7 +516,7 @@ export default class AttestationController { description: 'Accept a credential as holder (by sending a credential acknowledgement message) to the connection associated with the credential record.', }) - async acceptCredential(@Param() params: { credentialId: string }) { + public async acceptCredential(@Param() params: { credentialId: string }) { try { if (!params.credentialId) { throw new BadRequestException('Invalid credential ID'); @@ -535,7 +543,9 @@ export default class AttestationController { @EventPattern({ endpoint: `${Abstraction.NATS_ENDPOINT}/${Abstraction.CREDENTIAL_STATE_CHANGED}`, }) - async webHookCredentials(body: { credentialRecord: CredentialStateDto }) { + public async webHookCredentials(body: { + credentialRecord: CredentialStateDto; + }) { const credentialsCreate = body.credentialRecord; logger.info( `credentials webhook call data ${JSON.stringify(credentialsCreate)}`, @@ -586,7 +596,9 @@ export default class AttestationController { credentialsType?.schemaId === credentialObj.schemaId && credentialsCreate.state === AttestationService.status.DONE ) { - this.attestationService.connectionTrusted(credentialObj.connectionId); + await this.attestationService.connectionTrusted( + credentialObj.connectionId, + ); } res = { statusCode: HttpStatus.OK, @@ -638,7 +650,7 @@ export default class AttestationController { }, }, }) - async getCredentialInfo( + public async getCredentialInfo( @Param() params: GetCredentialParams, @Res() response: Response, ) { @@ -730,7 +742,7 @@ export default class AttestationController { }, }, }) - async deleteCredential( + public async deleteCredential( @Param() params: GetCredentialParams, @Res() response: Response, ) { @@ -852,7 +864,7 @@ export default class AttestationController { }, }, }) - async getCredentialList( + public async getCredentialList( @Query() query: GetCredentialQuery, @Res() response: Response, ) { @@ -1002,7 +1014,7 @@ export default class AttestationController { }, }, }) - async getCredential( + public async getCredential( @Param() params: GetCredentialParams, @Query() query: GetCredentialQuery, @Res() response: Response, @@ -1039,7 +1051,7 @@ export default class AttestationController { @MessagePattern({ endpoint: `${NATSServices.SERVICE_NAME}/offerMemberShipCredentials`, }) - async offerMemberShipCredentials(data: { + public async offerMemberShipCredentials(data: { status: string; connectionId: string; theirLabel: string; @@ -1214,7 +1226,7 @@ export default class AttestationController { }, }, }) - async updateSchemaIdByType( + public async updateSchemaIdByType( @Body() body: { schemaId: string }, @Query() query: { type: string }, ) { @@ -1287,7 +1299,7 @@ export default class AttestationController { }, }, }) - async createCredentialType(@Body() body: CredentialTypeDto) { + public async createCredentialType(@Body() body: CredentialTypeDto) { try { const res: ResponseType = { statusCode: HttpStatus.CREATED, @@ -1303,14 +1315,14 @@ export default class AttestationController { @MessagePattern({ endpoint: `${NATSServices.SERVICE_NAME}/getIssueCredentials`, }) - async getIssueCredentials(data: GetIssueCredentialsDto) { + public async getIssueCredentials(data: GetIssueCredentialsDto) { return this.attestationService.getIssueCredentials(data); } @MessagePattern({ endpoint: `${NATSServices.SERVICE_NAME}/getCredentialsTypeDetails`, }) - async getCredentialsTypeDetails(data: { type: string }) { + public async getCredentialsTypeDetails(data: { type: string }) { let res; const credentialsType = @@ -1407,7 +1419,7 @@ export default class AttestationController { }, }, }) - async getCredentialTypeAttributes(@Query() query: { type: string }) { + public async getCredentialTypeAttributes(@Query() query: { type: string }) { let res; const credentialsType = diff --git a/apps/attestation-manager/src/issue-credential/entities/credential.entity.ts b/apps/attestation-manager/src/issue-credential/entities/credential.entity.ts index 8d6043d..86e6f32 100644 --- a/apps/attestation-manager/src/issue-credential/entities/credential.entity.ts +++ b/apps/attestation-manager/src/issue-credential/entities/credential.entity.ts @@ -3,35 +3,35 @@ import { IsString, IsNotEmpty } from 'class-validator'; export default class CredentialDto { @IsString() @IsNotEmpty() - credentialId: string; + public credentialId: string; @IsString() @IsNotEmpty() - credDefId: string; + public credDefId: string; @IsString() - schemaId?: string; + public schemaId?: string; @IsString() @IsNotEmpty() - participantId?: string; + public participantId?: string; @IsString() @IsNotEmpty() - principalDid?: string; + public principalDid?: string; @IsString() @IsNotEmpty() - state: string; + public state: string; @IsString() @IsNotEmpty() - threadId: string; + public threadId: string; @IsString() @IsNotEmpty() - connectionId: string; + public connectionId: string; @IsString() - expirationDate?: Date | null; + public expirationDate?: Date | null; } diff --git a/apps/attestation-manager/src/issue-credential/entities/credential.state.entity.ts b/apps/attestation-manager/src/issue-credential/entities/credential.state.entity.ts index 845fc48..b06cb92 100644 --- a/apps/attestation-manager/src/issue-credential/entities/credential.state.entity.ts +++ b/apps/attestation-manager/src/issue-credential/entities/credential.state.entity.ts @@ -3,10 +3,10 @@ import { IsString, IsNotEmpty } from 'class-validator'; export default class CredentialStateDto { @IsString() @IsNotEmpty() - id: string; + public id: string; @IsNotEmpty() - metadata: { + public metadata: { '_internal/indyCredential': { credentialDefinitionId: string; schemaId: string; @@ -15,17 +15,17 @@ export default class CredentialStateDto { @IsString() @IsNotEmpty() - credDefId: string; + public credDefId: string; @IsString() @IsNotEmpty() - state: string; + public state: string; @IsString() @IsNotEmpty() - threadId: string; + public threadId: string; @IsString() @IsNotEmpty() - connectionId: string; + public connectionId: string; } diff --git a/apps/attestation-manager/src/issue-credential/entities/credentialType.entity.ts b/apps/attestation-manager/src/issue-credential/entities/credentialType.entity.ts index f5734f1..0b1e522 100644 --- a/apps/attestation-manager/src/issue-credential/entities/credentialType.entity.ts +++ b/apps/attestation-manager/src/issue-credential/entities/credentialType.entity.ts @@ -3,15 +3,15 @@ import { IsNotEmpty, IsString } from 'class-validator'; export default class CredentialTypeDto { @IsString() - id?: string; + public id?: string; @IsString() @IsNotEmpty() @ApiProperty() - type: string; + public type: string; @IsString() @IsNotEmpty() @ApiProperty() - schemaId: string; + public schemaId: string; } diff --git a/apps/attestation-manager/src/issue-credential/entities/entity.ts b/apps/attestation-manager/src/issue-credential/entities/entity.ts index 8166611..76ae7ba 100644 --- a/apps/attestation-manager/src/issue-credential/entities/entity.ts +++ b/apps/attestation-manager/src/issue-credential/entities/entity.ts @@ -5,33 +5,33 @@ class CredentialPreviewAttributes { @IsString() @IsNotEmpty() @ApiProperty() - name: string; + public name: string; @IsString() @ApiProperty() - value: string; + public value: string; } export default class OfferCredentialDto { @IsString() @IsNotEmpty() @ApiProperty() - connectionId: string; + public connectionId: string; @IsString() @IsNotEmpty() @ApiProperty() - credentialDefinitionId: string; + public credentialDefinitionId: string; @IsString() @IsNotEmpty() @ApiProperty() - comment: string; + public comment: string; @ApiProperty({ type: [CredentialPreviewAttributes] }) - attributes: CredentialPreviewAttributes[]; + public attributes: CredentialPreviewAttributes[]; @IsString() @IsNotEmpty() @ApiProperty() - autoAcceptCredential: string; + public autoAcceptCredential: string; } diff --git a/apps/attestation-manager/src/issue-credential/entities/get-issue-credentials.dto.ts b/apps/attestation-manager/src/issue-credential/entities/get-issue-credentials.dto.ts index efd99a2..b573e08 100644 --- a/apps/attestation-manager/src/issue-credential/entities/get-issue-credentials.dto.ts +++ b/apps/attestation-manager/src/issue-credential/entities/get-issue-credentials.dto.ts @@ -2,5 +2,5 @@ import { IsString } from 'class-validator'; export default class GetIssueCredentialsDto { @IsString() - connectionId: string; + public connectionId: string; } diff --git a/apps/attestation-manager/src/issue-credential/entities/get.credential.params.ts b/apps/attestation-manager/src/issue-credential/entities/get.credential.params.ts index 12c0cdf..61be5db 100644 --- a/apps/attestation-manager/src/issue-credential/entities/get.credential.params.ts +++ b/apps/attestation-manager/src/issue-credential/entities/get.credential.params.ts @@ -2,5 +2,5 @@ import { IsString } from 'class-validator'; export default class GetCredentialParams { @IsString() - id: string; + public id: string; } diff --git a/apps/attestation-manager/src/issue-credential/entities/get.credential.query.ts b/apps/attestation-manager/src/issue-credential/entities/get.credential.query.ts index 3f99041..47130d5 100644 --- a/apps/attestation-manager/src/issue-credential/entities/get.credential.query.ts +++ b/apps/attestation-manager/src/issue-credential/entities/get.credential.query.ts @@ -2,44 +2,44 @@ import { IsBoolean, IsString, IsDateString } from 'class-validator'; export default class GetCredentialQuery { @IsString() - page?: string; + public page?: string; @IsString() - pageSize?: string; + public pageSize?: string; @IsString() - threadId?: string; + public threadId?: string; @IsBoolean() - isReceived?: boolean | string; + public isReceived?: boolean | string; @IsString() - state?: string; + public state?: string; @IsString() - credDefId?: string; + public credDefId?: string; @IsDateString() - createdDateStart?: string; + public createdDateStart?: string; @IsDateString() - createdDateEnd?: string; + public createdDateEnd?: string; @IsDateString() - updatedDateStart?: string; + public updatedDateStart?: string; @IsDateString() - updatedDateEnd?: string; + public updatedDateEnd?: string; @IsDateString() - expirationDateStart?: string; + public expirationDateStart?: string; @IsDateString() - expirationDateEnd?: string; + public expirationDateEnd?: string; @IsString() - connectionId?: string; + public connectionId?: string; @IsString() - principalDid?: string; + public principalDid?: string; } diff --git a/apps/attestation-manager/src/issue-credential/entities/propose-credential.dto.ts b/apps/attestation-manager/src/issue-credential/entities/propose-credential.dto.ts index c1cc2ee..1d5e9cb 100644 --- a/apps/attestation-manager/src/issue-credential/entities/propose-credential.dto.ts +++ b/apps/attestation-manager/src/issue-credential/entities/propose-credential.dto.ts @@ -5,22 +5,22 @@ export default class ProposeCredentialDto { @IsString() @IsNotEmpty() @ApiProperty() - connectionId: string; + public connectionId: string; @IsString() @IsNotEmpty() @ApiProperty() - credentialDefinitionId: string; + public credentialDefinitionId: string; @IsString() @IsNotEmpty() @ApiProperty() - comment: string; + public comment: string; @IsString() @IsNotEmpty() @ApiProperty() - credentialProposal: { + public credentialProposal: { '@type': string; attributes: { name: string; @@ -31,5 +31,5 @@ export default class ProposeCredentialDto { @IsString() @IsNotEmpty() @ApiProperty() - autoAcceptCredential: string; + public autoAcceptCredential: string; } diff --git a/apps/attestation-manager/src/issue-credential/entities/updatecredDefIdByType.entity.ts b/apps/attestation-manager/src/issue-credential/entities/updatecredDefIdByType.entity.ts index d141e87..a28aae6 100644 --- a/apps/attestation-manager/src/issue-credential/entities/updatecredDefIdByType.entity.ts +++ b/apps/attestation-manager/src/issue-credential/entities/updatecredDefIdByType.entity.ts @@ -5,5 +5,5 @@ export default class UpdateSchemaIdByTypeDto { @IsString() @IsNotEmpty() @ApiProperty() - schemaId: string; + public schemaId: string; } diff --git a/apps/attestation-manager/src/issue-credential/module.ts b/apps/attestation-manager/src/issue-credential/module.ts index 31d05fe..8a27b1d 100644 --- a/apps/attestation-manager/src/issue-credential/module.ts +++ b/apps/attestation-manager/src/issue-credential/module.ts @@ -1,6 +1,7 @@ import { HttpModule } from '@nestjs/axios'; import { Module } from '@nestjs/common'; import { ClientsModule, Transport } from '@nestjs/microservices'; + import NatsClientService from '../client/nats.client.js'; import RestClientService from '../client/rest.client.js'; import TSAClientService from '../client/tsa.client.js'; @@ -10,6 +11,7 @@ import CredentialDefService from '../credentialDef/services/service.js'; import PrismaService from '../prisma/prisma.service.js'; import SchemasService from '../schemas/services/service.js'; import UserInfoService from '../userInfo/services/service.js'; + import AttestationController from './controller/controller.js'; import AttestationService from './services/service.js'; diff --git a/apps/attestation-manager/src/issue-credential/repository/credential.repository.ts b/apps/attestation-manager/src/issue-credential/repository/credential.repository.ts index 7d8183a..bc4d9f1 100644 --- a/apps/attestation-manager/src/issue-credential/repository/credential.repository.ts +++ b/apps/attestation-manager/src/issue-credential/repository/credential.repository.ts @@ -1,12 +1,14 @@ +import type { Prisma } from '@prisma/client'; + import { Injectable } from '@nestjs/common'; -import { Prisma } from '@prisma/client'; + import PrismaService from '../../prisma/prisma.service.js'; @Injectable() export default class CredentialRepository { - constructor(private readonly prismaService: PrismaService) {} + public constructor(private readonly prismaService: PrismaService) {} - async createCredential(data: Prisma.CredentialCreateInput) { + public async createCredential(data: Prisma.CredentialCreateInput) { const credential = await this.prismaService.credential.create({ data }); const credDef = await this.prismaService.credentialDef.findFirst({ @@ -33,7 +35,7 @@ export default class CredentialRepository { return credential; } - async findUniqueCredential(params: { + public async findUniqueCredential(params: { where: Prisma.CredentialWhereUniqueInput; }) { const { where } = params; @@ -42,7 +44,7 @@ export default class CredentialRepository { }); } - async updateCredential(params: { + public async updateCredential(params: { where: Prisma.CredentialWhereUniqueInput; data: Prisma.CredentialUpdateInput; }) { @@ -53,7 +55,7 @@ export default class CredentialRepository { }); } - async findCredential(params: { + public async findCredential(params: { skip?: number; take?: number; cursor?: Prisma.CredentialWhereUniqueInput; @@ -78,7 +80,9 @@ export default class CredentialRepository { ]); } - async deleteCredential(params: { where: Prisma.CredentialWhereUniqueInput }) { + public async deleteCredential(params: { + where: Prisma.CredentialWhereUniqueInput; + }) { const { where } = params; return this.prismaService.credential.delete({ diff --git a/apps/attestation-manager/src/issue-credential/repository/credentialType.repository.ts b/apps/attestation-manager/src/issue-credential/repository/credentialType.repository.ts index 8f9438a..4be0ada 100644 --- a/apps/attestation-manager/src/issue-credential/repository/credentialType.repository.ts +++ b/apps/attestation-manager/src/issue-credential/repository/credentialType.repository.ts @@ -1,16 +1,20 @@ +import type { Prisma } from '@prisma/client'; + import { Injectable } from '@nestjs/common'; -import { Prisma } from '@prisma/client'; + import PrismaService from '../../prisma/prisma.service.js'; @Injectable() export default class CredentialsTypeRepository { - constructor(private readonly prismaService: PrismaService) {} + public constructor(private readonly prismaService: PrismaService) {} - async createCredentialsType(data: Prisma.CredentialsTypeCreateInput) { + public async createCredentialsType(data: Prisma.CredentialsTypeCreateInput) { return this.prismaService.credentialsType.create({ data }); } - async createOrUpdateCredentialsType(data: Prisma.CredentialsTypeCreateInput) { + public async createOrUpdateCredentialsType( + data: Prisma.CredentialsTypeCreateInput, + ) { const credentialType = await this.prismaService.credentialsType.findFirst({ where: { type: { @@ -50,7 +54,7 @@ export default class CredentialsTypeRepository { }); } - async findUniqueCredentialsType(data: { type: string }) { + public async findUniqueCredentialsType(data: { type: string }) { return this.prismaService.credentialsType.findFirst({ where: { type: { @@ -62,7 +66,7 @@ export default class CredentialsTypeRepository { } // TODO check - async updateCredentialsType(params: { + public async updateCredentialsType(params: { where: Prisma.CredentialsTypeWhereUniqueInput; data: Prisma.CredentialsTypeUpdateInput; }) { @@ -73,7 +77,7 @@ export default class CredentialsTypeRepository { }); } - async findCredentialsType(params: { + public async findCredentialsType(params: { skip?: number; take?: number; cursor?: Prisma.CredentialsTypeWhereUniqueInput; diff --git a/apps/attestation-manager/src/issue-credential/services/service.ts b/apps/attestation-manager/src/issue-credential/services/service.ts index 9a73e13..22d2534 100644 --- a/apps/attestation-manager/src/issue-credential/services/service.ts +++ b/apps/attestation-manager/src/issue-credential/services/service.ts @@ -1,10 +1,17 @@ +import type CredentialDto from '../entities/credential.entity.js'; +import type CredentialTypeDto from '../entities/credentialType.entity.js'; +import type OfferCredentialDto from '../entities/entity.js'; +import type GetIssueCredentialsDto from '../entities/get-issue-credentials.dto.js'; +import type ProposeCredentialDto from '../entities/propose-credential.dto.js'; +import type { Credential, Prisma } from '@prisma/client'; + import { BadRequestException, Injectable, PreconditionFailedException, } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; -import { Credential, Prisma } from '@prisma/client'; + import NatsClientService from '../../client/nats.client.js'; import RestClientService from '../../client/rest.client.js'; import TSAClientService from '../../client/tsa.client.js'; @@ -14,11 +21,6 @@ import PrismaService from '../../prisma/prisma.service.js'; import Utils from '../../utils/common.js'; import logger from '../../utils/logger.js'; import pagination from '../../utils/pagination.js'; -import CredentialDto from '../entities/credential.entity.js'; -import CredentialTypeDto from '../entities/credentialType.entity.js'; -import OfferCredentialDto from '../entities/entity.js'; -import GetIssueCredentialsDto from '../entities/get-issue-credentials.dto.js'; -import ProposeCredentialDto from '../entities/propose-credential.dto.js'; import CredentialRepository from '../repository/credential.repository.js'; import CredentialsTypeRepository from '../repository/credentialType.repository.js'; @@ -28,7 +30,7 @@ export default class AttestationService { private credentialRepositoryType: CredentialsTypeRepository; - constructor( + public constructor( private readonly credDefService: CredentialDefService, private readonly prismaService: PrismaService, private readonly restClient: RestClientService, @@ -42,7 +44,7 @@ export default class AttestationService { ); } - static readonly status = { + public static readonly status = { OFFER_SENT: 'offer-sent', PROPOSAL_SENT: 'proposal-sent', REQUEST_RECEIVED: 'request-received', @@ -50,13 +52,14 @@ export default class AttestationService { OFFER_RECEIVED: 'offer-received', }; - static readonly principalMemberCredential = 'principalMemberCredential'; + public static readonly principalMemberCredential = + 'principalMemberCredential'; - static readonly connectionStatus = { + public static readonly connectionStatus = { TRUSTED: 'trusted', }; - async createOfferCredential( + public async createOfferCredential( credentialRequest: OfferCredentialDto, isTrustedConnectionRequired = false, ) { @@ -138,7 +141,7 @@ export default class AttestationService { } } - async proposeCredential(connectionCreate: ProposeCredentialDto) { + public async proposeCredential(connectionCreate: ProposeCredentialDto) { const agentUrl = this.configService.get('agent.AGENT_URL'); const connectionCreateObj = { ...connectionCreate }; try { @@ -154,7 +157,7 @@ export default class AttestationService { } } - async acceptRequestCredential(credentialId: string) { + public async acceptRequestCredential(credentialId: string) { const agentUrl = this.configService.get('agent.AGENT_URL'); const responseData = await this.restClient.post( @@ -165,7 +168,7 @@ export default class AttestationService { return responseData; } - async acceptProposeCredential(credentialId: string) { + public async acceptProposeCredential(credentialId: string) { const agentUrl = this.configService.get('agent.AGENT_URL'); const responseData = await this.restClient.post( `${agentUrl}/credentials/${credentialId}/accept-proposal`, @@ -175,7 +178,7 @@ export default class AttestationService { return responseData; } - async acceptCredentialOffer(credentialId: string) { + public async acceptCredentialOffer(credentialId: string) { const agentUrl = this.configService.get('agent.AGENT_URL'); const responseData = await this.restClient.post( `${agentUrl}/credentials/${credentialId}/accept-offer`, @@ -185,7 +188,7 @@ export default class AttestationService { return responseData; } - async acceptCredential(credentialId: string) { + public async acceptCredential(credentialId: string) { const agentUrl = this.configService.get('agent.AGENT_URL'); const responseData = await this.restClient.post( `${agentUrl}/credentials/${credentialId}/accept-credential`, @@ -195,7 +198,7 @@ export default class AttestationService { return responseData; } - async createCredential(credential: CredentialDto) { + public async createCredential(credential: CredentialDto) { const connection = await this.getConnectionByID(credential.connectionId); const credDef = await this.findCredDef(credential.credDefId); @@ -213,12 +216,12 @@ export default class AttestationService { }); } - async getConnectionByID(connectionID: string) { + public async getConnectionByID(connectionID: string) { const connection = await this.natsClient.getConnectionById(connectionID); return connection; } - async updateCredential(credential: CredentialDto) { + public async updateCredential(credential: CredentialDto) { return this.credentialRepository.updateCredential({ where: { credentialId: credential.credentialId }, data: { @@ -228,17 +231,17 @@ export default class AttestationService { }); } - findCredentialById(credentialId: string) { + public findCredentialById(credentialId: string) { const where: Prisma.CredentialWhereUniqueInput = { credentialId }; return this.credentialRepository.findUniqueCredential({ where }); } - findCredentialByThreadId(threadId: string) { + public findCredentialByThreadId(threadId: string) { const where: Prisma.CredentialWhereUniqueInput = { threadId }; return this.credentialRepository.findUniqueCredential({ where }); } - async findCredential( + public async findCredential( pageSize: number, page: number, isReceived: boolean, @@ -326,7 +329,7 @@ export default class AttestationService { return this.credentialRepository.findCredential(query); } - async issueMemberCredentials(data: { + public async issueMemberCredentials(data: { status: string; connectionId: string; theirLabel: string; @@ -361,11 +364,11 @@ export default class AttestationService { return result; } - getPrincipalMemberShipCredentials(data: { type: string }) { + public getPrincipalMemberShipCredentials(data: { type: string }) { return this.credentialRepositoryType.findUniqueCredentialsType(data); } - async getSchemaAndAttributesBySchemaIDFromLedger(schemaID: string) { + public async getSchemaAndAttributesBySchemaIDFromLedger(schemaID: string) { const agentUrl = this.configService.get('agent.AGENT_URL'); const responseData = await this.restClient.get( `${agentUrl}/schemas/${schemaID}`, @@ -378,7 +381,7 @@ export default class AttestationService { return responseData; } - updateSchemaByType(type: string, body: { schemaId: string }) { + public updateSchemaByType(type: string, body: { schemaId: string }) { return this.credentialRepositoryType.updateCredentialsType({ where: { type, @@ -389,7 +392,7 @@ export default class AttestationService { }); } - async getIssueCredentials(data: GetIssueCredentialsDto) { + public async getIssueCredentials(data: GetIssueCredentialsDto) { return this.credentialRepository.findCredential({ where: { connectionId: data.connectionId, @@ -397,7 +400,7 @@ export default class AttestationService { }); } - async getCredentialInformation(credentialId: string) { + public async getCredentialInformation(credentialId: string) { const agentUrl = this.configService.get('agent.AGENT_URL'); const responseData = await this.restClient.get( `${agentUrl}/credentials/${credentialId}`, @@ -410,7 +413,7 @@ export default class AttestationService { return responseData; } - async deleteCredential(credentialId: string) { + public async deleteCredential(credentialId: string) { const agentUrl = this.configService.get('agent.AGENT_URL'); const responseData = await this.restClient.delete( `${agentUrl}/credentials/${credentialId}`, @@ -425,18 +428,18 @@ export default class AttestationService { return responseData; } - createCredentialsType(credentialType: CredentialTypeDto) { + public createCredentialsType(credentialType: CredentialTypeDto) { return this.credentialRepositoryType.createCredentialsType({ type: credentialType.type, schemaId: credentialType.schemaId, }); } - connectionTrusted(connectionId: string) { + public connectionTrusted(connectionId: string) { return this.natsClient.connectionTrusted(connectionId); } - async findCredDef(credentialDefinitionId: string) { + public async findCredDef(credentialDefinitionId: string) { const credDefRes = await this.credDefService.findCredentialDefById( credentialDefinitionId, ); @@ -451,7 +454,7 @@ export default class AttestationService { return credDefRes[1][0]; } - async findReceivedCredentials() { + public async findReceivedCredentials() { try { let result: Credential[] = []; const receivedConnections = diff --git a/apps/attestation-manager/src/issue-credential/tests/controller.spec.ts b/apps/attestation-manager/src/issue-credential/tests/controller.spec.ts index 460fe18..6efe1de 100644 --- a/apps/attestation-manager/src/issue-credential/tests/controller.spec.ts +++ b/apps/attestation-manager/src/issue-credential/tests/controller.spec.ts @@ -1,11 +1,19 @@ +import type { ResponseType } from '../../common/response.js'; +import type CredentialDto from '../entities/credential.entity.js'; +import type CredentialStateDto from '../entities/credential.state.entity.js'; +import type CredentialTypeDto from '../entities/credentialType.entity.js'; +import type GetCredentialParams from '../entities/get.credential.params.js'; +import type GetCredentialQuery from '../entities/get.credential.query.js'; +import type { TestingModule } from '@nestjs/testing'; +import type { Response } from 'express'; + import { HttpStatus } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { ClientsModule, Transport } from '@nestjs/microservices'; -import { Test, TestingModule } from '@nestjs/testing'; -import { Response } from 'express'; -import httpMocks from 'node-mocks-http'; +import { Test } from '@nestjs/testing'; +import { createResponse } from 'node-mocks-http'; + import { NATSServices } from '../../common/constants.js'; -import { ResponseType } from '../../common/response.js'; import CredentialDefService from '../../credentialDef/services/service.js'; import CredentialDefServiceMock from '../../credentialDef/tests/__mocks__/service.js'; import SchemasService from '../../schemas/services/service.js'; @@ -13,12 +21,8 @@ import SchemasServiceMock from '../../schemas/tests/__mocks__/service.js'; import UserInfoService from '../../userInfo/services/service.js'; import UserInfoServiceMock from '../../userInfo/tests/__mocks__/service.js'; import AttestationController from '../controller/controller.js'; -import CredentialDto from '../entities/credential.entity.js'; -import CredentialStateDto from '../entities/credential.state.entity.js'; -import CredentialTypeDto from '../entities/credentialType.entity.js'; -import GetCredentialParams from '../entities/get.credential.params.js'; -import GetCredentialQuery from '../entities/get.credential.query.js'; import AttestationService from '../services/service.js'; + import AttestationServiceMock from './__mocks__/service.js'; import credentialDto from './stubs/credential-dto.js'; import credentialStateDto from './stubs/credential-state-dto.js'; @@ -172,7 +176,7 @@ describe('AttestationController', () => { }); describe('getCredential()', () => { - let attestationResponse: Response<string, Record<string, any>>; + let attestationResponse: Response<string, Record<string, unknown>>; let params: GetCredentialParams; let query: GetCredentialQuery; @@ -182,7 +186,7 @@ describe('AttestationController', () => { state: credentialDto().state, }; - const response = httpMocks.createResponse(); + const response = createResponse(); attestationResponse = await attestationController.getCredential( params, query, diff --git a/apps/attestation-manager/src/issue-credential/tests/module.spec.ts b/apps/attestation-manager/src/issue-credential/tests/module.spec.ts index 5ba9aaf..2a6c800 100644 --- a/apps/attestation-manager/src/issue-credential/tests/module.spec.ts +++ b/apps/attestation-manager/src/issue-credential/tests/module.spec.ts @@ -1,5 +1,8 @@ +import type { TestingModule } from '@nestjs/testing'; + import { HttpModule } from '@nestjs/axios'; -import { Test, TestingModule } from '@nestjs/testing'; +import { Test } from '@nestjs/testing'; + import NatsClientService from '../../client/nats.client.js'; import RestClientService from '../../client/rest.client.js'; import NatsClientServiceMock from '../../client/tests/__mocks__/nats.client.js'; @@ -10,6 +13,7 @@ import PrismaService from '../../prisma/prisma.service.js'; import PrismaServiceMock from '../../prisma/tests/__mocks__/prisma.service.js'; import AttestationModule from '../module.js'; import AttestationService from '../services/service.js'; + import AttestationServiceMock from './__mocks__/service.js'; describe('AttestationModule', () => { diff --git a/apps/attestation-manager/src/issue-credential/tests/service.spec.ts b/apps/attestation-manager/src/issue-credential/tests/service.spec.ts index 51f36e3..eb985da 100644 --- a/apps/attestation-manager/src/issue-credential/tests/service.spec.ts +++ b/apps/attestation-manager/src/issue-credential/tests/service.spec.ts @@ -1,7 +1,11 @@ +import type { ResponseType } from '../../common/response.js'; +import type { TestingModule } from '@nestjs/testing'; +import type { Credential, CredentialsType } from '@prisma/client'; + import { HttpModule } from '@nestjs/axios'; import { ConfigService } from '@nestjs/config'; -import { Test, TestingModule } from '@nestjs/testing'; -import { Credential, CredentialsType } from '@prisma/client'; +import { Test } from '@nestjs/testing'; + import NatsClientService from '../../client/nats.client.js'; import RestClientService from '../../client/rest.client.js'; import NatsClientServiceMock from '../../client/tests/__mocks__/nats.client.js'; @@ -9,12 +13,12 @@ import RestClientServiceMock from '../../client/tests/__mocks__/rest.client.js'; import TSAClientServiceMock from '../../client/tests/__mocks__/tsa.client.js'; import { natsConnectionResponse } from '../../client/tests/stubs/nats-response.js'; import TSAClientService from '../../client/tsa.client.js'; -import { ResponseType } from '../../common/response.js'; import CredentialDefService from '../../credentialDef/services/service.js'; import CredentialDefServiceMock from '../../credentialDef/tests/__mocks__/service.js'; import PrismaService from '../../prisma/prisma.service.js'; import PrismaServiceMock from '../../prisma/tests/__mocks__/prisma.service.js'; import AttestationService from '../services/service.js'; + import credentialDto from './stubs/credential-dto.js'; import credentialsTypeDto from './stubs/credential-type-dto.js'; diff --git a/apps/attestation-manager/src/issue-credential/tests/stubs/credential-dto.ts b/apps/attestation-manager/src/issue-credential/tests/stubs/credential-dto.ts index 6776e5d..fab4af5 100644 --- a/apps/attestation-manager/src/issue-credential/tests/stubs/credential-dto.ts +++ b/apps/attestation-manager/src/issue-credential/tests/stubs/credential-dto.ts @@ -1,5 +1,6 @@ +import type CredentialDto from '../../entities/credential.entity.js'; + import credDefStub from '../../../credentialDef/tests/stubs/credDef.stub.js'; -import CredentialDto from '../../entities/credential.entity.js'; import AttestationService from '../../services/service.js'; const credentialDto = (): CredentialDto => ({ diff --git a/apps/attestation-manager/src/issue-credential/tests/stubs/credential-state-dto.ts b/apps/attestation-manager/src/issue-credential/tests/stubs/credential-state-dto.ts index 945c1e9..f0fbf80 100644 --- a/apps/attestation-manager/src/issue-credential/tests/stubs/credential-state-dto.ts +++ b/apps/attestation-manager/src/issue-credential/tests/stubs/credential-state-dto.ts @@ -1,5 +1,7 @@ +import type CredentialStateDto from '../../entities/credential.state.entity.js'; + import credDefStub from '../../../credentialDef/tests/stubs/credDef.stub.js'; -import CredentialStateDto from '../../entities/credential.state.entity.js'; + import credentialDto from './credential-dto.js'; const credentialStateDto = (): CredentialStateDto => ({ diff --git a/apps/attestation-manager/src/issue-credential/tests/stubs/credential-type-dto.ts b/apps/attestation-manager/src/issue-credential/tests/stubs/credential-type-dto.ts index 67a9a04..1a888d0 100644 --- a/apps/attestation-manager/src/issue-credential/tests/stubs/credential-type-dto.ts +++ b/apps/attestation-manager/src/issue-credential/tests/stubs/credential-type-dto.ts @@ -1,5 +1,6 @@ +import type CredentialTypeDto from '../../entities/credentialType.entity.js'; + import schemaDto from '../../../schemas/tests/stubs/schema-dto.js'; -import CredentialTypeDto from '../../entities/credentialType.entity.js'; const credentialsTypeDto = (): CredentialTypeDto => ({ id: 'credential-type-id', diff --git a/apps/attestation-manager/src/issue-credential/tests/stubs/offer-credential-dto.ts b/apps/attestation-manager/src/issue-credential/tests/stubs/offer-credential-dto.ts index 0847f65..4cb5873 100644 --- a/apps/attestation-manager/src/issue-credential/tests/stubs/offer-credential-dto.ts +++ b/apps/attestation-manager/src/issue-credential/tests/stubs/offer-credential-dto.ts @@ -1,5 +1,7 @@ +import type OfferCredentialDto from '../../entities/entity.js'; + import schemaDto from '../../../schemas/tests/stubs/schema-dto.js'; -import OfferCredentialDto from '../../entities/entity.js'; + import credentialDto from './credential-dto.js'; const offerCredentialDto = (): OfferCredentialDto => ({ diff --git a/apps/attestation-manager/src/main.ts b/apps/attestation-manager/src/main.ts index acc553d..967a1fd 100644 --- a/apps/attestation-manager/src/main.ts +++ b/apps/attestation-manager/src/main.ts @@ -1,46 +1,46 @@ +import type { MicroserviceOptions } from '@nestjs/microservices'; + import { VersioningType } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { HttpAdapterHost, NestFactory } from '@nestjs/core'; -import { MicroserviceOptions, Transport } from '@nestjs/microservices'; +import { Transport } from '@nestjs/microservices'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; + import AppModule from './app.module.js'; import AllExceptionsFilter from './utils/exceptionsFilter.js'; import logger from './utils/logger.js'; -async function bootstrap() { - const app = await NestFactory.create(AppModule); - const configService = app.get(ConfigService); - app.enableCors(); - - app.connectMicroservice<MicroserviceOptions>({ - transport: Transport.NATS, - options: { - servers: [configService.get('nats').url], - }, - }); - - app.enableVersioning({ - defaultVersion: ['1'], - type: VersioningType.URI, - }); - - const swaggerConfig = new DocumentBuilder() - .setTitle('Gaia-x Attestation Manager API') - .setDescription('API documentation for GAIA-X Attestation Manager') - .setVersion('1.0') - .addServer('localhost:3005') - .build(); - - const document = SwaggerModule.createDocument(app, swaggerConfig); - - SwaggerModule.setup('/swagger', app, document); - await app.startAllMicroservices(); - - const httpAdapter = app.get(HttpAdapterHost); - app.useGlobalFilters(new AllExceptionsFilter(httpAdapter)); - - await app.listen(configService.get('PORT') || 3000, () => { - logger.info(`Listening on Port:${configService.get('PORT')}` || 3000); - }); -} -bootstrap(); +const app = await NestFactory.create(AppModule); +const configService = app.get(ConfigService); +app.enableCors(); + +app.connectMicroservice<MicroserviceOptions>({ + transport: Transport.NATS, + options: { + servers: [configService.get('nats').url], + }, +}); + +app.enableVersioning({ + defaultVersion: ['1'], + type: VersioningType.URI, +}); + +const swaggerConfig = new DocumentBuilder() + .setTitle('Gaia-x Attestation Manager API') + .setDescription('API documentation for GAIA-X Attestation Manager') + .setVersion('1.0') + .addServer('localhost:3005') + .build(); + +const document = SwaggerModule.createDocument(app, swaggerConfig); + +SwaggerModule.setup('/swagger', app, document); +await app.startAllMicroservices(); + +const httpAdapter = app.get(HttpAdapterHost); +app.useGlobalFilters(new AllExceptionsFilter(httpAdapter)); + +await app.listen(configService.get('PORT') || 3000, () => { + logger.info(`Listening on Port:${configService.get('PORT')}` || 3000); +}); diff --git a/apps/attestation-manager/src/middleware/auth.middleware.ts b/apps/attestation-manager/src/middleware/auth.middleware.ts index 9532e93..fbbe618 100644 --- a/apps/attestation-manager/src/middleware/auth.middleware.ts +++ b/apps/attestation-manager/src/middleware/auth.middleware.ts @@ -1,14 +1,16 @@ -import { HttpStatus, Injectable, NestMiddleware } from '@nestjs/common'; -import { ConfigService } from '@nestjs/config'; -import { NextFunction, Request, Response } from 'express'; +import type { NestMiddleware } from '@nestjs/common'; +import type { NextFunction, Request, Response } from 'express'; +import { HttpStatus, Injectable } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; import * as jwt from 'jsonwebtoken'; import jwksClient from 'jwks-rsa'; + import logger from '../utils/logger.js'; @Injectable() export class AuthMiddleware implements NestMiddleware { - constructor(private readonly configService: ConfigService) {} + public constructor(private readonly configService: ConfigService) {} /* eslint-disable */ async use(req: Request, res: Response, next: NextFunction) { diff --git a/apps/attestation-manager/src/prisma/prisma.module.ts b/apps/attestation-manager/src/prisma/prisma.module.ts index fe47082..5833b53 100644 --- a/apps/attestation-manager/src/prisma/prisma.module.ts +++ b/apps/attestation-manager/src/prisma/prisma.module.ts @@ -1,5 +1,6 @@ import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; + import PrismaService from './prisma.service.js'; @Module({ diff --git a/apps/attestation-manager/src/prisma/prisma.service.ts b/apps/attestation-manager/src/prisma/prisma.service.ts index 187a829..07142ad 100644 --- a/apps/attestation-manager/src/prisma/prisma.service.ts +++ b/apps/attestation-manager/src/prisma/prisma.service.ts @@ -1,4 +1,6 @@ -import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common'; +import type { OnModuleDestroy, OnModuleInit } from '@nestjs/common'; + +import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { PrismaClient } from '@prisma/client'; @@ -7,11 +9,11 @@ export default class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy { - constructor(private configService: ConfigService) { + public constructor(private configService: ConfigService) { super(); } - async onModuleInit() { + public async onModuleInit() { const prisma = new PrismaClient({ datasources: { db: { @@ -22,7 +24,7 @@ export default class PrismaService await prisma.$connect(); } - async onModuleDestroy() { + public async onModuleDestroy() { await this.$disconnect(); } } diff --git a/apps/attestation-manager/src/prisma/tests/prisma.module.spec.ts b/apps/attestation-manager/src/prisma/tests/prisma.module.spec.ts index d190f50..dc6edda 100644 --- a/apps/attestation-manager/src/prisma/tests/prisma.module.spec.ts +++ b/apps/attestation-manager/src/prisma/tests/prisma.module.spec.ts @@ -1,8 +1,12 @@ +import type { TestingModule } from '@nestjs/testing'; + import { ConfigModule } from '@nestjs/config'; -import { Test, TestingModule } from '@nestjs/testing'; -import PrismaModule from '../prisma.module'; -import PrismaService from '../prisma.service'; -import PrismaServiceMock from './__mocks__/prisma.service'; +import { Test } from '@nestjs/testing'; + +import PrismaModule from '../prisma.module.js'; +import PrismaService from '../prisma.service.js'; + +import PrismaServiceMock from './__mocks__/prisma.service.js'; describe('PrismaModule', () => { let prismaModule: PrismaModule; diff --git a/apps/attestation-manager/src/prisma/tests/prisma.service.spec.ts b/apps/attestation-manager/src/prisma/tests/prisma.service.spec.ts index eb3f05f..e0cfff6 100644 --- a/apps/attestation-manager/src/prisma/tests/prisma.service.spec.ts +++ b/apps/attestation-manager/src/prisma/tests/prisma.service.spec.ts @@ -1,5 +1,8 @@ +import type { TestingModule } from '@nestjs/testing'; + import { ConfigService } from '@nestjs/config'; -import { Test, TestingModule } from '@nestjs/testing'; +import { Test } from '@nestjs/testing'; + import PrismaService from '../prisma.service.js'; describe('PrismaService', () => { @@ -18,7 +21,7 @@ describe('PrismaService', () => { }); describe('onModuleInit()', () => { - let res: any; + let res: unknown; beforeEach(async () => { res = await prismaService.onModuleInit(); @@ -30,7 +33,7 @@ describe('PrismaService', () => { }); describe('onModuleDestroy()', () => { - let res: any; + let res: unknown; beforeEach(async () => { res = await prismaService.onModuleDestroy(); diff --git a/apps/attestation-manager/src/schemas/controller/controller.ts b/apps/attestation-manager/src/schemas/controller/controller.ts index 066dd8d..2286104 100644 --- a/apps/attestation-manager/src/schemas/controller/controller.ts +++ b/apps/attestation-manager/src/schemas/controller/controller.ts @@ -1,3 +1,5 @@ +import type { ResponseType } from '../../common/response.js'; + import { Body, Controller, @@ -19,9 +21,9 @@ import { ApiTags, } from '@nestjs/swagger'; import { Prisma } from '@prisma/client'; -import type { Response } from 'express'; +import { Response } from 'express'; + import { VersionRegex } from '../../common/constants.js'; -import { ResponseType } from '../../common/response.js'; import logger from '../../utils/logger.js'; import SchemaDto from '../entities/schema-entity.js'; import SchemasService from '../services/service.js'; @@ -29,7 +31,7 @@ import SchemasService from '../services/service.js'; @ApiTags('Schemas') @Controller('schemas') export default class SchemasController { - constructor(private readonly schemasService: SchemasService) {} + public constructor(private readonly schemasService: SchemasService) {} @Version(['1']) @ApiQuery({ name: 'page', required: false }) @@ -137,7 +139,7 @@ export default class SchemasController { }, }, }) - async findSchemas( + public async findSchemas( @Query() query: { pageSize: string; page: string }, @Res() response: Response, ) { @@ -257,7 +259,10 @@ export default class SchemasController { }, }, }) - async findSchemasById(@Param('id') id: string, @Res() response: Response) { + public async findSchemasById( + @Param('id') id: string, + @Res() response: Response, + ) { let res: ResponseType; try { logger.info('Schema fetched successfully'); @@ -408,7 +413,7 @@ export default class SchemasController { }, }, }) - async createSchema( + public async createSchema( @Body() createSchema: SchemaDto, @Res() response: Response, ) { @@ -544,7 +549,10 @@ export default class SchemasController { }, }, }) - async getDidsForSchema(@Param('id') id: string, @Res() response: Response) { + public async getDidsForSchema( + @Param('id') id: string, + @Res() response: Response, + ) { let res: ResponseType; try { logger.info('Schema DIDs fetched successfully'); diff --git a/apps/attestation-manager/src/schemas/entities/schema-entity.ts b/apps/attestation-manager/src/schemas/entities/schema-entity.ts index a11fbc8..ec6cbf5 100644 --- a/apps/attestation-manager/src/schemas/entities/schema-entity.ts +++ b/apps/attestation-manager/src/schemas/entities/schema-entity.ts @@ -4,45 +4,45 @@ import { IsString, IsNotEmpty } from 'class-validator'; export default class SchemaDto { @IsString() @IsNotEmpty() - id: string; + public id: string; @IsString() @IsNotEmpty() - schemaID: string; + public schemaID: string; @IsString() @IsNotEmpty() @ApiProperty() - name: string; + public name: string; @IsString() @ApiProperty() - createdBy: string; + public createdBy: string; @IsString() - createdDate: Date; + public createdDate: Date; @IsString() - updatedBy?: string; + public updatedBy?: string; @IsString() - updatedDate: Date; + public updatedDate: Date; @IsString() @ApiProperty() - version: string; + public version: string; @IsString() @ApiProperty() - attributes: string[]; + public attributes: string[]; @IsString() - pageSize?: string; + public pageSize?: string; @IsString() - page?: string; + public page?: string; @IsString() @ApiPropertyOptional() - type?: string; + public type?: string; } diff --git a/apps/attestation-manager/src/schemas/module.ts b/apps/attestation-manager/src/schemas/module.ts index c292459..7ec28d3 100644 --- a/apps/attestation-manager/src/schemas/module.ts +++ b/apps/attestation-manager/src/schemas/module.ts @@ -1,11 +1,13 @@ import { HttpModule } from '@nestjs/axios'; import { Module } from '@nestjs/common'; import { ClientsModule, Transport } from '@nestjs/microservices'; + import NatsClientService from '../client/nats.client.js'; import RestClientService from '../client/rest.client.js'; import { NATSServices } from '../common/constants.js'; import config from '../config/config.js'; import PrismaService from '../prisma/prisma.service.js'; + import SchemasController from './controller/controller.js'; import SchemasService from './services/service.js'; diff --git a/apps/attestation-manager/src/schemas/repository/schema.respository.ts b/apps/attestation-manager/src/schemas/repository/schema.respository.ts index cb11b48..8b4500f 100644 --- a/apps/attestation-manager/src/schemas/repository/schema.respository.ts +++ b/apps/attestation-manager/src/schemas/repository/schema.respository.ts @@ -1,12 +1,14 @@ +import type { Prisma } from '@prisma/client'; + import { Injectable } from '@nestjs/common'; -import { Prisma } from '@prisma/client'; + import PrismaService from '../../prisma/prisma.service.js'; @Injectable() export default class SchemaRepository { - constructor(private readonly prismaService: PrismaService) {} + public constructor(private readonly prismaService: PrismaService) {} - async createSchema(data: Prisma.SchemaCreateInput) { + public async createSchema(data: Prisma.SchemaCreateInput) { return this.prismaService.schema.create({ data, include: { @@ -19,7 +21,7 @@ export default class SchemaRepository { }); } - async findSchemas(params: { + public async findSchemas(params: { skip?: number; take?: number; cursor?: Prisma.SchemaWhereUniqueInput; @@ -48,7 +50,9 @@ export default class SchemaRepository { ]); } - async findUniqueSchema(params: { where: Prisma.SchemaWhereUniqueInput }) { + public async findUniqueSchema(params: { + where: Prisma.SchemaWhereUniqueInput; + }) { const { where } = params; return this.prismaService.schema.findUnique({ where, diff --git a/apps/attestation-manager/src/schemas/services/service.ts b/apps/attestation-manager/src/schemas/services/service.ts index c2b18d4..e0e6ee3 100644 --- a/apps/attestation-manager/src/schemas/services/service.ts +++ b/apps/attestation-manager/src/schemas/services/service.ts @@ -1,13 +1,15 @@ +import type SchemaDto from '../entities/schema-entity.js'; +import type { Prisma } from '@prisma/client'; + import { BadRequestException, Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; -import { Prisma } from '@prisma/client'; + import NatsClientService from '../../client/nats.client.js'; import RestClientService from '../../client/rest.client.js'; +import CredentialTypeRepository from '../../issue-credential/repository/credentialType.repository.js'; import PrismaService from '../../prisma/prisma.service.js'; import pagination from '../../utils/pagination.js'; -import SchemaDto from '../entities/schema-entity.js'; import SchemaRepository from '../repository/schema.respository.js'; -import CredentialTypeRepository from '../../issue-credential/repository/credentialType.repository.js'; @Injectable() export default class SchemasService { @@ -15,7 +17,7 @@ export default class SchemasService { private credentialTypeRepository: CredentialTypeRepository; - constructor( + public constructor( private readonly prismaService: PrismaService, private readonly restClient: RestClientService, private readonly natsClient: NatsClientService, @@ -27,7 +29,7 @@ export default class SchemasService { ); } - async createSchemas(schema: SchemaDto) { + public async createSchemas(schema: SchemaDto) { const query: { schemaID: string; name: string; @@ -69,7 +71,7 @@ export default class SchemasService { return this.schemaRepository.createSchema(query); } - async findSchemas(pageSize: number, page: number) { + public async findSchemas(pageSize: number, page: number) { let query: { skip?: number; take?: number; @@ -82,13 +84,13 @@ export default class SchemasService { return this.schemaRepository.findSchemas(query); } - async findSchemasById(id: string) { + public async findSchemasById(id: string) { return this.schemaRepository.findSchemas({ where: { schemaID: id }, }); } - async getDidsForSchemasId(id: string) { + public async getDidsForSchemasId(id: string) { return this.prismaService.schema.findMany({ where: { schemaID: id }, include: { @@ -104,12 +106,12 @@ export default class SchemasService { }); } - findBySchemaId(schemaID: string) { + public findBySchemaId(schemaID: string) { const query = { where: { schemaID } }; return this.schemaRepository.findUniqueSchema(query); } - async checkSchemasByNameAndVersion(schemaDto: SchemaDto) { + public async checkSchemasByNameAndVersion(schemaDto: SchemaDto) { return this.schemaRepository.findSchemas({ where: { schemaID: { @@ -123,7 +125,7 @@ export default class SchemasService { }); } - async createSchemaOnLedger(schemaDto: SchemaDto) { + public async createSchemaOnLedger(schemaDto: SchemaDto) { const agentUrl = this.configService.get('agent.AGENT_URL'); const responseData = await this.restClient.post( `${agentUrl}/schemas/`, @@ -133,7 +135,7 @@ export default class SchemasService { return responseData; } - async getSchemaAndAttributesBySchemaIDFromLedger(schemaID: string) { + public async getSchemaAndAttributesBySchemaIDFromLedger(schemaID: string) { const agentUrl = this.configService.get('agent.AGENT_URL'); const responseData = await this.restClient.get( `${agentUrl}/schemas/${schemaID}`, diff --git a/apps/attestation-manager/src/schemas/tests/controller.spec.ts b/apps/attestation-manager/src/schemas/tests/controller.spec.ts index 35a629e..dbda0e8 100644 --- a/apps/attestation-manager/src/schemas/tests/controller.spec.ts +++ b/apps/attestation-manager/src/schemas/tests/controller.spec.ts @@ -1,9 +1,13 @@ +import type SchemaDto from '../entities/schema-entity.js'; +import type { TestingModule } from '@nestjs/testing'; + import { HttpStatus } from '@nestjs/common'; -import { Test, TestingModule } from '@nestjs/testing'; -import httpMocks from 'node-mocks-http'; +import { Test } from '@nestjs/testing'; +import { createResponse } from 'node-mocks-http'; + import SchemasController from '../controller/controller.js'; -import SchemaDto from '../entities/schema-entity.js'; import SchemasService from '../services/service.js'; + import SchemasServiceMock from './__mocks__/service.js'; import schemaDto from './stubs/schema-dto.js'; @@ -32,13 +36,13 @@ describe('SchemasController', () => { }); describe('findSchemas()', () => { - let schemasResponse: Response<string, Record<string, any>>; + let schemasResponse: Response<string, Record<string, unknown>>; let query: SchemaDto; - let response: Response<string, Record<string, any>>; + let response: Response<string, Record<string, unknown>>; beforeEach(async () => { query = schemaDto(); - response = httpMocks.createResponse(); + response = createResponse(); schemasResponse = await schemasController.findSchemas(query, response); }); @@ -62,13 +66,13 @@ describe('SchemasController', () => { }); describe('findSchemasById()', () => { - let schemasResponse: Response<string, Record<string, any>>; + let schemasResponse: Response<string, Record<string, unknown>>; let id: string; - let response: Response<string, Record<string, any>>; + let response: Response<string, Record<string, unknown>>; beforeEach(async () => { id = schemaDto().schemaID || ''; - response = httpMocks.createResponse(); + response = createResponse(); schemasResponse = await schemasController.findSchemasById(id, response); }); @@ -87,13 +91,13 @@ describe('SchemasController', () => { }); describe('createSchema()', () => { - let schemasResponse: Response<string, Record<string, any>>; + let schemasResponse: Response<string, Record<string, unknown>>; let createSchema: SchemaDto; - let response: Response<string, Record<string, any>>; + let response: Response<string, Record<string, unknown>>; beforeEach(async () => { createSchema = schemaDto(); - response = httpMocks.createResponse(); + response = createResponse(); schemasResponse = await schemasController.createSchema( createSchema, diff --git a/apps/attestation-manager/src/schemas/tests/module.spec.ts b/apps/attestation-manager/src/schemas/tests/module.spec.ts index 844ce26..277195c 100644 --- a/apps/attestation-manager/src/schemas/tests/module.spec.ts +++ b/apps/attestation-manager/src/schemas/tests/module.spec.ts @@ -1,6 +1,9 @@ +import type { TestingModule } from '@nestjs/testing'; + import { HttpModule } from '@nestjs/axios'; import { ConfigService } from '@nestjs/config'; -import { Test, TestingModule } from '@nestjs/testing'; +import { Test } from '@nestjs/testing'; + import NatsClientService from '../../client/nats.client.js'; import RestClientService from '../../client/rest.client.js'; import NatsClientServiceMock from '../../client/tests/__mocks__/nats.client.js'; @@ -9,6 +12,7 @@ import PrismaService from '../../prisma/prisma.service.js'; import PrismaServiceMock from '../../prisma/tests/__mocks__/prisma.service.js'; import SchemasModule from '../module.js'; import SchemasService from '../services/service.js'; + import SchemasServiceMock from './__mocks__/service.js'; describe('SchemasModule', () => { diff --git a/apps/attestation-manager/src/schemas/tests/service.spec.ts b/apps/attestation-manager/src/schemas/tests/service.spec.ts index 1e98621..79977aa 100644 --- a/apps/attestation-manager/src/schemas/tests/service.spec.ts +++ b/apps/attestation-manager/src/schemas/tests/service.spec.ts @@ -1,15 +1,19 @@ +import type { ResponseType } from '../../common/response.js'; +import type { TestingModule } from '@nestjs/testing'; +import type { Schema } from 'joi'; + import { HttpModule } from '@nestjs/axios'; import { ConfigService } from '@nestjs/config'; -import { Test, TestingModule } from '@nestjs/testing'; -import { Schema } from 'joi'; +import { Test } from '@nestjs/testing'; + import NatsClientService from '../../client/nats.client.js'; import RestClientService from '../../client/rest.client.js'; import NatsClientServiceMock from '../../client/tests/__mocks__/nats.client.js'; import RestClientServiceMock from '../../client/tests/__mocks__/rest.client.js'; -import { ResponseType } from '../../common/response.js'; import PrismaService from '../../prisma/prisma.service.js'; import PrismaServiceMock from '../../prisma/tests/__mocks__/prisma.service.js'; import SchemasService from '../services/service.js'; + import schemaDto from './stubs/schema-dto.js'; describe('SchemasService', () => { diff --git a/apps/attestation-manager/src/schemas/tests/stubs/schema-dto.ts b/apps/attestation-manager/src/schemas/tests/stubs/schema-dto.ts index a869a4f..7494244 100644 --- a/apps/attestation-manager/src/schemas/tests/stubs/schema-dto.ts +++ b/apps/attestation-manager/src/schemas/tests/stubs/schema-dto.ts @@ -1,4 +1,4 @@ -import SchemaDto from '../../entities/schema-entity.js'; +import type SchemaDto from '../../entities/schema-entity.js'; const schemaDto = (): SchemaDto => ({ id: 'schema-db-id', diff --git a/apps/attestation-manager/src/tests/app.module.spec.ts b/apps/attestation-manager/src/tests/app.module.spec.ts index 3bde7fe..e52dd78 100644 --- a/apps/attestation-manager/src/tests/app.module.spec.ts +++ b/apps/attestation-manager/src/tests/app.module.spec.ts @@ -1,5 +1,8 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { INestApplication } from '@nestjs/common'; +import type { INestApplication } from '@nestjs/common'; +import type { TestingModule } from '@nestjs/testing'; + +import { Test } from '@nestjs/testing'; + import AppModule from '../app.module.js'; describe('App Module', () => { diff --git a/apps/attestation-manager/src/userInfo/controller/controller.ts b/apps/attestation-manager/src/userInfo/controller/controller.ts index 25c381e..741b6fd 100644 --- a/apps/attestation-manager/src/userInfo/controller/controller.ts +++ b/apps/attestation-manager/src/userInfo/controller/controller.ts @@ -12,7 +12,8 @@ import { import { ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger'; import { Prisma } from '@prisma/client'; import { isUUID } from 'class-validator'; -import type { Response } from 'express'; +import { Response } from 'express'; + import { AutoAcceptCredential } from '../../common/constants.js'; import logger from '../../utils/logger.js'; import UserInfoDto from '../entities/userInfo.entity.js'; @@ -21,7 +22,7 @@ import UserInfoService from '../services/service.js'; @ApiTags('userInfo (to be deprecated)') @Controller('userInfo') export default class UserInfoController { - constructor(private readonly userInfoService: UserInfoService) {} + public constructor(private readonly userInfoService: UserInfoService) {} @Version(['1']) @ApiBody({ type: UserInfoDto }) @@ -31,7 +32,7 @@ export default class UserInfoController { description: 'This call provides the capability to add any additional information to connection. The format of added data is just a simple json', }) - async createUserInfo( + public async createUserInfo( @Body() userInfoDto: UserInfoDto, @Res() response: Response, ) { diff --git a/apps/attestation-manager/src/userInfo/entities/update-unserInfo.dto.ts b/apps/attestation-manager/src/userInfo/entities/update-unserInfo.dto.ts index f19ab0e..838bb0c 100644 --- a/apps/attestation-manager/src/userInfo/entities/update-unserInfo.dto.ts +++ b/apps/attestation-manager/src/userInfo/entities/update-unserInfo.dto.ts @@ -3,11 +3,11 @@ type UserInfo = { }; export default class UpdateUserInfoDto { - connectionId: string; + public connectionId: string; - status: string; + public status: string; - credentialDefinitionId: string; + public credentialDefinitionId: string; - userInfo: UserInfo; + public userInfo: UserInfo; } diff --git a/apps/attestation-manager/src/userInfo/entities/userInfo.entity.ts b/apps/attestation-manager/src/userInfo/entities/userInfo.entity.ts index f4dd7d5..d3aa49b 100644 --- a/apps/attestation-manager/src/userInfo/entities/userInfo.entity.ts +++ b/apps/attestation-manager/src/userInfo/entities/userInfo.entity.ts @@ -8,14 +8,14 @@ export default class UserInfoDto { @IsString() @IsNotEmpty() @ApiProperty() - connectionId: string; + public connectionId: string; @IsEnum(['always', 'contentApproved', 'never']) @IsNotEmpty() @ApiProperty() - autoAcceptCredential: string; + public autoAcceptCredential: string; @IsNotEmpty() @ApiProperty({ type: {} }) - userInfo: UserInfo; + public userInfo: UserInfo; } diff --git a/apps/attestation-manager/src/userInfo/module.ts b/apps/attestation-manager/src/userInfo/module.ts index 1c7287f..2c20ccd 100644 --- a/apps/attestation-manager/src/userInfo/module.ts +++ b/apps/attestation-manager/src/userInfo/module.ts @@ -1,12 +1,14 @@ import { HttpModule } from '@nestjs/axios'; import { Module } from '@nestjs/common'; import { ClientsModule, Transport } from '@nestjs/microservices'; + import NatsClientService from '../client/nats.client.js'; import RestClientService from '../client/rest.client.js'; import { NATSServices } from '../common/constants.js'; import config from '../config/config.js'; import PrismaService from '../prisma/prisma.service.js'; import SchemasService from '../schemas/services/service.js'; + import UserInfoController from './controller/controller.js'; import UserInfoService from './services/service.js'; diff --git a/apps/attestation-manager/src/userInfo/repository/userInfo.respository.ts b/apps/attestation-manager/src/userInfo/repository/userInfo.respository.ts index 9bd974a..d73d474 100644 --- a/apps/attestation-manager/src/userInfo/repository/userInfo.respository.ts +++ b/apps/attestation-manager/src/userInfo/repository/userInfo.respository.ts @@ -1,12 +1,14 @@ -import { Injectable } from '@nestjs/common'; import type { Prisma } from '@prisma/client'; + +import { Injectable } from '@nestjs/common'; + import PrismaService from '../../prisma/prisma.service.js'; @Injectable() export default class UserInfoRepository { - constructor(private readonly prismaService: PrismaService) {} + public constructor(private readonly prismaService: PrismaService) {} - async createUserInfo(data: Prisma.UserInfoCreateInput) { + public async createUserInfo(data: Prisma.UserInfoCreateInput) { const userInfo = await this.prismaService.userInfo.create({ data, }); @@ -14,7 +16,7 @@ export default class UserInfoRepository { return userInfo; } - async updateUserInfo(data: Prisma.UserInfoUncheckedUpdateManyInput) { + public async updateUserInfo(data: Prisma.UserInfoUncheckedUpdateManyInput) { const userInfo = await this.prismaService.userInfo.updateMany({ where: { connectionId: data.connectionId as string, @@ -25,7 +27,7 @@ export default class UserInfoRepository { return userInfo; } - async getUserInfo(params: { where: Prisma.UserInfoWhereInput }) { + public async getUserInfo(params: { where: Prisma.UserInfoWhereInput }) { const { where } = params; return this.prismaService.userInfo.findFirst({ where, diff --git a/apps/attestation-manager/src/userInfo/services/service.ts b/apps/attestation-manager/src/userInfo/services/service.ts index 4236473..4df6fd2 100644 --- a/apps/attestation-manager/src/userInfo/services/service.ts +++ b/apps/attestation-manager/src/userInfo/services/service.ts @@ -1,19 +1,21 @@ +import type UpdateUserInfoDto from '../entities/update-unserInfo.dto.js'; +import type UserInfoDto from '../entities/userInfo.entity.js'; + import { Injectable } from '@nestjs/common'; + import PrismaService from '../../prisma/prisma.service.js'; import logger from '../../utils/logger.js'; -import UpdateUserInfoDto from '../entities/update-unserInfo.dto.js'; -import UserInfoDto from '../entities/userInfo.entity.js'; import UserInfoRepository from '../repository/userInfo.respository.js'; @Injectable() export default class UserInfoService { private userInfoRepository: UserInfoRepository; - constructor(private readonly prismaService: PrismaService) { + public constructor(private readonly prismaService: PrismaService) { this.userInfoRepository = new UserInfoRepository(this.prismaService); } - async createUserInfo(userInfoDto: UserInfoDto) { + public async createUserInfo(userInfoDto: UserInfoDto) { logger.info(`In user info service, ${JSON.stringify(userInfoDto)}`); return this.userInfoRepository.createUserInfo({ autoAcceptCredential: userInfoDto.autoAcceptCredential, @@ -22,7 +24,7 @@ export default class UserInfoService { }); } - async updateUserInfo(userInfoDto: UpdateUserInfoDto) { + public async updateUserInfo(userInfoDto: UpdateUserInfoDto) { logger.info(`In user info service, ${userInfoDto}`); return this.userInfoRepository.updateUserInfo({ connectionId: userInfoDto.connectionId, @@ -32,7 +34,7 @@ export default class UserInfoService { }); } - async getUserInfo(connectionId: string) { + public async getUserInfo(connectionId: string) { logger.info(`In get user info service, ${connectionId}`); return this.userInfoRepository.getUserInfo({ where: { diff --git a/apps/attestation-manager/src/userInfo/tests/stubs/user-info-dto.stub.ts b/apps/attestation-manager/src/userInfo/tests/stubs/user-info-dto.stub.ts index 4725dfc..b7cce22 100644 --- a/apps/attestation-manager/src/userInfo/tests/stubs/user-info-dto.stub.ts +++ b/apps/attestation-manager/src/userInfo/tests/stubs/user-info-dto.stub.ts @@ -1,7 +1,8 @@ +import type UserInfoDto from '../../entities/userInfo.entity.js'; + import credentialDto from '../../../issue-credential/tests/stubs/credential-dto.js'; import offerCredentialDto from '../../../issue-credential/tests/stubs/offer-credential-dto.js'; import schemaDto from '../../../schemas/tests/stubs/schema-dto.js'; -import UserInfoDto from '../../entities/userInfo.entity.js'; const userInfo = (): UserInfoDto => ({ autoAcceptCredential: offerCredentialDto().autoAcceptCredential, diff --git a/apps/attestation-manager/src/utils/exceptionsFilter.ts b/apps/attestation-manager/src/utils/exceptionsFilter.ts index 711d55c..b445637 100644 --- a/apps/attestation-manager/src/utils/exceptionsFilter.ts +++ b/apps/attestation-manager/src/utils/exceptionsFilter.ts @@ -1,23 +1,18 @@ -import { - ArgumentsHost, - Catch, - ExceptionFilter, - HttpException, - HttpStatus, - Logger, -} from '@nestjs/common'; +import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common'; +import type { Request } from 'express'; + +import { Catch, HttpException, HttpStatus, Logger } from '@nestjs/common'; import { HttpAdapterHost } from '@nestjs/core'; import { Prisma } from '@prisma/client'; -import { Request } from 'express'; const { PrismaClientKnownRequestError, PrismaClientValidationError } = Prisma; @Catch() export default class AllExceptionsFilter implements ExceptionFilter { - constructor(private readonly httpAdapterHost: HttpAdapterHost) {} + public constructor(private readonly httpAdapterHost: HttpAdapterHost) {} // eslint-disable-next-line @typescript-eslint/no-explicit-any - catch(exception: any, host: ArgumentsHost): void { + public catch(exception: any, host: ArgumentsHost): void { const { httpAdapter } = this.httpAdapterHost; const ctx = host.switchToHttp(); diff --git a/apps/attestation-manager/src/utils/logger.ts b/apps/attestation-manager/src/utils/logger.ts index 89b3250..218005e 100644 --- a/apps/attestation-manager/src/utils/logger.ts +++ b/apps/attestation-manager/src/utils/logger.ts @@ -1,15 +1,16 @@ import { ecsFormat } from '@elastic/ecs-winston-format'; import { mkdirSync } from 'fs'; -import winston, { Logger } from 'winston'; +import { createLogger, transports, type Logger } from 'winston'; + import { LoggerConfig } from '../common/constants.js'; mkdirSync(LoggerConfig.lOG_DIR, { recursive: true }); -const logger: Logger = winston.createLogger({ +const logger: Logger = createLogger({ format: ecsFormat({ convertReqRes: true }), transports: [ - new winston.transports.Console(), - new winston.transports.File({ + new transports.Console(), + new transports.File({ filename: LoggerConfig.FILE_PATH, }), // esTransport, @@ -17,6 +18,7 @@ const logger: Logger = winston.createLogger({ }); logger.on('error', (error) => { + // eslint-disable-next-line no-console console.error('Error in logger caught', error); }); diff --git a/apps/attestation-manager/test/app.e2e-spec.ts b/apps/attestation-manager/test/app.e2e-spec.ts index 9bb5cc3..e6000c0 100644 --- a/apps/attestation-manager/test/app.e2e-spec.ts +++ b/apps/attestation-manager/test/app.e2e-spec.ts @@ -1,6 +1,9 @@ -import { INestApplication } from '@nestjs/common'; -import { Test, TestingModule } from '@nestjs/testing'; +import type { INestApplication } from '@nestjs/common'; +import type { TestingModule } from '@nestjs/testing'; + +import { Test } from '@nestjs/testing'; import request from 'supertest'; + import AppModule from '../src/app.module.js'; describe('AppController (e2e)', () => { -- GitLab