Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: bulk issuance template list response changes #824

Merged
merged 4 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 0 additions & 4 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