summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-06-14 19:24:24 -0400
committerJules Laplace <jules@okfoc.us>2016-06-14 19:24:24 -0400
commit796f144dacbee71f1816c10cb75c58b13a3718a1 (patch)
tree57b9c1fec3806923d311204f9a2790030a5793b6
parentd4a98f11e4557f21385a91266aeb198106edb62e (diff)
check if we have a duplicate layout on create
-rw-r--r--server/lib/api/layouts.js27
1 files changed, 18 insertions, 9 deletions
diff --git a/server/lib/api/layouts.js b/server/lib/api/layouts.js
index c04f926..2c68f71 100644
--- a/server/lib/api/layouts.js
+++ b/server/lib/api/layouts.js
@@ -50,15 +50,24 @@ var layouts = {
data.rooms = JSON.parse(data.rooms)
data.startPosition = JSON.parse(data.startPosition)
- upload.put("layouts", req.files.thumbnail, {
- unacceptable: function(err){
- res.json({ error: { errors: { thumbnail: { message: "Problem saving thumbnail: " + err } } } })
- },
- success: function(url){
- data.photo = url
- done()
- }
- })
+ Layout.findOne({ slug: data.slug }, function(err, doc){
+ if (! err || doc) {
+ data.slug = data.slug + "-" + Date.now()
+ }
+ do_upload()
+ })
+
+ function do_upload () {
+ upload.put("layouts", req.files.thumbnail, {
+ unacceptable: function(err){
+ res.json({ error: { errors: { thumbnail: { message: "Problem saving thumbnail: " + err } } } })
+ },
+ success: function(url){
+ data.photo = url
+ done()
+ }
+ })
+ }
function done() {
new Layout(data).save(function(err, doc){