Skip to content

Commit 2e4e6fd

Browse files
authored
Merge pull request #1314 from credebl/feat/include_org_name_in_all_schema_api
Included organization name in all schema api for schema list
2 parents fca8aba + 0ca57b2 commit 2e4e6fd

File tree

3 files changed

+137
-120
lines changed

3 files changed

+137
-120
lines changed

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
import { AgentDetails, ISchemasWithCount, IUpdateSchema, UpdateSchemaResponse } from '../interfaces/schema.interface';
12
/* eslint-disable camelcase */
23
import { ConflictException, Injectable, InternalServerErrorException, Logger } from '@nestjs/common';
3-
import { PrismaService } from '@credebl/prisma-service';
4-
import { ledgers, org_agents, org_agents_type, organisation, Prisma, schema } from '@prisma/client';
5-
import { ISchema, ISchemaExist, ISchemaSearchCriteria, ISaveSchema } from '../interfaces/schema-payload.interface';
6-
import { ResponseMessages } from '@credebl/common/response-messages';
7-
import { AgentDetails, ISchemasWithCount, IUpdateSchema, UpdateSchemaResponse } from '../interfaces/schema.interface';
4+
import { ICredDefWithCount, IPlatformSchemasWithOrg } from '@credebl/common/interfaces/schema.interface';
5+
import { ISaveSchema, ISchema, ISchemaExist, ISchemaSearchCriteria } from '../interfaces/schema-payload.interface';
6+
import { Prisma, ledgers, org_agents, org_agents_type, organisation, schema } from '@prisma/client';
87
import { SchemaType, SortValue } from '@credebl/enum/enum';
9-
import { ICredDefWithCount, IPlatformSchemas } from '@credebl/common/interfaces/schema.interface';
8+
109
import { ISchemaId } from '../schema.interface';
10+
import { PrismaService } from '@credebl/prisma-service';
11+
import { ResponseMessages } from '@credebl/common/response-messages';
1112

1213
@Injectable()
1314
export class SchemaRepository {
@@ -297,7 +298,7 @@ export class SchemaRepository {
297298
}
298299
}
299300

