Created
June 21, 2017 15:46
-
-
Save mmetting/41eaefad456a1a746842938befc6c831 to your computer and use it in GitHub Desktop.
Only add unique Name values to DB (list)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $fh = require('fh-mbaas-api'); | |
var readOptions = { | |
"act": "list", | |
"type": "myFirstEntity", | |
"eq": { | |
"name": world | |
} | |
}; | |
$fh.db(readOptions, function (err, data) { | |
if (err) { | |
console.error("Error " + err); | |
res.status(500).json({ msg: err }) | |
} else { | |
console.log(JSON.stringify(data)); | |
if (data.count == 0) { | |
var timestamp = new Date().getTime(); | |
var options = { | |
"act": "create", | |
"type": "myFirstEntity", | |
"fields": { | |
"name": world, | |
"timestamp": timestamp | |
} | |
}; | |
$fh.db(options, function (err, data) { | |
if (err) { | |
console.error("Error " + err); | |
res.status(500).json({ msg: err }) | |
} else { | |
console.log(JSON.stringify(data)); | |
res.status(200).json({ msg: data }) | |
} | |
}); | |
} else { | |
console.log("Entry already exists"); | |
res.status(200).json({ msg: "Entry already exists" }); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment