@@ -4,7 +4,7 @@ import { PrismaService } from '@credebl/prisma-service';
4
4
import { ledgers , org_agents , org_agents_type , organisation , Prisma , schema } from '@prisma/client' ;
5
5
import { ISchema , ISchemaExist , ISchemaSearchCriteria , ISaveSchema } from '../interfaces/schema-payload.interface' ;
6
6
import { ResponseMessages } from '@credebl/common/response-messages' ;
7
- import { AgentDetails , ISchemasWithCount } from '../interfaces/schema.interface' ;
7
+ import { AgentDetails , ISchemasWithCount , IUpdateSchema , UpdateSchemaResponse } from '../interfaces/schema.interface' ;
8
8
import { SchemaType , SortValue } from '@credebl/enum/enum' ;
9
9
import { ICredDefWithCount , IPlatformSchemas } from '@credebl/common/interfaces/schema.interface' ;
10
10
import { ISchemaId } from '../schema.interface' ;
@@ -38,7 +38,8 @@ export class SchemaRepository {
38
38
orgId : schemaResult . orgId ,
39
39
ledgerId : schemaResult . ledgerId ,
40
40
type : schemaResult . type ,
41
- isSchemaArchived : false
41
+ isSchemaArchived : false ,
42
+ alias : schemaResult . alias
42
43
}
43
44
} ) ;
44
45
return saveResult ;
@@ -119,8 +120,9 @@ export class SchemaRepository {
119
120
publisherDid : true ,
120
121
orgId : true ,
121
122
issuerId : true ,
123
+ alias : true ,
122
124
organisation : {
123
- select :{
125
+ select : {
124
126
name : true ,
125
127
userOrgRoles : {
126
128
select : {
@@ -299,11 +301,11 @@ export class SchemaRepository {
299
301
try {
300
302
const { ledgerId, schemaType, searchByText, sortField, sortBy, pageSize, pageNumber } = payload ;
301
303
let schemaResult ;
302
- /**
303
- * This is made so because the default pageNumber is set to 1 in DTO,
304
+ /**
305
+ * This is made so because the default pageNumber is set to 1 in DTO,
304
306
* If there is any 'searchByText' field, we ignore the pageNumbers and search
305
307
* in all available records.
306
- *
308
+ *
307
309
* Because in that case pageNumber would be insignificant.
308
310
*/
309
311
if ( searchByText ) {
@@ -316,7 +318,8 @@ export class SchemaRepository {
316
318
{ name : { contains : searchByText , mode : 'insensitive' } } ,
317
319
{ version : { contains : searchByText , mode : 'insensitive' } } ,
318
320
{ schemaLedgerId : { contains : searchByText , mode : 'insensitive' } } ,
319
- { issuerId : { contains : searchByText , mode : 'insensitive' } }
321
+ { issuerId : { contains : searchByText , mode : 'insensitive' } } ,
322
+ { alias : { contains : searchByText , mode : 'insensitive' } }
320
323
]
321
324
} ,
322
325
select : {
@@ -328,9 +331,10 @@ export class SchemaRepository {
328
331
isSchemaArchived : true ,
329
332
createdBy : true ,
330
333
publisherDid : true ,
331
- orgId : true , // This field can be null
334
+ orgId : true , // This field can be null
332
335
issuerId : true ,
333
- type : true
336
+ type : true ,
337
+ alias : true
334
338
} ,
335
339
orderBy : {
336
340
[ sortField ] : SortValue . DESC === sortBy ? SortValue . DESC : SortValue . ASC
@@ -356,9 +360,10 @@ export class SchemaRepository {
356
360
isSchemaArchived : true ,
357
361
createdBy : true ,
358
362
publisherDid : true ,
359
- orgId : true , // This field can be null
363
+ orgId : true , // This field can be null
360
364
issuerId : true ,
361
- type : true
365
+ type : true ,
366
+ alias : true
362
367
} ,
363
368
orderBy : {
364
369
[ sortField ] : SortValue . DESC === sortBy ? SortValue . DESC : SortValue . ASC
@@ -376,7 +381,7 @@ export class SchemaRepository {
376
381
} ) ;
377
382
378
383
// Handle null orgId in the response
379
- const schemasWithDefaultOrgId = schemaResult . map ( schema => ( {
384
+ const schemasWithDefaultOrgId = schemaResult . map ( ( schema ) => ( {
380
385
...schema ,
381
386
orgId : schema . orgId || null // Replace null orgId with 'N/A' or any default value
382
387
} ) ) ;
@@ -429,21 +434,23 @@ export class SchemaRepository {
429
434
}
430
435
}
431
436
432
- async schemaExist ( payload : ISchemaExist ) : Promise < {
433
- id : string ;
434
- createDateTime : Date ;
435
- createdBy : string ;
436
- lastChangedDateTime : Date ;
437
- lastChangedBy : string ;
438
- name : string ;
439
- version : string ;
440
- attributes : string ;
441
- schemaLedgerId : string ;
442
- publisherDid : string ;
443
- issuerId : string ;
444
- orgId : string ;
445
- ledgerId : string ;
446
- } [ ] > {
437
+ async schemaExist ( payload : ISchemaExist ) : Promise <
438
+ {
439
+ id : string ;
440
+ createDateTime : Date ;
441
+ createdBy : string ;
442
+ lastChangedDateTime : Date ;
443
+ lastChangedBy : string ;
444
+ name : string ;
445
+ version : string ;
446
+ attributes : string ;
447
+ schemaLedgerId : string ;
448
+ publisherDid : string ;
449
+ issuerId : string ;
450
+ orgId : string ;
451
+ ledgerId : string ;
452
+ } [ ]
453
+ > {
447
454
try {
448
455
return this . prisma . schema . findMany ( {
449
456
where : {
@@ -456,4 +463,18 @@ export class SchemaRepository {
456
463
throw error ;
457
464
}
458
465
}
466
+
467
+ async updateSchema ( schemaDetails : IUpdateSchema ) : Promise < UpdateSchemaResponse > {
468
+ const { alias, schemaLedgerId, orgId } = schemaDetails ;
469
+
470
+ try {
471
+ return await this . prisma . schema . updateMany ( {
472
+ where : orgId ? { schemaLedgerId, orgId } : { schemaLedgerId } ,
473
+ data : { alias }
474
+ } ) ;
475
+ } catch ( error ) {
476
+ this . logger . error ( `Error in updating schema details: ${ error } ` ) ;
477
+ throw error ;
478
+ }
479
+ }
459
480
}
0 commit comments