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

fix: pagination, sorting feature functionality and schema validations bug #346

Merged
merged 5 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion apps/api-gateway/src/issuance/dtos/issuance.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class CredentialAttributes {

export class OutOfBandCredentialDto {

@ApiProperty({ example: [{ 'emailId': 'abc@example.com', 'attribute': [{ 'value': 'string', 'name': 'string' }] }] })
@ApiProperty({ example: [{ 'emailId': 'abc@example.com', 'attributes': [{ 'value': 'string', 'name': 'string' }] }] })
@IsNotEmpty({ message: 'Please provide valid attributes' })
@IsArray({ message: 'attributes should be array'})
@ArrayMaxSize(Number(process.env.OOB_BATCH_SIZE), { message: `Limit reached (${process.env.OOB_BATCH_SIZE} credentials max). Easily handle larger batches via seamless CSV file uploads`})
Expand Down
4 changes: 4 additions & 0 deletions apps/api-gateway/src/verification/dto/webhook-proof.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export class WebhookPresentationProof {
@IsOptional()
threadId: string;

@ApiProperty()
@IsOptional()
presentationId: string;

@ApiProperty()
@IsOptional()
autoAcceptProof: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class VerificationController {
@Param('proofId') id: string,
@Param('orgId') orgId: string
): Promise<object> {
const sendProofRequest = await this.verificationService.getProofFormData(id, orgId, user);
const sendProofRequest = await this.verificationService.getProofFormData(id, orgId, user);
const finalResponse: IResponseType = {
statusCode: HttpStatus.OK,
message: ResponseMessages.verification.success.proofFormData,
Expand Down
56 changes: 28 additions & 28 deletions apps/connection/src/connection.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class ConnectionRepository {
}

const walletLabelName = connectionDto?.theirLabel;
let maskedTheirLabel: string;
let maskedTheirLabel: string;
let firstLetters: string;
let maskedMiddleLetters: string;
let lastLetters: string;
Expand All @@ -117,34 +117,34 @@ export class ConnectionRepository {
firstLetters = walletLabelName.slice(0, 1);
maskedMiddleLetters = walletLabelName.slice(1).replace(/./g, '*');
maskedTheirLabel = firstLetters + maskedMiddleLetters;
break;
break;

case 3 < walletLabelName.length && 6 > walletLabelName.length:
firstLetters = walletLabelName.slice(0, 1);
lastLetters = walletLabelName.slice(-1);
maskedMiddleLetters = walletLabelName.slice(1, -1).replace(/./g, '*');
maskedTheirLabel = firstLetters + lastLetters + maskedMiddleLetters;
break;
maskedTheirLabel = firstLetters + maskedMiddleLetters + lastLetters;
break;

case 6 <= walletLabelName.length && 8 >= walletLabelName.length:
firstLetters = walletLabelName.slice(0, 2);
lastLetters = walletLabelName.slice(-2);
maskedMiddleLetters = walletLabelName.slice(2, -2).replace(/./g, '*');
maskedTheirLabel = firstLetters + lastLetters + maskedMiddleLetters;
break;
maskedTheirLabel = firstLetters + maskedMiddleLetters + lastLetters;
break;

case 8 < walletLabelName.length:
firstLetters = walletLabelName.slice(0, 3);
lastLetters = walletLabelName.slice(-3);
maskedMiddleLetters = walletLabelName.slice(3, -3).replace(/./g, '*');
maskedTheirLabel = firstLetters + lastLetters + maskedMiddleLetters;
break;
default:
maskedTheirLabel = walletLabelName;
break;
}
maskedTheirLabel = firstLetters + maskedMiddleLetters + lastLetters;
break;

default:
maskedTheirLabel = walletLabelName;
break;
}

const agentDetails = await this.prisma.connections.upsert({
where: {
connectionId: connectionDto?.id
Expand All @@ -171,7 +171,7 @@ export class ConnectionRepository {
throw error;
}
}

/**
* Description: Save ShorteningUrl details
* @param referenceId
Expand Down Expand Up @@ -274,23 +274,23 @@ export class ConnectionRepository {
connectionId: true
},
orderBy: {
[connectionSearchCriteria.sorting]:
'DESC' === connectionSearchCriteria.sortByValue
[connectionSearchCriteria?.sorting || 'createDateTime']:
'DESC' === connectionSearchCriteria?.sortByValue
? 'desc'
: 'ASC' === connectionSearchCriteria.sortByValue
? 'asc'
: 'desc'
: 'asc'
},
take: Number(connectionSearchCriteria.pageSize),
skip: (connectionSearchCriteria.pageNumber - 1) * connectionSearchCriteria.pageSize
});
const connectionCount = await this.prisma.connections.count({
where: {
organisation: {
id: orgId
where: {
orgId,
OR: [
{ theirLabel: { contains: connectionSearchCriteria.searchByText, mode: 'insensitive' } },
{ connectionId: { contains: connectionSearchCriteria.searchByText, mode: 'insensitive' } }
]
}
}
});
});

return { connectionCount, connectionsList };
} catch (error) {
Expand Down
3 changes: 3 additions & 0 deletions apps/connection/src/connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ export class ConnectionService {
throw new NotFoundException(ResponseMessages.connection.error.connectionNotFound);
}
} catch (error) {
; if (404 === error.status) {
throw new NotFoundException(error.response.message);
}
throw new RpcException(
`[getConnections] [NATS call]- error in fetch connections details : ${JSON.stringify(error)}`
);
Expand Down
17 changes: 9 additions & 8 deletions apps/issuance/src/issuance.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,22 @@ export class IssuanceRepository {
connectionId: true
},
orderBy: {
[issuedCredentialsSearchCriteria.sorting]:
'DESC' === issuedCredentialsSearchCriteria.sortByValue
[issuedCredentialsSearchCriteria?.sorting || 'createDateTime']:
'DESC' === issuedCredentialsSearchCriteria?.sortByValue
? 'desc'
: 'ASC' === issuedCredentialsSearchCriteria.sortByValue
? 'asc'
: 'desc'
: 'asc'
},
take: Number(issuedCredentialsSearchCriteria.pageSize),
skip: (issuedCredentialsSearchCriteria.pageNumber - 1) * issuedCredentialsSearchCriteria.pageSize
});

const issuedCredentialsCount = await this.prisma.credentials.count({
where: {
organisation: {
id: orgId
}
orgId,
OR: [
{ schemaId: { contains: issuedCredentialsSearchCriteria.searchByText, mode: 'insensitive' } },
{ connectionId: { contains: issuedCredentialsSearchCriteria.searchByText, mode: 'insensitive' } }
]
}
});

Expand Down
5 changes: 4 additions & 1 deletion apps/issuance/src/issuance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,12 @@ export class IssuanceService {
if (0 !== getIssuedCredentialsList.issuedCredentialsCount) {
return issuedCredentialsResponse;
} else {
throw new NotFoundException(ResponseMessages.connection.error.connectionNotFound);
throw new NotFoundException(ResponseMessages.issuance.error.credentialsNotFound);
}
} catch (error) {
if (404 === error.status) {
throw new NotFoundException(error.response.message);
}
throw new RpcException(
`[getConnections] [NATS call]- error in fetch connections details : ${JSON.stringify(error)}`
);
Expand Down
65 changes: 38 additions & 27 deletions apps/ledger/src/schema/schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ export class SchemaService extends BaseService {
const apiKey = '';
const { userId } = user.selectedOrg;
try {

const schemaExists = await this.schemaRepository.schemaExists(
schema.schemaName,
schema.schemaVersion
);

if (0 !== schemaExists.length) {
this.logger.error(ResponseMessages.schema.error.exists);
throw new ConflictException(ResponseMessages.schema.error.exists);
}

if (null !== schema || schema !== undefined) {
const schemaVersionIndexOf = -1;
if (
);
if (0 !== schemaExists.length) {
this.logger.error(ResponseMessages.schema.error.exists);
throw new ConflictException(ResponseMessages.schema.error.exists);
}
if (null !== schema || schema !== undefined) {
const schemaVersionIndexOf = -1;
if (
isNaN(parseFloat(schema.schemaVersion)) ||
schema.schemaVersion.toString().indexOf('.') ===
schemaVersionIndexOf
Expand All @@ -61,22 +62,32 @@ export class SchemaService extends BaseService {
if (schema.attributes.length === schemaAttributeLength) {
throw new NotAcceptableException(
ResponseMessages.schema.error.insufficientAttributes
);
} else if (schema.attributes.length > schemaAttributeLength) {

const trimmedAttributes = schema.attributes.map(attribute => ({
attributeName: attribute.attributeName.trim(),
schemaDataType: attribute.schemaDataType,
displayName: attribute.displayName
}));

const findDuplicates: boolean =
new Set(trimmedAttributes).size !== trimmedAttributes.length;
if (true === findDuplicates) {
throw new NotAcceptableException(
ResponseMessages.schema.error.invalidAttributes
);
}
} else if (schema.attributes.length > schemaAttributeLength) {

const trimmedAttributes = schema.attributes.map(attribute => ({
attributeName: attribute.attributeName.trim(),
schemaDataType: attribute.schemaDataType,
displayName: attribute.displayName.trim()
}));


const attributeNamesLowerCase = trimmedAttributes.map(attribute => attribute.attributeName.toLowerCase());
const duplicateAttributeNames = attributeNamesLowerCase
.filter((value, index, element) => element.indexOf(value) !== index);

if (0 < duplicateAttributeNames.length) {
throw new ConflictException(ResponseMessages.schema.error.uniqueAttributesnames);
}

const attributeDisplayNamesLowerCase = trimmedAttributes.map(attribute => attribute.displayName.toLocaleLowerCase());
const duplicateAttributeDisplayNames = attributeDisplayNamesLowerCase
.filter((value, index, element) => element.indexOf(value) !== index);

if (0 < duplicateAttributeDisplayNames.length) {
throw new ConflictException(ResponseMessages.schema.error.uniqueAttributesDisplaynames);
}

schema.schemaName = schema.schemaName.trim();
const { agentEndPoint, orgDid } = await this.schemaRepository.getAgentDetailsByOrgId(orgId);
const getAgentDetails = await this.schemaRepository.getAgentType(orgId);
Expand Down Expand Up @@ -134,7 +145,7 @@ export class SchemaService extends BaseService {

if ('finished' === responseObj.schema.state) {
schemaDetails.schema.schemaName = responseObj.schema.schema.name;
schemaDetails.schema.attributes = schema.attributes;
schemaDetails.schema.attributes = trimmedAttributes;
schemaDetails.schema.schemaVersion = responseObj.schema.schema.version;
schemaDetails.createdBy = userId;
schemaDetails.schema.id = responseObj.schema.schemaId;
Expand All @@ -151,7 +162,7 @@ export class SchemaService extends BaseService {

} else if ('finished' === responseObj.state) {
schemaDetails.schema.schemaName = responseObj.schema.name;
schemaDetails.schema.attributes = schema.attributes;
schemaDetails.schema.attributes = trimmedAttributes;
schemaDetails.schema.schemaVersion = responseObj.schema.version;
schemaDetails.createdBy = userId;
schemaDetails.schema.id = responseObj.schemaId;
Expand Down
1 change: 1 addition & 0 deletions apps/verification/src/interfaces/verification.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export interface IWebhookProofPresentation {
protocolVersion: string;
state: string;
connectionId: string;
presentationId: string;
threadId: string;
autoAcceptProof: string;
updatedAt: string;
Expand Down
20 changes: 11 additions & 9 deletions apps/verification/src/repositories/verification.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,25 @@ export class VerificationRepository {
orgId: true,
state: true,
connectionId: true,
id: true
id: true,
presentationId: true
},
orderBy: {
[proofRequestsSearchCriteria.sorting]:
'DESC' === proofRequestsSearchCriteria.sortByValue
[proofRequestsSearchCriteria?.sorting || 'createDateTime']:
'DESC' === proofRequestsSearchCriteria?.sortByValue
? 'desc'
: 'ASC' === proofRequestsSearchCriteria.sortByValue
? 'asc'
: 'desc'
: 'asc'
},
take: Number(proofRequestsSearchCriteria.pageSize),
skip: (proofRequestsSearchCriteria.pageNumber - 1) * proofRequestsSearchCriteria.pageSize
});
const proofRequestsCount = await this.prisma.presentations.count({
where: {
organisation: {
id: orgId
}
orgId,
OR: [
{ connectionId: { contains: proofRequestsSearchCriteria.searchByText, mode: 'insensitive' } },
{ state: { contains: proofRequestsSearchCriteria.searchByText, mode: 'insensitive' } }
]
}
});

Expand Down Expand Up @@ -139,6 +140,7 @@ export class VerificationRepository {
state: proofPresentationPayload.state,
threadId: proofPresentationPayload.threadId,
isVerified: proofPresentationPayload.isVerified,
presentationId: proofPresentationPayload.id,
orgId: organisationId
}
});
Expand Down
3 changes: 3 additions & 0 deletions apps/verification/src/verification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export class VerificationService {
throw new NotFoundException(ResponseMessages.verification.error.proofPresentationNotFound);
}
} catch (error) {
if (404 === error.status) {
throw new NotFoundException(error.response.message);
}
throw new RpcException(
`[getConnections] [NATS call]- error in fetch proof requests details : ${JSON.stringify(error)}`
);
Expand Down
11 changes: 6 additions & 5 deletions libs/common/src/response-messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ export const ResponseMessages = {
versionNotEmpty: 'Schema version is required',
invalidVersion: 'Invalid schema version provided.',
insufficientAttributes: 'Please provide at least one attribute.',
invalidAttributes: 'Please provide unique attributes',
uniqueAttributesnames: 'Please provide unique attribute names',
uniqueAttributesDisplaynames: 'Please provide unique display names for attributes',
emptyData: 'Please provide data for creating schema.',
exists: 'Schema already exists',
notCreated: 'Schema not created',
Expand Down Expand Up @@ -161,15 +162,15 @@ export const ResponseMessages = {
},
error: {
exists: 'Connection is already exist',
connectionNotFound: 'ConnectionNotFound not found',
connectionNotFound: 'Connection not found',
agentEndPointNotFound: 'agentEndPoint Not Found',
agentUrlNotFound: 'agent url not found'
}
},
issuance: {
success: {
create: 'Credentials offer created successfully',
fetch: 'Credentials offer send successfully',
fetch: 'Issued Credential details fetched successfully',
importCSV: 'File imported sucessfully',
previewCSV: 'File details fetched sucessfully',
bulkIssuance: 'Issuance process started. It will take some time',
Expand Down Expand Up @@ -200,7 +201,7 @@ export const ResponseMessages = {
},
verification: {
success: {
fetch: 'Proof presentation received successfully.',
fetch: 'Proof presentations details fetched successfully.',
proofFormData: 'Proof presentation form data received successfully.',
send: 'Proof request send successfully.',
verified: 'Proof presentation verified successfully.'
Expand All @@ -210,7 +211,7 @@ export const ResponseMessages = {
agentUrlNotFound: 'agent url not found',
schemaIdNotFound: 'Schema Id is required',
predicatesValueNotNumber: 'The attribuite value is not a number',
proofPresentationNotFound: 'Proof presentation not found',
proofPresentationNotFound: 'Proof presentations not found',
invitationNotFound: 'Invitation not found',
platformConfigNotFound: 'Platform config not found',
emailSend: 'Unable to send email to the user'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "presentations" ADD COLUMN "presentationId" TEXT;
Loading