1
1
/* eslint-disable camelcase */
2
2
import { ConflictException , Injectable , InternalServerErrorException , Logger } from '@nestjs/common' ;
3
3
import { PrismaService } from '@credebl/prisma-service' ;
4
- import { ledgers , org_agents , org_agents_type , organisation , schema } from '@prisma/client' ;
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
7
import { AgentDetails , ISchemasWithCount } from '../interfaces/schema.interface' ;
@@ -36,7 +36,8 @@ export class SchemaRepository {
36
36
publisherDid : schemaResult . issuerId . split ( ':' ) [ 4 ] || schemaResult . issuerId ,
37
37
orgId : schemaResult . orgId ,
38
38
ledgerId : schemaResult . ledgerId ,
39
- type : schemaResult . type
39
+ type : schemaResult . type ,
40
+ isSchemaArchived : false
40
41
}
41
42
} ) ;
42
43
return saveResult ;
@@ -77,6 +78,7 @@ export class SchemaRepository {
77
78
return this . prisma . schema . findMany ( {
78
79
where : {
79
80
type : SchemaType . INDY ,
81
+ isSchemaArchived : false ,
80
82
name : {
81
83
contains : schemaName ,
82
84
mode : 'insensitive'
@@ -98,6 +100,7 @@ export class SchemaRepository {
98
100
const schemasResult = await this . prisma . schema . findMany ( {
99
101
where : {
100
102
organisation : { id : orgId } ,
103
+ isSchemaArchived : false ,
101
104
OR : [
102
105
{ name : { contains : payload . searchByText , mode : 'insensitive' } } ,
103
106
{ version : { contains : payload . searchByText , mode : 'insensitive' } } ,
@@ -176,6 +179,24 @@ export class SchemaRepository {
176
179
}
177
180
}
178
181
182
+ async archiveSchemasByDid ( did : string ) : Promise < Prisma . BatchPayload > {
183
+ try {
184
+ const schemasResult = await this . prisma . schema . updateMany ( {
185
+ where : {
186
+ issuerId : did
187
+ } ,
188
+ data : {
189
+ isSchemaArchived : true
190
+ }
191
+ } ) ;
192
+
193
+ return schemasResult ;
194
+ } catch ( error ) {
195
+ this . logger . error ( `Error in archive schemas: ${ error } ` ) ;
196
+ throw error ;
197
+ }
198
+ }
199
+
179
200
async getAgentDetailsByOrgId ( orgId : string ) : Promise < AgentDetails > {
180
201
try {
181
202
const schemasResult = await this . prisma . org_agents . findFirst ( {
@@ -275,6 +296,7 @@ export class SchemaRepository {
275
296
schemaResult = await this . prisma . schema . findMany ( {
276
297
where : {
277
298
ledgerId,
299
+ isSchemaArchived : false ,
278
300
type : schemaType ,
279
301
OR : [
280
302
{ name : { contains : searchByText , mode : 'insensitive' } } ,
@@ -289,6 +311,7 @@ export class SchemaRepository {
289
311
version : true ,
290
312
attributes : true ,
291
313
schemaLedgerId : true ,
314
+ isSchemaArchived : true ,
292
315
createdBy : true ,
293
316
publisherDid : true ,
294
317
orgId : true , // This field can be null
@@ -307,6 +330,7 @@ export class SchemaRepository {
307
330
schemaResult = await this . prisma . schema . findMany ( {
308
331
where : {
309
332
ledgerId,
333
+ isSchemaArchived : false ,
310
334
type : schemaType
311
335
} ,
312
336
select : {
@@ -315,6 +339,7 @@ export class SchemaRepository {
315
339
version : true ,
316
340
attributes : true ,
317
341
schemaLedgerId : true ,
342
+ isSchemaArchived : true ,
318
343
createdBy : true ,
319
344
publisherDid : true ,
320
345
orgId : true , // This field can be null
0 commit comments