Skip to content

Commit f212554

Browse files
fix: added search on schema name for credentials list (#1111)
* fix:added array data type in schema payload Signed-off-by: pallavicoder <[email protected]> * fix:added nested attributes in schema paylaod Signed-off-by: pallavicoder <[email protected]> * feat: add array data type while creating schema Signed-off-by: bhavanakarwade <[email protected]> * replace hardcoded value with dynamic Signed-off-by: bhavanakarwade <[email protected]> * fix: removed commented code Signed-off-by: bhavanakarwade <[email protected]> * fix: added search on schema name Signed-off-by: bhavanakarwade <[email protected]> * fix: made api property optional Signed-off-by: bhavanakarwade <[email protected]> * handled conditions for empty array Signed-off-by: bhavanakarwade <[email protected]> --------- Signed-off-by: pallavicoder <[email protected]> Signed-off-by: bhavanakarwade <[email protected]> Co-authored-by: pallavicoder <[email protected]> Signed-off-by: bhavanakarwade <[email protected]>
1 parent af1973b commit f212554

File tree

10 files changed

+78
-10
lines changed

10 files changed

+78
-10
lines changed

apps/api-gateway/src/dtos/create-schema.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { JSONSchemaType, SchemaTypeEnum, W3CSchemaDataType } from '@credebl/enum
3232
@IsNotEmpty({ message: 'isRequired property is required' })
3333
isRequired: boolean;
3434

35-
@ApiProperty({
35+
@ApiPropertyOptional({
3636
description: 'Array of objects with dynamic keys',
3737
isArray: true
3838
})

apps/issuance/interfaces/issuance.interfaces.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,7 @@ export interface BulkPayloadDetails {
396396
height?: string;
397397
width?: string;
398398
}
399+
400+
export interface ISchemaId {
401+
schemaLedgerId: string;
402+
}

apps/issuance/src/issuance.repository.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ export class IssuanceRepository {
108108
async getAllIssuedCredentials(
109109
user: IUserRequest,
110110
orgId: string,
111-
issuedCredentialsSearchCriteria: IIssuedCredentialSearchParams
111+
issuedCredentialsSearchCriteria: IIssuedCredentialSearchParams,
112+
schemaIds?: string[]
112113
): Promise<{
113114
issuedCredentialsCount: number;
114115
issuedCredentialsList: {
@@ -121,11 +122,12 @@ export class IssuanceRepository {
121122
}[];
122123
}> {
123124
try {
125+
124126
const issuedCredentialsList = await this.prisma.credentials.findMany({
125127
where: {
126128
orgId,
127129
OR: [
128-
{ schemaId: { contains: issuedCredentialsSearchCriteria.search, mode: 'insensitive' } },
130+
{ schemaId: { in: schemaIds } },
129131
{ connectionId: { contains: issuedCredentialsSearchCriteria.search, mode: 'insensitive' } }
130132
]
131133
},
@@ -150,7 +152,7 @@ export class IssuanceRepository {
150152
where: {
151153
orgId,
152154
OR: [
153-
{ schemaId: { contains: issuedCredentialsSearchCriteria.search, mode: 'insensitive' } },
155+
{ schemaId: { in: schemaIds } },
154156
{ connectionId: { contains: issuedCredentialsSearchCriteria.search, mode: 'insensitive' } }
155157
]
156158
}

apps/issuance/src/issuance.service.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { CommonConstants } from '@credebl/common/common.constant';
99
import { ResponseMessages } from '@credebl/common/response-messages';
1010
import { ClientProxy, RpcException } from '@nestjs/microservices';
1111
import { map } from 'rxjs';
12-
import { BulkPayloadDetails, CredentialOffer, FileUpload, FileUploadData, IAttributes, IBulkPayloadObject, IClientDetails, ICreateOfferResponse, ICredentialPayload, IIssuance, IIssueData, IPattern, IQueuePayload, ISchemaAttributes, ISendOfferNatsPayload, ImportFileDetails, IssueCredentialWebhookPayload, OutOfBandCredentialOfferPayload, PreviewRequest, SchemaDetails, SendEmailCredentialOffer, TemplateDetailsInterface } from '../interfaces/issuance.interfaces';
12+
import { BulkPayloadDetails, CredentialOffer, FileUpload, FileUploadData, IAttributes, IBulkPayloadObject, IClientDetails, ICreateOfferResponse, ICredentialPayload, IIssuance, IIssueData, IPattern, IQueuePayload, ISchemaAttributes, ISchemaId, ISendOfferNatsPayload, ImportFileDetails, IssueCredentialWebhookPayload, OutOfBandCredentialOfferPayload, PreviewRequest, SchemaDetails, SendEmailCredentialOffer, TemplateDetailsInterface } from '../interfaces/issuance.interfaces';
1313
import { AutoAccept, IssuanceProcessState, OrgAgentType, PromiseResult, SchemaType, TemplateIdentifier, W3CSchemaDataType} from '@credebl/enum/enum';
1414
import * as QRCode from 'qrcode';
1515
import { OutOfBandIssuance } from '../templates/out-of-band-issuance.template';
@@ -457,10 +457,21 @@ export class IssuanceService {
457457
issuedCredentialsSearchCriteria: IIssuedCredentialSearchParams
458458
): Promise<IIssuedCredential> {
459459
try {
460+
461+
let schemaIds;
462+
if (issuedCredentialsSearchCriteria?.search) {
463+
const schemaDetails = await this._getSchemaDetailsByName(issuedCredentialsSearchCriteria?.search);
464+
465+
if (schemaDetails && 0 < schemaDetails?.length) {
466+
schemaIds = schemaDetails.map(item => item?.schemaLedgerId);
467+
}
468+
}
469+
460470
const getIssuedCredentialsList = await this.issuanceRepository.getAllIssuedCredentials(
461471
user,
462472
orgId,
463-
issuedCredentialsSearchCriteria
473+
issuedCredentialsSearchCriteria,
474+
schemaIds
464475
);
465476

466477
const getSchemaIds = getIssuedCredentialsList?.issuedCredentialsList?.map((schema) => schema?.schemaId);
@@ -508,6 +519,26 @@ export class IssuanceService {
508519
}
509520
}
510521

522+
async _getSchemaDetailsByName(schemaName: string): Promise<ISchemaId[]> {
523+
const pattern = { cmd: 'get-schemas-details-by-name' };
524+
525+
const schemaDetails = await this.natsClient
526+
.send<ISchemaId[]>(this.issuanceServiceProxy, pattern, schemaName)
527+
528+
.catch((error) => {
529+
this.logger.error(`catch: ${JSON.stringify(error)}`);
530+
throw new HttpException(
531+
{
532+
status: error.status,
533+
error: error.message
534+
},
535+
error.status
536+
);
537+
});
538+
539+
return schemaDetails;
540+
}
541+
511542
async getSchemaUrlDetails(schemaUrls: string[]): Promise<ISchemaObject[]> {
512543
const results = [];
513544

apps/issuance/templates/out-of-band-issuance.template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class OutOfBandIssuance {
5656
<a href="${process.env.IOS_DOWNLOAD_LINK}" target="_blank">iOS App Store.</a> (Skip, if already downloaded)
5757
</li>
5858
<li>Complete the onboarding process in ${process.env.MOBILE_APP}.</li>
59-
<li>Open the “Accept Credential” link below in this email <i>(This will open the link in the ${process.env.MOBILE_APP} App)</i></li>
59+
<li>Open the “Accept Credential” link below in this email <i>(This will open the link in the ${process.env.MOBILE_APP})</i></li>
6060
<li><b>Accept</b> the Credential in ${process.env.MOBILE_APP}.</li>
6161
<li>Check <b>"Credentials"</b> tab in ${process.env.MOBILE_APP} to view the issued credential.</li>
6262
</ul>

apps/ledger/src/schema/repositories/schema.repository.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ResponseMessages } from '@credebl/common/response-messages';
77
import { AgentDetails, ISchemasWithCount } from '../interfaces/schema.interface';
88
import { SchemaType, SortValue } from '@credebl/enum/enum';
99
import { ICredDefWithCount, IPlatformSchemas } from '@credebl/common/interfaces/schema.interface';
10+
import { ISchemaId } from '../schema.interface';
1011

1112
@Injectable()
1213
export class SchemaRepository {
@@ -156,6 +157,18 @@ export class SchemaRepository {
156157
}
157158
}
158159

160+
async getSchemasDetailsBySchemaName(schemaName: string): Promise<ISchemaId[]> {
161+
const schemaDetails = await this.prisma.schema.findMany({
162+
where: {
163+
name: { contains: schemaName, mode: 'insensitive' }
164+
},
165+
166+
select: { schemaLedgerId: true }
167+
});
168+
169+
return schemaDetails;
170+
}
171+
159172
async getSchemasDetailsBySchemaIds(templateIds: string[]): Promise<schema[]> {
160173
try {
161174
const schemasResult = await this.prisma.schema.findMany({

apps/ledger/src/schema/schema.controller.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
ISchemasWithPagination
1717
} from '@credebl/common/interfaces/schema.interface';
1818
import { IschemaPayload } from './interfaces/schema.interface';
19+
import { ISchemaId } from './schema.interface';
1920

2021
@Controller('schema')
2122
export class SchemaController {
@@ -33,6 +34,11 @@ export class SchemaController {
3334
return this.schemaService.getSchemaDetails(templateIds);
3435
}
3536

37+
@MessagePattern({ cmd: 'get-schemas-details-by-name' })
38+
async getSchemasDetailsBySchemaName(schemaName: string): Promise<ISchemaId[]> {
39+
return this.schemaService.getSchemaDetailsBySchemaName(schemaName);
40+
}
41+
3642
@MessagePattern({ cmd: 'get-schema-by-id' })
3743
async getSchemaById(payload: ISchema): Promise<schema> {
3844
const { schemaId, orgId } = payload;

apps/ledger/src/schema/schema.interface.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import { IUserRequestInterface } from "./interfaces/schema.interface";
1+
import { IUserRequestInterface } from './interfaces/schema.interface';
22

3+
export interface ISchemaId {
4+
schemaLedgerId: string;
5+
}
36
export interface SchemaSearchCriteria {
47
schemaLedgerId: string;
58
credentialDefinitionId: string;

apps/ledger/src/schema/schema.service.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Prisma, schema } from '@prisma/client';
1313
import { ISaveSchema, ISchema, ISchemaCredDeffSearchInterface, ISchemaExist, ISchemaSearchCriteria, W3CCreateSchema } from './interfaces/schema-payload.interface';
1414
import { ResponseMessages } from '@credebl/common/response-messages';
1515
import { ICreateSchema, ICreateW3CSchema, IGenericSchema, IUserRequestInterface } from './interfaces/schema.interface';
16-
import { CreateSchemaAgentRedirection, GetSchemaAgentRedirection } from './schema.interface';
16+
import { CreateSchemaAgentRedirection, GetSchemaAgentRedirection, ISchemaId } from './schema.interface';
1717
import { map } from 'rxjs/operators';
1818
import { JSONSchemaType, LedgerLessConstant, LedgerLessMethods, OrgAgentType, SchemaType, SchemaTypeEnum } from '@credebl/enum/enum';
1919
import { ICredDefWithPagination, ISchemaData, ISchemaDetails, ISchemasWithPagination } from '@credebl/common/interfaces/schema.interface';
@@ -716,6 +716,15 @@ export class SchemaService extends BaseService {
716716
}
717717
}
718718

719+
async getSchemaDetailsBySchemaName(schemaName: string): Promise<ISchemaId[]> {
720+
try {
721+
const getSchemaDetails = await this.schemaRepository.getSchemasDetailsBySchemaName(schemaName);
722+
return getSchemaDetails;
723+
} catch (error) {
724+
throw new RpcException(error.response ? error.response : error);
725+
}
726+
}
727+
719728
async _getSchemaById(payload: GetSchemaAgentRedirection): Promise<{ response: string }> {
720729
try {
721730
const pattern = {

apps/verification/templates/out-of-band-verification.template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class OutOfBandVerification {
4444
<a href="${process.env.IOS_DOWNLOAD_LINK}" target="_blank">iOS App Store.</a> (Skip, if already downloaded)
4545
</li>
4646
<li>Complete the onboarding process in ${process.env.MOBILE_APP}.</li>
47-
<li>Open the “Share Credential” link below in this email <i>(This will open the link in the ${process.env.MOBILE_APP} App)</i></li>
47+
<li>Open the “Share Credential” link below in this email <i>(This will open the link in the ${process.env.MOBILE_APP})</i></li>
4848
<li>Tap the <b>"Send Proof"</b> button in ${process.env.MOBILE_APP} to share you credential data.</li>
4949
</ul>
5050
<div style="text-align: center; padding-bottom: 20px;">

0 commit comments

Comments
 (0)