Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import automation logic fix #5

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9317fe4
update importFromCsv and createWithRow functions to accept additional…
Sep 26, 2018
515e0da
initial code for testing/troubleshooting - WIP
Sep 27, 2018
28f9df6
update dist files - WIP
Sep 27, 2018
0a9ab7c
fix mistake in reference to request body - WIP
Sep 28, 2018
bec6553
update dist files
Sep 28, 2018
5f98839
add explicit return in createWithRow function and update dist file - …
Oct 1, 2018
1e4fb89
add console.log for troubleshooting
Oct 1, 2018
f44e4da
futher console.logs for troubleshooting
Oct 1, 2018
ac0b62e
update query parameter - WIP
Oct 1, 2018
db7ce83
fix mongoose query syntax - WIP
Oct 1, 2018
f6286c2
implement string interpolation in mongoose query - WIP
Oct 1, 2018
58fa3b6
troubleshooting
Oct 1, 2018
e278f00
more troubleshooting
Oct 1, 2018
5de5278
update mongoose query to use findOne instead of find - troubleshootin…
Oct 1, 2018
8ec3aab
update mongoose query methods - still WIP
Oct 1, 2018
c8ed9d5
code cleanup - still possibly WIP but mostly complete"
Oct 3, 2018
813e309
add upsert and setDefaultsOnInsert options to findOneAndUpdate calls …
Nov 9, 2018
6648940
handle incoming incompatible User.isInitialLogin values for custom CS…
Nov 9, 2018
7309252
update dist files
Nov 9, 2018
1459606
remove unneeded logic check; rebuild dist files
Nov 9, 2018
49cd4b4
remove console.log and rearrange order of checks in checkForFalseyVal…
Nov 9, 2018
a93ce44
add explicit returns for error handling
Nov 9, 2018
9c34229
remove unneeded console.log
Nov 9, 2018
3cd01cd
update date createWithRow logic to depend on pre/post 'save' hooks
Nov 21, 2018
889ec51
replace for...of loop with for...in loop to interate over plain objec…
Nov 21, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add upsert and setDefaultsOnInsert options to findOneAndUpdate calls …
…- WIP
  • Loading branch information
Ryan Dempsey committed Nov 9, 2018
commit 813e309d4f653a5ad2fd90ff3ea4a4007839ddea
9 changes: 7 additions & 2 deletions src/admin/admin.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ export function importFromCsv(req, res, next) {
function createWithRow(req, object, row, successCallback, errorCallback, importOpt) {
// if the importOpt (dbOption in importFromCsv function) is passed,
// we need to search the database using that value
let options = {
upsert: true,
setDefaultsOnInsert: true,
};

if (importOpt) {
// here we use the importOpt/dbOption to find and update objects in the database
let conditions = {
Expand All @@ -464,7 +469,7 @@ function createWithRow(req, object, row, successCallback, errorCallback, importO
[importOpt]: { $eq: found[importOpt] },
};

req.class.findOneAndUpdate(foundConditions, object).then(function (result) {
req.class.findOneAndUpdate(foundConditions, object, options).then(function (result) {
return successCallback(result, row);
}).catch(function(error) {
errorCallback(error, row);
Expand All @@ -483,7 +488,7 @@ function createWithRow(req, object, row, successCallback, errorCallback, importO
// normal admin portal CSV import functionality
req.class.findById(object._id, (err, found) => {
if (found) {
req.class.findByIdAndUpdate(object._id, object)
req.class.findByIdAndUpdate(object._id, object, options)
.then(function(result) {
return successCallback(result, row);
}).catch(function(error) {
Expand Down