Commit 6e8ca3c5 authored by Anuj Gupta's avatar Anuj Gupta
Browse files

Merge branch 'ibm-open-issues-ctag-final' into 'master'

fix: IBM open issues ctag final

See merge request !136
parents cc64b65b 3d6b11f9
Pipeline #50570 passed with stages
in 12 minutes and 2 seconds
...@@ -18,14 +18,13 @@ export class DatastoreDAO extends AbstractJournal { ...@@ -18,14 +18,13 @@ export class DatastoreDAO extends AbstractJournal {
public constructor(tenant: TenantModel) { public constructor(tenant: TenantModel) {
super(); super();
logger.info('In datastore.constructor.'); logger.info('In datastore.constructor.');
this.dataPartition = tenant.esd.indexOf('.') !== -1 ? tenant.esd.split('.')[0] : tenant.esd; this.dataPartition = tenant.gcpid;
} }
public async initDb(dataPartition: string) public async initDb(dataPartition: string)
{ {
logger.info('In datastore.initDb.'); logger.info('In datastore.initDb.');
const dbUrl = IbmConfig.DOC_DB_URL; const dbUrl = IbmConfig.DOC_DB_URL;
logger.debug(dbUrl);
const cloudantOb = cloudant(dbUrl); const cloudantOb = cloudant(dbUrl);
logger.info('DB initialized. cloudantOb-'); logger.info('DB initialized. cloudantOb-');
...@@ -84,11 +83,10 @@ export class DatastoreDAO extends AbstractJournal { ...@@ -84,11 +83,10 @@ export class DatastoreDAO extends AbstractJournal {
await this.initDb(this.dataPartition); await this.initDb(this.dataPartition);
logger.info('Fetching document.'); logger.info('Fetching document.');
/// changed from entity.name to entity.key.name try{
await this.docDb.get(entity.key.name, { revs_info: true }, (err, existingDoc) => { const getResponse = await this.docDb.get(entity.key.name, { revs_info: true });
if (!err) {/// update record
logger.info('Document exists in db.'); logger.info('Document exists in db.');
const existingDoc = getResponse;
const docTemp = JSON.parse(JSON.stringify(existingDoc)); const docTemp = JSON.parse(JSON.stringify(existingDoc));
/// have to add if condition. before that check the dataset object structure /// have to add if condition. before that check the dataset object structure
docTemp.ltag = entity.ltag; docTemp.ltag = entity.ltag;
...@@ -97,10 +95,10 @@ export class DatastoreDAO extends AbstractJournal { ...@@ -97,10 +95,10 @@ export class DatastoreDAO extends AbstractJournal {
Object.assign(docTemp, entity.data); Object.assign(docTemp, entity.data);
logger.debug(docTemp); logger.debug(docTemp);
this.docDb.insert(docTemp, entity.key.name); await this.docDb.insert(docTemp, entity.key.name);
logger.info('Document updated.'); logger.info('Document updated.');
} } catch(err){
else/// insert record if(err.statusCode === 404)
{ {
logger.info('Document does not exist. This will be a new document'); logger.info('Document does not exist. This will be a new document');
const customizedOb = {}; const customizedOb = {};
...@@ -113,10 +111,10 @@ export class DatastoreDAO extends AbstractJournal { ...@@ -113,10 +111,10 @@ export class DatastoreDAO extends AbstractJournal {
customizedOb[element] = entity.data[element]; customizedOb[element] = entity.data[element];
}; };
logger.debug(customizedOb); logger.debug(customizedOb);
this.docDb.insert(customizedOb, entity.key.name); await this.docDb.insert(customizedOb, entity.key.name);
logger.info('Document inserted.'); logger.info('Document inserted.');
} }
}); }
logger.info('Returning from datastore.save.'); logger.info('Returning from datastore.save.');
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment