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: added temaplateId column in file_upload table #842

Merged
merged 24 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c811f9d
fix: send email verification issue
bhavanakarwade Jul 2, 2024
8ee3ee5
Merge branch 'develop' of https://github.com/credebl/platform into fi…
bhavanakarwade Jul 3, 2024
5c98415
refcator: schema endorsement flow
bhavanakarwade Jul 5, 2024
b13e3a0
Merge branch 'develop' of https://github.com/credebl/platform into fi…
bhavanakarwade Jul 5, 2024
4f63200
fix: resolved sonar lint issues
bhavanakarwade Jul 5, 2024
80671ed
fix: worked on sonarcloud issues
bhavanakarwade Jul 5, 2024
4e7dd55
fix: delete organization bugs
bhavanakarwade Jul 8, 2024
bee5fc3
Merge branch 'develop' of https://github.com/credebl/platform into fi…
bhavanakarwade Jul 8, 2024
3b0936b
fix: cred def id space fixes
bhavanakarwade Jul 9, 2024
9c80531
Merge branch 'develop' of https://github.com/credebl/platform into fi…
bhavanakarwade Jul 9, 2024
81b19b7
Merge branch 'develop' of https://github.com/credebl/platform into fi…
bhavanakarwade Jul 10, 2024
62ca670
Merge branch 'develop' of https://github.com/credebl/platform into fi…
bhavanakarwade Jul 10, 2024
d90986e
fix: create organization bug
bhavanakarwade Jul 11, 2024
29cbe57
Merge branch 'develop' of https://github.com/credebl/platform into fi…
bhavanakarwade Jul 11, 2024
aebc54b
fix: pagination issue for preview file
bhavanakarwade Jul 11, 2024
a7c20cb
resolved conflicts
bhavanakarwade Jul 11, 2024
fe8035b
fix: pagination issue
bhavanakarwade Jul 11, 2024
60c9663
fix: imageurl issue in verification
bhavanakarwade Jul 11, 2024
6325d77
Merge branch 'develop' of https://github.com/credebl/platform into fi…
bhavanakarwade Jul 11, 2024
3f6a7de
Merge branch 'develop' of https://github.com/credebl/platform into fi…
bhavanakarwade Jul 12, 2024
e2c6ec0
fix: made request if parameter optional
bhavanakarwade Jul 12, 2024
355e679
Merge branch 'develop' of https://github.com/credebl/platform into fi…
bhavanakarwade Jul 12, 2024
32baed0
refactor: added templateId mapping in file upload functionality
bhavanakarwade Jul 13, 2024
e6a1ff4
refactor: interface types
bhavanakarwade Jul 15, 2024
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
3 changes: 2 additions & 1 deletion apps/issuance/interfaces/issuance.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ export interface FileUpload {
orgId?: string,
createDateTime?: Date | null,
lastChangedDateTime?: Date | null,
credentialType?: string
credentialType?: string,
templateId?: string
}

