Skip to content

Commit

Permalink
refactor: bulk issuance template list response changes (#824)
Browse files Browse the repository at this point in the history
* refactor: updated schema response for get API

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

* fix: schema already exist logic

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

* fix: schema attribute while w3c schema creation

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

---------

Signed-off-by: tipusinghaw <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>
  • Loading branch information
tipusinghaw authored and KulkarniShashank committed Sep 11, 2024
1 parent 4f0fc49 commit 021c409
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 26 deletions.
2 changes: 2 additions & 0 deletions apps/api-gateway/src/dtos/create-schema.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ export class CreateW3CSchemaDto {
})
@ValidateNested({each: true})
@Type(() => W3CAttributeValue)
@IsArray({ message: 'attributes must be an array' })
@ArrayMinSize(1)
@IsNotEmpty()
attributes: W3CAttributeValue [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,16 +325,18 @@ export class CredentialDefinitionService extends BaseService {
credDefSortBy: 'id'
};

if (schemaType == SchemaType.W3C_Schema) {
if (schemaType === SchemaType.W3C_Schema) {
const schemaDetailList = await this.credentialDefinitionRepository.getAllSchemaByOrgIdAndType(orgId, schemaType);

const schemaResponse = await Promise.all(schemaDetailList.map(async (schemaDetails) => ({
schemaCredDefName: `${schemaDetails.name}-${schemaDetails.version}`,
schemaName: schemaDetails.name,
schemaVersion: schemaDetails.version,
schemaAttributes: schemaDetails.attributes,
type: SchemaType.W3C_Schema,
schemaIdentifier: schemaDetails.schemaLedgerId
schemaIdentifier: schemaDetails.schemaLedgerId,
createDateTime: schemaDetails.createDateTime,
organizationName: schemaDetails?.organisation?.name,
userName: schemaDetails?.organisation?.userOrgRoles[0]?.user?.firstName
})));

return schemaResponse;
Expand Down
16 changes: 16 additions & 0 deletions apps/ledger/src/credential-definition/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,20 @@ export interface ISchemaResponse{
attributes: string;
schemaLedgerId: string;
orgId: string;
createDateTime?: Date;
createdBy?: string;
organisation?: Organisation;
}

interface UserDetails {
firstName: string;
}

interface UserOrgRole {
user: UserDetails;
}

interface Organisation {
name: string;
userOrgRoles: UserOrgRole[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Injectable, Logger } from '@nestjs/common';
import { ResponseMessages } from '@credebl/common/response-messages';
import { BulkCredDefSchema, CredDefSchema } from '../interfaces/credential-definition.interface';
import { ICredDefData, IPlatformCredDefDetails } from '@credebl/common/interfaces/cred-def.interface';
import { SortValue } from '@credebl/enum/enum';
import { SchemaType, SortValue } from '@credebl/enum/enum';
import { ISchemaResponse } from '../interfaces';

@Injectable()
Expand Down Expand Up @@ -235,7 +235,8 @@ export class CredentialDefinitionRepository {
where: {
schemaLedgerId: {
in: schemaLedgerIdArray
}
},
type: SchemaType.INDY
},
select: {
name: true,
Expand Down Expand Up @@ -283,7 +284,23 @@ export class CredentialDefinitionRepository {
version: true,
schemaLedgerId: true,
orgId: true,
attributes: true
attributes: true,
createDateTime: true,
createdBy: true,
organisation: {
select:{
name: true,
userOrgRoles: {
select: {
user: {
select: {
firstName: true
}
}
}
}
}
}
}
});
} catch (error) {
Expand Down
3 changes: 2 additions & 1 deletion apps/ledger/src/schema/repositories/schema.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ledgers, org_agents, org_agents_type, organisation, schema } from '@pri
import { ISchema, ISchemaExist, ISchemaSearchCriteria } from '../interfaces/schema-payload.interface';
import { ResponseMessages } from '@credebl/common/response-messages';
import { AgentDetails, ISchemasWithCount } from '../interfaces/schema.interface';
import { SortValue } from '@credebl/enum/enum';
import { SchemaType, SortValue } from '@credebl/enum/enum';
import { ICredDefWithCount, IPlatformSchemas } from '@credebl/common/interfaces/schema.interface';

@Injectable()
Expand Down Expand Up @@ -51,6 +51,7 @@ export class SchemaRepository {
try {
return this.prisma.schema.findMany({
where: {
type: SchemaType.INDY,
name: {
contains: schemaName,
mode: 'insensitive'
Expand Down
22 changes: 3 additions & 19 deletions apps/ledger/src/schema/schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,6 @@ export class SchemaService extends BaseService {
async createW3CSchema(orgId:string, schemaPayload: ICreateW3CSchema, user: string): Promise<ISchemaData> {
try {
let createSchema;
const isSchemaExist = await this.schemaRepository.schemaExists(schemaPayload.schemaName, W3CSchemaVersion.W3C_SCHEMA_VERSION);
if (0 !== isSchemaExist.length) {
throw new ConflictException(ResponseMessages.schema.error.exists);
}

const { description, attributes, schemaName} = schemaPayload;
const agentDetails = await this.schemaRepository.getAgentDetailsByOrgId(orgId);
Expand Down Expand Up @@ -327,7 +323,7 @@ export class SchemaService extends BaseService {
createSchema.schemaUrl = `${process.env.SCHEMA_FILE_SERVER_URL}${createSchemaPayload.data.schemaId}`;
}

const storeW3CSchema = await this.storeW3CSchemas(createSchema, user, orgId);
const storeW3CSchema = await this.storeW3CSchemas(createSchema, user, orgId, attributes);

if (!storeW3CSchema) {
throw new BadRequestException(ResponseMessages.schema.error.storeW3CSchema, {
Expand Down Expand Up @@ -526,7 +522,7 @@ export class SchemaService extends BaseService {
return W3CSchema;
}

private async storeW3CSchemas(schemaDetails, user, orgId): Promise <schema> {
private async storeW3CSchemas(schemaDetails, user, orgId, attributes): Promise <schema> {
let ledgerDetails;
const schemaServerUrl = `${process.env.SCHEMA_FILE_SERVER_URL}${schemaDetails.schemaId}`;
const schemaRequest = await this.commonService
Expand All @@ -538,18 +534,6 @@ export class SchemaService extends BaseService {
description: ResponseMessages.errorMessages.notFound
});
}
const schemaAttributeJson = schemaRequest.definitions.credentialSubject.properties;
const extractedData = [];
for (const key in schemaAttributeJson) {
if (2 < Object.keys(schemaAttributeJson[key]).length) {
const { type, title } = schemaAttributeJson[key];
const schemaDataType = type;
const displayName = title;
const isRequired = true;
extractedData.push({ 'attributeName': title, schemaDataType, displayName, isRequired });
}
}

const indyNamespace = await networkNamespace(schemaDetails?.did);
if (indyNamespace === LedgerLessMethods.WEB || indyNamespace === LedgerLessMethods.KEY) {
ledgerDetails = await this.schemaRepository.getLedgerByNamespace(LedgerLessConstant.NO_LEDGER);
Expand All @@ -567,7 +551,7 @@ export class SchemaService extends BaseService {
schema: {
schemaName: schemaRequest.title,
schemaVersion: W3CSchemaVersion.W3C_SCHEMA_VERSION,
attributes:extractedData,
attributes,
id: schemaDetails.schemaUrl

},
Expand Down

0 comments on commit 021c409

Please sign in to comment.