Skip to content

Commit

Permalink
some here and there
Browse files Browse the repository at this point in the history
  • Loading branch information
pallavi2209 committed Oct 26, 2016
1 parent 58e20dc commit 0cecf2b
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions db/model/sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ module.exports = function sample(seq, dataTypes) {
*/
upsertByName(toUpsert, isBulk) {
if (config.optimizeUpsert) {
let sampleExists = true;
// let sampleExists = true;
return new seq.Promise((resolve, reject) => {
// get sample by name
Sample.findOne({
Expand All @@ -186,28 +186,23 @@ module.exports = function sample(seq, dataTypes) {
},
})
.then((o) => {
if (o) {
// Else, if sample exists, update the sample.
// set value changed to true, during updates to avoid timeouts
// Adding this to the before update hook does
// give the needed effect; so adding it here!!!.
o.changed('value', true);
resolve(o.update(toUpsert));
}

// If sample does not exist, set sampleExists to false, which is
// used after this promise returns. Get corresponding subject and
// aspect to check if the sample name is valid.
if (o === null) {
sampleExists = false;
return u.getSubjectAndAspectBySampleName(seq, toUpsert.name,
isBulk);
}

// Else, if sample exists, update the sample.
// set value changed to true, during updates to avoid timeouts
// Adding this to the before update hook does
// give the needed effect; so adding it here!!!.
o.changed('value', true);
return o.update(toUpsert);
// sampleExists = false;
return u.getSubjectAndAspectBySampleName(seq, toUpsert.name,
isBulk);
})
.then((returnedObj) => {
// If sample existed, return the updated object.
if (sampleExists) {
return returnedObj;
}

// If sample does not exist, update subject and aspect id in
// sample object to be created. Create sample.
toUpsert.subjectId = returnedObj.subject.id;
Expand Down

0 comments on commit 0cecf2b

Please sign in to comment.