export interface FileUploadData {
Expand Down
6 changes: 4 additions & 2 deletions apps/issuance/src/issuance.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export class IssuanceRepository {

async saveFileUploadDetails(fileUploadPayload: FileUpload, userId: string): Promise<file_upload> {
try {
const { name, status, upload_type, orgId, credentialType } = fileUploadPayload;
const { name, status, upload_type, orgId, credentialType, templateId } = fileUploadPayload;
return this.prisma.file_upload.create({
data: {
name: String(name),
Expand All @@ -320,7 +320,8 @@ export class IssuanceRepository {
upload_type,
createdBy: userId,
lastChangedBy: userId,
credential_type: credentialType
credential_type: credentialType,
templateId
}
});
} catch (error) {
Expand Down Expand Up @@ -379,6 +380,7 @@ export class IssuanceRepository {
deletedAt: Date;
failedRecords: number;
totalRecords: number;
templateId: string;
}[];
}> {
try {
Expand Down
42 changes: 39 additions & 3 deletions apps/issuance/src/issuance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { sendEmail } from '@credebl/common/send-grid-helper-file';
import * as pLimit from 'p-limit';
import { UserActivityRepository } from 'libs/user-activity/repositories';
import { validateW3CSchemaAttributes } from '../libs/helpers/attributes.validator';
import { ISchemaDetail } from '@credebl/common/interfaces/schema.interface';


@Injectable()
Expand Down Expand Up @@ -1153,14 +1154,27 @@ async sendEmailForCredentialOffer(sendEmailCredentialOffer: SendEmailCredentialO
try {

const fileDetails = await this.issuanceRepository.getAllFileDetails(orgId, getAllfileDetails);

const templateIds = fileDetails?.fileList.map(file => file.templateId);

const getSchemaDetails = await this._getSchemaDetails(templateIds);

const fileListWithSchema = fileDetails?.fileList.map(file => {
const schemaDetail = getSchemaDetails?.find(schema => schema.schemaLedgerId === file.templateId);
return {
...file,
schema: schemaDetail ? { name: schemaDetail.name, version: schemaDetail.version, schemaType: schemaDetail.type } : null
};
});

const fileResponse = {
totalItems: fileDetails.fileCount,
hasNextPage: getAllfileDetails.pageSize * getAllfileDetails.pageNumber < fileDetails.fileCount,
hasPreviousPage: 1 < getAllfileDetails.pageNumber,
nextPage: Number(getAllfileDetails.pageNumber) + 1,
previousPage: getAllfileDetails.pageNumber - 1,
lastPage: Math.ceil(fileDetails.fileCount / getAllfileDetails.pageSize),
data: fileDetails.fileList
data: fileListWithSchema
};

if (0 !== fileDetails.fileCount) {
Expand All @@ -1175,6 +1189,29 @@ async sendEmailForCredentialOffer(sendEmailCredentialOffer: SendEmailCredentialO
}
}

async _getSchemaDetails(templateIds: string[]): Promise<ISchemaDetail[]> {
const pattern = { cmd: 'get-schemas-details' };

const payload = {
templateIds
};
const schemaDetails = await this.issuanceServiceProxy
.send(pattern, payload)
.toPromise()
.catch((error) => {
this.logger.error(`catch: ${JSON.stringify(error)}`);
throw new HttpException(
{
status: error.status,
error: error.message
},
error.status
);
});
return schemaDetails;
}


async delay(ms): Promise<unknown> {
return new Promise(resolve => setTimeout(resolve, ms));
}
Expand Down Expand Up @@ -1298,7 +1335,6 @@ async sendEmailForCredentialOffer(sendEmailCredentialOffer: SendEmailCredentialO
throw new BadRequestException(ResponseMessages.issuance.error.cachedData);
}
const parsedFileDetails = JSON.parse(cachedData as string);

if (!parsedFileDetails) {
throw new BadRequestException(ResponseMessages.issuance.error.cachedfileData);
}
Expand All @@ -1309,7 +1345,7 @@ async sendEmailForCredentialOffer(sendEmailCredentialOffer: SendEmailCredentialO
fileUpload.createDateTime = new Date();
fileUpload.name = parsedFileDetails.fileName;
fileUpload.credentialType = parsedFileDetails.credentialType;

fileUpload.templateId = parsedFileDetails?.schemaLedgerId;
csvFileDetail = await this.issuanceRepository.saveFileUploadDetails(fileUpload, clientDetails.userId);

const bulkPayloadObject: IBulkPayloadObject = {
Expand Down
16 changes: 16 additions & 0 deletions apps/ledger/src/schema/repositories/schema.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ export class SchemaRepository {
}
}

async getSchemasDetailsBySchemaIds(templateIds: string[]): Promise<schema[]> {
try {
const schemasResult = await this.prisma.schema.findMany({
where: {
schemaLedgerId: {
in: templateIds
}
}
});
return schemasResult;
} catch (error) {
this.logger.error(`Error in getting agent DID: ${error}`);
throw error;
}
}

async getAgentDetailsByOrgId(orgId: string): Promise<AgentDetails> {
try {
const schemasResult = await this.prisma.org_agents.findFirst({
Expand Down
5 changes: 5 additions & 0 deletions apps/ledger/src/schema/schema.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export class SchemaController {
return this.schemaService.createSchema(schemaDetails, user, orgId);
}

@MessagePattern({ cmd: 'get-schemas-details' })
async getSchemasDetails(payload: {templateIds: string[]}): Promise<schema[]> {
const { templateIds } = payload;
return this.schemaService.getSchemaDetails(templateIds);
}

@MessagePattern({ cmd: 'get-schema-by-id' })
async getSchemaById(payload: ISchema): Promise<schema> {
Expand Down
9 changes: 9 additions & 0 deletions apps/ledger/src/schema/schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,15 @@ export class SchemaService extends BaseService {
}
}

async getSchemaDetails(templateIds: string[]): Promise<schema[]> {
try {
const getSchemaData = await this.schemaRepository.getSchemasDetailsBySchemaIds(templateIds);
return getSchemaData;
} catch (error) {
throw new RpcException(error.response ? error.response : error);
}
}

async _getSchemaById(payload: GetSchemaAgentRedirection): Promise<{ response: string }> {
try {
const pattern = {
Expand Down
23 changes: 23 additions & 0 deletions libs/common/src/interfaces/schema.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ export interface ISchemasWithPagination extends IPaginationDetails{
issuerId: string;
}

interface Attribute {
attributeName: string;
schemaDataType: string;
displayName: string;
isRequired: boolean;
}

export interface ISchemaDetail {
id: string;
createDateTime: string;
createdBy: string;
lastChangedDateTime: string;
lastChangedBy: string;
name: string;
version: string;
attributes: Attribute[];
schemaLedgerId: string;
publisherDid: string;
issuerId: string;
orgId: string;
ledgerId: string;
type: string;
}

export interface IPlatformSchemas {
schemasCount: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "file_upload" ADD COLUMN "templateId" VARCHAR;
1 change: 1 addition & 0 deletions libs/prisma-service/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ model file_upload {
organisation organisation? @relation(fields: [orgId], references: [id])
orgId String? @db.Uuid
credential_type String?
templateId String? @db.VarChar
}

model file_data {
Expand Down