Skip to content

Included organization name in all schema api for schema list #1314

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

Merged
merged 1 commit into from
Jul 16, 2025
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
39 changes: 25 additions & 14 deletions apps/ledger/src/schema/repositories/schema.repository.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { AgentDetails, ISchemasWithCount, IUpdateSchema, UpdateSchemaResponse } from '../interfaces/schema.interface';
/* eslint-disable camelcase */
import { ConflictException, Injectable, InternalServerErrorException, Logger } from '@nestjs/common';
import { PrismaService } from '@credebl/prisma-service';
import { ledgers, org_agents, org_agents_type, organisation, Prisma, schema } from '@prisma/client';
import { ISchema, ISchemaExist, ISchemaSearchCriteria, ISaveSchema } from '../interfaces/schema-payload.interface';
import { ResponseMessages } from '@credebl/common/response-messages';
import { AgentDetails, ISchemasWithCount, IUpdateSchema, UpdateSchemaResponse } from '../interfaces/schema.interface';
import { ICredDefWithCount, IPlatformSchemasWithOrg } from '@credebl/common/interfaces/schema.interface';
import { ISaveSchema, ISchema, ISchemaExist, ISchemaSearchCriteria } from '../interfaces/schema-payload.interface';
import { Prisma, ledgers, org_agents, org_agents_type, organisation, schema } from '@prisma/client';
import { SchemaType, SortValue } from '@credebl/enum/enum';
import { ICredDefWithCount, IPlatformSchemas } from '@credebl/common/interfaces/schema.interface';

import { ISchemaId } from '../schema.interface';
import { PrismaService } from '@credebl/prisma-service';
import { ResponseMessages } from '@credebl/common/response-messages';

@Injectable()
export class SchemaRepository {
Expand Down Expand Up @@ -297,7 +298,7 @@ export class SchemaRepository {
}
}