300-
async getAllSchemaDetails(payload: ISchemaSearchCriteria): Promise<IPlatformSchemas> {
301+
async getAllSchemaDetails(payload: ISchemaSearchCriteria): Promise<IPlatformSchemasWithOrg> {
301302
try {
302303
const { ledgerId, schemaType, searchByText, sortField, sortBy, pageSize, pageNumber } = payload;
303304
let schemaResult;
@@ -334,7 +335,12 @@ export class SchemaRepository {
334335
orgId: true, // This field can be null
335336
issuerId: true,
336337
type: true,
337-
alias: true
338+
alias: true,
339+
organisation: {
340+
select: {
341+
name: true
342+
}
343+
}
338344
},
339345
orderBy: {
340346
[sortField]: SortValue.DESC === sortBy ? SortValue.DESC : SortValue.ASC
@@ -363,7 +369,12 @@ export class SchemaRepository {
363369
orgId: true, // This field can be null
364370
issuerId: true,
365371
type: true,
366-
alias: true
372+
alias: true,
373+
organisation: {
374+
select: {
375+
name: true
376+
}
377+
}
367378
},
368379
orderBy: {
369380
[sortField]: SortValue.DESC === sortBy ? SortValue.DESC : SortValue.ASC
@@ -468,13 +479,13 @@ export class SchemaRepository {
468479
const { alias, schemaLedgerId, orgId } = schemaDetails;
469480

470481
try {
471-
return await this.prisma.schema.updateMany({
472-
where: orgId ? { schemaLedgerId, orgId } : { schemaLedgerId },
473-
data: { alias }
474-
});
482+
return await this.prisma.schema.updateMany({
483+
where: orgId ? { schemaLedgerId, orgId } : { schemaLedgerId },
484+
data: { alias }
485+
});
475486
} catch (error) {
476487
this.logger.error(`Error in updating schema details: ${error}`);
477488
throw error;
478489
}
479490
}
480-
}
491+
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ export class SchemaService extends BaseService {
360360
}
361361

362362
private async storeW3CSchemas(schemaDetails, user, orgId, attributes, alias): Promise<schema> {
363-
364363
let ledgerDetails;
365364
const schemaServerUrl = `${process.env.SCHEMA_FILE_SERVER_URL}${schemaDetails.schemaId}`;
366365
const schemaRequest = await this.commonService.httpGet(schemaServerUrl).then(async (response) => response);
@@ -658,10 +657,9 @@ export class SchemaService extends BaseService {
658657
async getAllSchema(schemaSearchCriteria: ISchemaSearchCriteria): Promise<ISchemaDetails> {
659658
try {
660659
const response = await this.schemaRepository.getAllSchemaDetails(schemaSearchCriteria);
661-
662660
const schemasDetails = response?.schemasResult.map((schemaAttributeItem) => {
663661
const attributes = JSON.parse(schemaAttributeItem.attributes);
664-
return { ...schemaAttributeItem, attributes };
662+
return { ...schemaAttributeItem, attributes, organizationName: schemaAttributeItem.organisation.name };
665663
});
666664

667665
const schemasResponse = {
Lines changed: 111 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
export interface IPaginationDetails {
32
totalItems: number;
43
hasNextPage: boolean;
@@ -8,111 +7,120 @@ export interface IPaginationDetails {
87
lastPage: number;
98
}
109

10+
export interface ISchemasWithPagination extends IPaginationDetails {
11+
data: ISchemaData[];
12+
}
13+
14+
export interface ISchemaData extends ISchema {
15+
orgId: string;
16+
}
1117

12-
export interface ISchemasWithPagination extends IPaginationDetails{
13-
data: ISchemaData[];
14-
}
18+
export interface ISchemaDetails extends IPaginationDetails {
19+
data: ISchema[];
20+
}
1521

16-
export interface ISchemaData extends ISchema {
17-
orgId: string;
18-
}
22+
export interface IW3CSchema {
23+
response: {
24+
did: string;
25+
schemaId: string;
26+
schemaTxnHash: string;
27+
resourceTxnHash: string;
28+
};
29+
}
30+
interface ISchema {
31+
createDateTime: Date;
32+
createdBy: string;
33+
name: string;
34+
schemaLedgerId: string;
35+
version: string;
36+
attributes: string;
37+
publisherDid: string;
38+
issuerId: string;
39+
}
1940

20-
export interface ISchemaDetails extends IPaginationDetails{
21-
data: ISchema[];
22-
}
41+
interface Attribute {
42+
attributeName: string;
43+
schemaDataType: string;
44+
displayName: string;
45+
isRequired: boolean;
46+
}
2347

24-
export interface IW3CSchema {
25-
response: {
26-
did: string,
27-
schemaId: string,
28-
schemaTxnHash: string,
29-
resourceTxnHash: string
30-
}
31-
}
32-
interface ISchema {
33-
createDateTime: Date;
34-
createdBy: string;
48+
export interface ISchemaDetail {
49+
id: string;
50+
createDateTime: string;
51+
createdBy: string;
52+
lastChangedDateTime: string;
53+
lastChangedBy: string;
54+
name: string;
55+
version: string;
56+
attributes: Attribute[];
57+
schemaLedgerId: string;
58+
publisherDid: string;
59+
issuerId: string;
60+
orgId: string;
61+
ledgerId: string;
62+
type: string;
63+
isSchemaArchived: boolean;
64+
organisation: {
3565
name: string;
36-
schemaLedgerId: string;
37-
version: string;
38-
attributes: string;
39-
publisherDid: string;
40-
issuerId: string;
41-
}
42-
43-
interface Attribute {
44-
attributeName: string;
45-
schemaDataType: string;
46-
displayName: string;
47-
isRequired: boolean;
48-
}
49-
50-
export interface ISchemaDetail {
51-
id: string;
52-
createDateTime: string;
53-
createdBy: string;
54-
lastChangedDateTime: string;
55-
lastChangedBy: string;
66+
};
67+
}
68+
69+
export interface IPlatformSchemas {
70+
schemasCount: number;
71+
schemasResult: ISchemaData[];
72+
}
73+
74+
export interface ICredDefData {
75+
tag: string;
76+
credentialDefinitionId: string;
77+
schemaLedgerId: string;
78+
revocable: boolean;
79+
createDateTime?: Date;
80+
}
81+
82+
export interface ICredDefWithPagination extends IPaginationDetails {
83+
data: ICredDefData[];
84+
}
85+
86+
export interface ICredDefWithCount {
87+
credDefCount: number;
88+
credDefResult: ICredDefData[];
89+
}
90+
91+
export interface INetworkUrl {
92+
networkUrl: string;
93+
}
94+
95+
export interface ISchemaFields {
96+
name?: string;
97+
schemaName?: string;
98+
attributes?: IIndySchemaAttributesValue[];
99+
schemaAttributes?: IW3CSchemaAttributesValue[];
100+
endorse?: boolean;
101+
version?: string;
102+
did?: string;
103+
description?: string;
104+
}
105+
106+
interface IIndySchemaAttributesValue {
107+
attributeName: string;
108+
schemaDataType: string;
109+
displayName: string;
110+
}
111+
112+
interface IW3CSchemaAttributesValue {
113+
title: string;
114+
type: string;
115+
}
116+
117+
export interface ISchemaDataWithOrg extends ISchemaData {
118+
organisation: {
56119
name: string;
57-
version: string;
58-
attributes: Attribute[];
59-
schemaLedgerId: string;
60-
publisherDid: string;
61-
issuerId: string;
62-
orgId: string;
63-
ledgerId: string;
64-
type: string;
65-
isSchemaArchived: boolean,
66-
organisation: {
67-
name: string
68-
}
69-
}
70-
71-
export interface IPlatformSchemas {
72-
schemasCount: number;
73-
schemasResult: ISchemaData[];
74-
}
75-
76-
export interface ICredDefData {
77-
tag: string;
78-
credentialDefinitionId: string;
79-
schemaLedgerId: string;
80-
revocable: boolean;
81-
createDateTime?: Date;
82-
}
83-
84-
export interface ICredDefWithPagination extends IPaginationDetails{
85-
data: ICredDefData[];
86-
}
87-
88-
export interface ICredDefWithCount {
89-
credDefCount: number;
90-
credDefResult: ICredDefData[];
91-
}
92-
93-
export interface INetworkUrl {
94-
networkUrl: string;
95-
}
96-
97-
export interface ISchemaFields {
98-
name?: string;
99-
schemaName?: string;
100-
attributes?: IIndySchemaAttributesValue[];
101-
schemaAttributes?: IW3CSchemaAttributesValue[];
102-
endorse?: boolean;
103-
version?: string;
104-
did?: string;
105-
description?: string;
106-
}
107-
108-
interface IIndySchemaAttributesValue {
109-
attributeName: string;
110-
schemaDataType: string;
111-
displayName: string;
112-
}
113-
114-
interface IW3CSchemaAttributesValue {
115-
title: string;
116-
type: string;
117-
}
118-
120+
};
121+
}
122+
123+
export interface IPlatformSchemasWithOrg {
124+
schemasCount: number;
125+
schemasResult: ISchemaDataWithOrg[];
126+
}

0 commit comments

Comments
 (0)