Skip to content

Commit

Permalink
Merge branch 'qa' of https://github.com/credebl/platform into merge/q…
Browse files Browse the repository at this point in the history
…a-to-prod-August-2024
  • Loading branch information
GHkrishna committed Aug 30, 2024
2 parents f61b098 + 1a74e32 commit 963846a
Show file tree
Hide file tree
Showing 18 changed files with 156 additions and 62 deletions.
4 changes: 2 additions & 2 deletions apps/issuance/src/issuance.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ export class IssuanceRepository {

let schemaId = '';

if (issueCredentialDto?.metadata?.['_anoncreds/credential']?.schemaId) {
schemaId = issueCredentialDto?.metadata?.['_anoncreds/credential']?.schemaId;
if (issueCredentialDto?.metadata?.['_anoncreds/credential']?.schemaId || issueCredentialDto?.['credentialData']?.offer?.jsonld?.credential?.['@context'][1]) {
schemaId = issueCredentialDto?.metadata?.['_anoncreds/credential']?.schemaId || issueCredentialDto?.['credentialData']?.offer?.jsonld?.credential?.['@context'][1];
}

let credDefId = '';
Expand Down
44 changes: 42 additions & 2 deletions apps/issuance/src/issuance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { FileUploadStatus, FileUploadType } from 'apps/api-gateway/src/enum';
import { AwsService } from '@credebl/aws';
import { io } from 'socket.io-client';
import { IIssuedCredentialSearchParams, IssueCredentialType } from 'apps/api-gateway/src/issuance/interfaces';
import { ICredentialOfferResponse, IDeletedIssuanceRecords, IIssuedCredential, IJsonldCredential, IPrettyVc } from '@credebl/common/interfaces/issuance.interface';
import { ICredentialOfferResponse, IDeletedIssuanceRecords, IIssuedCredential, IJsonldCredential, IPrettyVc, ISchemaObject } from '@credebl/common/interfaces/issuance.interface';
import { OOBIssueCredentialDto } from 'apps/api-gateway/src/issuance/dtos/issuance.dto';
import { RecordType, agent_invitations, organisation, user } from '@prisma/client';
import { createOobJsonldIssuancePayload, validateAndUpdateIssuanceDates, validateEmail } from '@credebl/common/cast.helper';
Expand Down Expand Up @@ -456,6 +456,30 @@ export class IssuanceService {
orgId,
issuedCredentialsSearchCriteria
);

const getSchemaIds = getIssuedCredentialsList?.issuedCredentialsList?.map((schema) => schema?.schemaId);

const getSchemaDetails = await this._getSchemaDetails(getSchemaIds);

let responseWithSchemaName;
if (getSchemaDetails) {
responseWithSchemaName = getIssuedCredentialsList?.issuedCredentialsList.map(file => {
const schemaDetail = getSchemaDetails?.find(schema => schema.schemaLedgerId === file.schemaId);
return {
...file,
schemaName: schemaDetail?.name
};
});
} else {
const getSchemaUrlDetails = await this.getSchemaUrlDetails(getSchemaIds);
responseWithSchemaName = getIssuedCredentialsList?.issuedCredentialsList.map(file => {
const schemaDetail = getSchemaUrlDetails?.find(schema => schema.title);
return {
...file,
schemaName: schemaDetail?.title
};
});
}
const issuedCredentialsResponse: IIssuedCredential = {
totalItems: getIssuedCredentialsList.issuedCredentialsCount,
hasNextPage:
Expand All @@ -464,7 +488,7 @@ export class IssuanceService {
nextPage: Number(issuedCredentialsSearchCriteria.pageNumber) + 1,
previousPage: issuedCredentialsSearchCriteria.pageNumber - 1,
lastPage: Math.ceil(getIssuedCredentialsList.issuedCredentialsCount / issuedCredentialsSearchCriteria.pageSize),
data: getIssuedCredentialsList.issuedCredentialsList
data: responseWithSchemaName
};

if (0 === getIssuedCredentialsList?.issuedCredentialsCount) {
Expand All @@ -478,6 +502,22 @@ export class IssuanceService {
}
}

async getSchemaUrlDetails(schemaUrls: string[]): Promise<ISchemaObject[]> {
const results = [];

for (const schemaUrl of schemaUrls) {
const schemaRequest = await this.commonService.httpGet(schemaUrl);
if (!schemaRequest) {
throw new NotFoundException(ResponseMessages.schema.error.W3CSchemaNotFOund, {
cause: new Error(),
description: ResponseMessages.errorMessages.notFound
});
}
results.push(schemaRequest);
}
return results;
}

async _getIssueCredentials(url: string, apiKey: string): Promise<{
response: string;
}> {
Expand Down
96 changes: 66 additions & 30 deletions apps/ledger/src/schema/repositories/schema.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,35 +238,71 @@ export class SchemaRepository {
async getAllSchemaDetails(payload: ISchemaSearchCriteria): Promise<IPlatformSchemas> {
try {
const { ledgerId, schemaType, searchByText, sortField, sortBy, pageSize, pageNumber } = payload;
const schemasResult = await this.prisma.schema.findMany({
where: {
ledgerId,
type: schemaType,
OR: [
{ name: { contains: searchByText, mode: 'insensitive' } },
{ version: { contains: searchByText, mode: 'insensitive' } },
{ schemaLedgerId: { contains: searchByText, mode: 'insensitive' } },
{ issuerId: { contains: searchByText, mode: 'insensitive' } }
]
},
select: {
createDateTime: true,
name: true,
version: true,
attributes: true,
schemaLedgerId: true,
createdBy: true,
publisherDid: true,
orgId: true, // This field can be null
issuerId: true,
type: true
},
orderBy: {
[sortField]: SortValue.DESC === sortBy ? SortValue.DESC : SortValue.ASC
},
take: Number(pageSize),
skip: (pageNumber - 1) * pageSize
});
let schemaResult;
/**
* This is made so because the default pageNumber is set to 1 in DTO,
* If there is any 'searchByText' field, we ignore the pageNumbers and search
* in all available records.
*
* Because in that case pageNumber would be insignificant.
*/
if (searchByText) {
schemaResult = await this.prisma.schema.findMany({
where: {
ledgerId,
type: schemaType,
OR: [
{ name: { contains: searchByText, mode: 'insensitive' } },
{ version: { contains: searchByText, mode: 'insensitive' } },
{ schemaLedgerId: { contains: searchByText, mode: 'insensitive' } },
{ issuerId: { contains: searchByText, mode: 'insensitive' } }
]
},
select: {
createDateTime: true,
name: true,
version: true,
attributes: true,
schemaLedgerId: true,
createdBy: true,
publisherDid: true,
orgId: true, // This field can be null
issuerId: true,
type: true
},
orderBy: {
[sortField]: SortValue.DESC === sortBy ? SortValue.DESC : SortValue.ASC
},
take: Number(pageSize)
});
} else {
/**
* Queries apart from the one containing searchText would go here
*/
schemaResult = await this.prisma.schema.findMany({
where: {
ledgerId,
type: schemaType
},
select: {
createDateTime: true,
name: true,
version: true,
attributes: true,
schemaLedgerId: true,
createdBy: true,
publisherDid: true,
orgId: true, // This field can be null
issuerId: true,
type: true
},
orderBy: {
[sortField]: SortValue.DESC === sortBy ? SortValue.DESC : SortValue.ASC
},
take: Number(pageSize),
skip: (pageNumber - 1) * pageSize
});
}

const schemasCount = await this.prisma.schema.count({
where: {
Expand All @@ -276,7 +312,7 @@ export class SchemaRepository {
});

// Handle null orgId in the response
const schemasWithDefaultOrgId = schemasResult.map(schema => ({
const schemasWithDefaultOrgId = schemaResult.map(schema => ({
...schema,
orgId: schema.orgId || null // Replace null orgId with 'N/A' or any default value
}));
Expand Down
16 changes: 15 additions & 1 deletion libs/common/src/interfaces/issuance.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,18 @@ export interface IIssuedCredential {
credential?: ICredential;
options?: IOptions;
}


export interface ISchemaObject {
'$schema': string;
'$id': string;
type: string;
required: string[];
properties: {
[key: string]: object;
};
definitions: {
[key: string]: object;
};
title: string;
description: string;
}
6 changes: 5 additions & 1 deletion libs/prisma-service/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,13 @@ const migrateOrgAgentDids = async (): Promise<void> => {
}
});

const filteredOrgAgents = orgAgents.filter(
(agent) => null !== agent.orgDid && '' !== agent.orgDid
);

// If there are org DIDs that do not exist in org_dids table
if (orgDids.length !== existingDids.length) {
const newOrgAgents = orgAgents.filter(
const newOrgAgents = filteredOrgAgents.filter(
(agent) => !existingDids.some((did) => did.did === agent.orgDid)
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"family": "DEV_AGENT-PROVISIONING_SERVICE_TASKDEFINITION",
"family": "${FAMILY}",
"containerDefinitions": [
{
"name": "agent_provisioning",
Expand Down Expand Up @@ -33,7 +33,7 @@
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/DEV_AGENT-PROVISIONING_SERVICE_TASKDEFINITION",
"awslogs-group": "/ecs/${FAMILY}",
"awslogs-region": "${AWS_REGION}",
"awslogs-stream-prefix": "ecs"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"family": "DEV_AGENT_SERVICE_TASKDEFINITION",
"family": "${FAMILY}",
"containerDefinitions": [
{
"name": "agent",
Expand All @@ -22,7 +22,7 @@
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/DEV_AGENT_SERVICE_TASKDEFINITION",
"awslogs-group": "/ecs/${FAMILY}",
"awslogs-region": "${AWS_REGION}",
"awslogs-stream-prefix": "ecs"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"family": "DEV_API-GATEWAY_SERVICE_TASKDEFINITION",
"family": "${FAMILY}",
"containerDefinitions": [
{
"name": "api_gateway",
Expand Down Expand Up @@ -34,7 +34,7 @@
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/DEV_API-GATEWAY_SERVICE_TASKDEFINITION",
"awslogs-group": "/ecs/${FAMILY}",
"awslogs-region": "${AWS_REGION}",
"awslogs-stream-prefix": "ecs"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"family": "DEV_CONNECTION_SERVICE_TASKDEFINITION",
"family": "${FAMILY}",
"containerDefinitions": [
{
"name": "connection",
Expand All @@ -22,7 +22,7 @@
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/DEV_CONNECTION_SERVICE_TASKDEFINITION",
"awslogs-group": "/ecs/${FAMILY}",
"awslogs-region": "${AWS_REGION}",
"awslogs-stream-prefix": "ecs"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"family": "DEV_ECOSYSTEM_SERVICE_TASKDEFINITION",
"family": "${FAMILY}",
"containerDefinitions": [
{
"name": "ecosystem",
Expand All @@ -22,7 +22,7 @@
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/DEV_ECOSYSTEM_SERVICE_TASKDEFINITION",
"awslogs-group": "/ecs/${FAMILY}",
"awslogs-region": "${AWS_REGION}",
"awslogs-stream-prefix": "ecs"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"family": "DEV_ISSUANCE_SERVICE_TASKDEFINITION",
"family": "${FAMILY}",
"containerDefinitions": [
{
"name": "issuance",
Expand Down Expand Up @@ -28,7 +28,7 @@
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/DEV_ISSUANCE_SERVICE_TASKDEFINITION",
"awslogs-group": "/ecs/${FAMILY}",
"awslogs-region": "${AWS_REGION}",
"awslogs-stream-prefix": "ecs"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"family": "DEV_LEDGER_SERVICE_TASKDEFINITION",
"family": "${FAMILY}",
"containerDefinitions": [
{
"name": "ledger",
Expand All @@ -22,7 +22,7 @@
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/DEV_LEDGER_SERVICE_TASKDEFINITION",
"awslogs-group": "/ecs/${FAMILY}",
"awslogs-region": "${AWS_REGION}",
"awslogs-stream-prefix": "ecs"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"family": "DEV_NOTIFICATION_SERVICE_TASKDEFINITION",
"family": "${FAMILY}",
"containerDefinitions": [
{
"name": "notification",
Expand All @@ -22,7 +22,7 @@
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/DEV_NOTIFICATION_SERVICE_TASKDEFINITION",
"awslogs-group": "/ecs/${FAMILY}",
"awslogs-region": "${AWS_REGION}",
"awslogs-stream-prefix": "ecs"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"family": "DEV_ORGANIZATION_SERVICE_TASKDEFINITION",
"family": "${FAMILY}",
"containerDefinitions": [
{
"name": "organization",
Expand All @@ -22,7 +22,7 @@
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/DEV_ORGANIZATION_SERVICE_TASKDEFINITION",
"awslogs-group": "/ecs/${FAMILY}",
"awslogs-region": "${AWS_REGION}",
"awslogs-stream-prefix": "ecs"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"family": "DEV_USER_SERVICE_TASKDEFINITION",
"family": "${FAMILY}",
"containerDefinitions": [
{
"name": "user",
Expand All @@ -22,7 +22,7 @@
"logDriver": "awslogs",
"options": {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/DEV_USER_SERVICE_TASKDEFINITION",
"awslogs-group": "/ecs/${FAMILY}",
"awslogs-region": "${AWS_REGION}",
"awslogs-stream-prefix": "ecs"
},
Expand Down
Loading

0 comments on commit 963846a

Please sign in to comment.