async getAllSchemaDetails(payload: ISchemaSearchCriteria): Promise<IPlatformSchemas> {
async getAllSchemaDetails(payload: ISchemaSearchCriteria): Promise<IPlatformSchemasWithOrg> {
try {
const { ledgerId, schemaType, searchByText, sortField, sortBy, pageSize, pageNumber } = payload;
let schemaResult;
Expand Down Expand Up @@ -334,7 +335,12 @@ export class SchemaRepository {
orgId: true, // This field can be null
issuerId: true,
type: true,
alias: true
alias: true,
organisation: {
select: {
name: true
}
}
},
orderBy: {
[sortField]: SortValue.DESC === sortBy ? SortValue.DESC : SortValue.ASC
Expand Down Expand Up @@ -363,7 +369,12 @@ export class SchemaRepository {
orgId: true, // This field can be null
issuerId: true,
type: true,
alias: true
alias: true,
organisation: {
select: {
name: true
}
}
},
orderBy: {
[sortField]: SortValue.DESC === sortBy ? SortValue.DESC : SortValue.ASC
Expand Down Expand Up @@ -468,13 +479,13 @@ export class SchemaRepository {
const { alias, schemaLedgerId, orgId } = schemaDetails;

try {
return await this.prisma.schema.updateMany({
where: orgId ? { schemaLedgerId, orgId } : { schemaLedgerId },
data: { alias }
});
return await this.prisma.schema.updateMany({
where: orgId ? { schemaLedgerId, orgId } : { schemaLedgerId },
data: { alias }
});
} catch (error) {
this.logger.error(`Error in updating schema details: ${error}`);
throw error;
}
}
}
}
4 changes: 1 addition & 3 deletions apps/ledger/src/schema/schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ export class SchemaService extends BaseService {
}

private async storeW3CSchemas(schemaDetails, user, orgId, attributes, alias): Promise<schema> {

let ledgerDetails;
const schemaServerUrl = `${process.env.SCHEMA_FILE_SERVER_URL}${schemaDetails.schemaId}`;
const schemaRequest = await this.commonService.httpGet(schemaServerUrl).then(async (response) => response);
Expand Down Expand Up @@ -658,10 +657,9 @@ export class SchemaService extends BaseService {
async getAllSchema(schemaSearchCriteria: ISchemaSearchCriteria): Promise<ISchemaDetails> {
try {
const response = await this.schemaRepository.getAllSchemaDetails(schemaSearchCriteria);

const schemasDetails = response?.schemasResult.map((schemaAttributeItem) => {
const attributes = JSON.parse(schemaAttributeItem.attributes);
return { ...schemaAttributeItem, attributes };
return { ...schemaAttributeItem, attributes, organizationName: schemaAttributeItem.organisation.name };
});

const schemasResponse = {
Expand Down
214 changes: 111 additions & 103 deletions libs/common/src/interfaces/schema.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export interface IPaginationDetails {
totalItems: number;
hasNextPage: boolean;
Expand All @@ -8,111 +7,120 @@ export interface IPaginationDetails {
lastPage: number;
}

export interface ISchemasWithPagination extends IPaginationDetails {
data: ISchemaData[];
}

export interface ISchemaData extends ISchema {
orgId: string;
}

export interface ISchemasWithPagination extends IPaginationDetails{
data: ISchemaData[];
}
export interface ISchemaDetails extends IPaginationDetails {
data: ISchema[];
}

export interface ISchemaData extends ISchema {
orgId: string;
}
export interface IW3CSchema {
response: {
did: string;
schemaId: string;
schemaTxnHash: string;
resourceTxnHash: string;
};
}
interface ISchema {
createDateTime: Date;
createdBy: string;
name: string;
schemaLedgerId: string;
version: string;
attributes: string;
publisherDid: string;
issuerId: string;
}

export interface ISchemaDetails extends IPaginationDetails{
data: ISchema[];
}
interface Attribute {
attributeName: string;
schemaDataType: string;
displayName: string;
isRequired: boolean;
}

export interface IW3CSchema {
response: {
did: string,
schemaId: string,
schemaTxnHash: string,
resourceTxnHash: string
}
}
interface ISchema {
createDateTime: Date;
createdBy: string;
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;
isSchemaArchived: boolean;
organisation: {
name: string;
schemaLedgerId: string;
version: string;
attributes: string;
publisherDid: string;
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;
};
}

export interface IPlatformSchemas {
schemasCount: number;
schemasResult: ISchemaData[];
}

export interface ICredDefData {
tag: string;
credentialDefinitionId: string;
schemaLedgerId: string;
revocable: boolean;
createDateTime?: Date;
}

export interface ICredDefWithPagination extends IPaginationDetails {
data: ICredDefData[];
}

export interface ICredDefWithCount {
credDefCount: number;
credDefResult: ICredDefData[];
}

export interface INetworkUrl {
networkUrl: string;
}

export interface ISchemaFields {
name?: string;
schemaName?: string;
attributes?: IIndySchemaAttributesValue[];
schemaAttributes?: IW3CSchemaAttributesValue[];
endorse?: boolean;
version?: string;
did?: string;
description?: string;
}

interface IIndySchemaAttributesValue {
attributeName: string;
schemaDataType: string;
displayName: string;
}

interface IW3CSchemaAttributesValue {
title: string;
type: string;
}

export interface ISchemaDataWithOrg extends ISchemaData {
organisation: {
name: string;
version: string;
attributes: Attribute[];
schemaLedgerId: string;
publisherDid: string;
issuerId: string;
orgId: string;
ledgerId: string;
type: string;
isSchemaArchived: boolean,
organisation: {
name: string
}
}

export interface IPlatformSchemas {
schemasCount: number;
schemasResult: ISchemaData[];
}

export interface ICredDefData {
tag: string;
credentialDefinitionId: string;
schemaLedgerId: string;
revocable: boolean;
createDateTime?: Date;
}

export interface ICredDefWithPagination extends IPaginationDetails{
data: ICredDefData[];
}

export interface ICredDefWithCount {
credDefCount: number;
credDefResult: ICredDefData[];
}

export interface INetworkUrl {
networkUrl: string;
}

export interface ISchemaFields {
name?: string;
schemaName?: string;
attributes?: IIndySchemaAttributesValue[];
schemaAttributes?: IW3CSchemaAttributesValue[];
endorse?: boolean;
version?: string;
did?: string;
description?: string;
}

interface IIndySchemaAttributesValue {
attributeName: string;
schemaDataType: string;
displayName: string;
}

interface IW3CSchemaAttributesValue {
title: string;
type: string;
}

};
}

export interface IPlatformSchemasWithOrg {
schemasCount: number;
schemasResult: ISchemaDataWithOrg[];
}