@@ -10,11 +10,6 @@ import dbSchema from '../../change_request_schema.json'
1010import { doc } from "@terminusdb/terminusdb-client/dist/typescript/lib/woql"
1111//import {v4 as uuidv4} from 'uuid';
1212const { 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"
1813class ChangeRequestDB {
1914 client : WOQLClient ;
2015 request : Request
@@ -24,8 +19,8 @@ class ChangeRequestDB {
2419 dbName : string | undefined
2520 changeRequestDbName : string | undefined
2621 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 }
2924 errorMessage :any = { 'api:UnknownDatabase' :true , 'api:NoUniqueIdForOrganizationName' :true }
3025
3126 constructor ( req : Request ) {
@@ -221,22 +216,21 @@ class ChangeRequestDB {
221216
222217 // check if there is an old CR db
223218 async updateDocumentFixSchema ( changeRequestDoc :typeDef . ChangeReqDoc | typeDef . IndexedCommit , message = 'add new doc' ) {
224- let docResult
225219 try {
226220 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 )
228222 } catch ( err :any ) {
229223 const errData = err . data || { }
230224 // I have the old schema
231225 if ( errData [ 'api:message' ] === 'Schema check failure' ) {
232226 // update old schema
233227 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 )
235229 } else {
236230 throw err
237231 }
238232 }
239- return docResult
233+ return changeRequestDoc
240234 }
241235
242236 async getCROriginCommitId ( userDBClient :WOQLClient , originBranch :string , trackingBranch :string ) {
@@ -379,10 +373,11 @@ class ChangeRequestDB {
379373 async checkStatus ( taskId :string ) {
380374 try {
381375 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 }
384379 }
385- return { status : 'Complete ' }
380+ return { status : 'Progress ' }
386381 } catch ( err :any ) {
387382 const message = err . response && err . response . data ? err . response . data : err . message
388383 return { status : 'Error' , error_message : message }
@@ -402,11 +397,12 @@ class ChangeRequestDB {
402397 await this . client . updateDocument ( doc )
403398 break
404399 case 'Complete' :
400+ doc . indexed_documents = statusObj . indexed_documents
405401 // eslint-disable-next-line no-case-declarations
406402 const result = await this . assignCommit ( domain , commit , doc . searchable_branch_commit_id , apiKey )
407403 doc . indexing_status = result . status
408404 if ( result . error_message ) doc . error_message = result . error_message
409- await this . client . updateDocument ( doc )
405+ await this . updateDocumentFixSchema ( doc )
410406 break
411407 case 'Error' :
412408 doc . indexing_status = 'Error'
@@ -459,6 +455,7 @@ class ChangeRequestDB {
459455 WOQL . triple ( 'v:index' , '@schema:indexed_at' , 'v:time' ) ,
460456 WOQL . opt ( ) . triple ( 'v:index' , '@schema:task_id' , 'v:task_id' ) ,
461457 WOQL . opt ( ) . triple ( 'v:index' , '@schema:error_message' , 'v:error_message' ) ,
458+ WOQL . opt ( ) . triple ( 'v:index' , '@schema:indexed_documents' , 'v:indexed_documents' ) ,
462459 WOQL . triple ( 'v:changeR' , '@schema:indexing_info' , 'v:index' ) ,
463460 WOQL . triple ( 'v:changeR' , '@schema:name' , 'v:name' ) ,
464461 WOQL . triple ( 'v:changeR' , '@schema:tracking_branch' , 'v:tracking_branch' )
0 commit comments