@@ -10,11 +10,6 @@ import dbSchema from '../../change_request_schema.json'
10
10
import { doc } from "@terminusdb/terminusdb-client/dist/typescript/lib/woql"
11
11
//import {v4 as uuidv4} from 'uuid';
12
12
const { v4 : uuidv4 } = require ( 'uuid' ) ;
13
-
14
- //const endpoint :string = process.env.SERVER_ENDPOINT || "http://127.0.0.1:6363"
15
- //const key = process.env.USER_KEY || "root"
16
- //const CROrg = process.env.CR_TEAM_NAME || "terminusCR"
17
- //const user = process.env.USER_NAME || "admin"
18
13
class ChangeRequestDB {
19
14
client : WOQLClient ;
20
15
request : Request
@@ -24,8 +19,8 @@ class ChangeRequestDB {
24
19
dbName : string | undefined
25
20
changeRequestDbName : string | undefined
26
21
logger : typeDef . Logger
27
- endStatus :any = { Assigned : true , Error : true }
28
- availableStatus :any = { Assigned : true , Error : true , Progress : true }
22
+ endStatus :any = { Assigned : true , Error : true , Close : true }
23
+ availableStatus :any = { Assigned : true , Error : true , Progress : true , Close : true }
29
24
errorMessage :any = { 'api:UnknownDatabase' :true , 'api:NoUniqueIdForOrganizationName' :true }
30
25
31
26
constructor ( req : Request ) {
@@ -221,22 +216,21 @@ class ChangeRequestDB {
221
216
222
217
// check if there is an old CR db
223
218
async updateDocumentFixSchema ( changeRequestDoc :typeDef . ChangeReqDoc | typeDef . IndexedCommit , message = 'add new doc' ) {
224
- let docResult
225
219
try {
226
220
const putDocParams : DocParamsPut = { create : true }
227
- docResult = await this . client . updateDocument ( changeRequestDoc , { create : true } , undefined , message )
221
+ await this . client . updateDocument ( changeRequestDoc , { create : true } , undefined , message )
228
222
} catch ( err :any ) {
229
223
const errData = err . data || { }
230
224
// I have the old schema
231
225
if ( errData [ 'api:message' ] === 'Schema check failure' ) {
232
226
// update old schema
233
227
await this . client . addDocument ( dbSchema , { graph_type : 'schema' , full_replace : true } )
234
- docResult = await this . client . updateDocument ( changeRequestDoc , { create : true } , undefined , message )
228
+ await this . client . updateDocument ( changeRequestDoc , { create : true } , undefined , message )
235
229
} else {
236
230
throw err
237
231
}
238
232
}
239
- return docResult
233
+ return changeRequestDoc
240
234
}
241
235
242
236
async getCROriginCommitId ( userDBClient :WOQLClient , originBranch :string , trackingBranch :string ) {
@@ -379,10 +373,11 @@ class ChangeRequestDB {
379
373
async checkStatus ( taskId :string ) {
380
374
try {
381
375
const progress = await IndexClient . checkStatus ( this . logger , taskId )
382
- if ( progress . data < 1 ) {
383
- return { status : 'Progress' }
376
+ if ( progress . status === "Complete" ) {
377
+ const indexedDocuments = progress . indexed_documents || 0
378
+ return { status : 'Complete' , indexed_documents :indexedDocuments }
384
379
}
385
- return { status : 'Complete ' }
380
+ return { status : 'Progress ' }
386
381
} catch ( err :any ) {
387
382
const message = err . response && err . response . data ? err . response . data : err . message
388
383
return { status : 'Error' , error_message : message }
@@ -402,11 +397,12 @@ class ChangeRequestDB {
402
397
await this . client . updateDocument ( doc )
403
398
break
404
399
case 'Complete' :
400
+ doc . indexed_documents = statusObj . indexed_documents
405
401
// eslint-disable-next-line no-case-declarations
406
402
const result = await this . assignCommit ( domain , commit , doc . searchable_branch_commit_id , apiKey )
407
403
doc . indexing_status = result . status
408
404
if ( result . error_message ) doc . error_message = result . error_message
409
- await this . client . updateDocument ( doc )
405
+ await this . updateDocumentFixSchema ( doc )
410
406
break
411
407
case 'Error' :
412
408
doc . indexing_status = 'Error'
@@ -459,6 +455,7 @@ class ChangeRequestDB {
459
455
WOQL . triple ( 'v:index' , '@schema:indexed_at' , 'v:time' ) ,
460
456
WOQL . opt ( ) . triple ( 'v:index' , '@schema:task_id' , 'v:task_id' ) ,
461
457
WOQL . opt ( ) . triple ( 'v:index' , '@schema:error_message' , 'v:error_message' ) ,
458
+ WOQL . opt ( ) . triple ( 'v:index' , '@schema:indexed_documents' , 'v:indexed_documents' ) ,
462
459
WOQL . triple ( 'v:changeR' , '@schema:indexing_info' , 'v:index' ) ,
463
460
WOQL . triple ( 'v:changeR' , '@schema:name' , 'v:name' ) ,
464
461
WOQL . triple ( 'v:changeR' , '@schema:tracking_branch' , 'v:tracking_branch' )
0 commit comments