diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-08-18 21:25:28 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-08-18 21:25:28 -0400 |
| commit | d9ecfddd7ba63d3cf94b29053476d1d11118d38e (patch) | |
| tree | 55e759395068e4e21125e140d2a23f1833801ffb /server/lib | |
| parent | 62a8127787c1ed2f0ae420722be9327e421633bd (diff) | |
saving blueprints
Diffstat (limited to 'server/lib')
| -rw-r--r-- | server/lib/api/blueprint.js | 20 | ||||
| -rw-r--r-- | server/lib/schemas/Blueprint.js | 11 |
2 files changed, 30 insertions, 1 deletions
diff --git a/server/lib/api/blueprint.js b/server/lib/api/blueprint.js index 7319055..e581d8f 100644 --- a/server/lib/api/blueprint.js +++ b/server/lib/api/blueprint.js @@ -81,6 +81,26 @@ var blueprint = { }) }) }, + + update: function(req, res){ + var _id = req.body._id + var data = util.cleanQuery(req.body) + if (! _id) { return res.json({ error: 404 }) } + Blueprint.findOne({ _id: _id }, function(err, doc){ + if (! doc) { return res.json({ error: 404 }) } + if (String(doc.user_id) !== String(req.user._id)) { return res.json({ error: 404 }) } + + doc.name = util.sanitize(data.name) + doc.slug = util.slugify(data.name) + doc.shapes = JSON.parse(data.shapes) + doc.startPosition = JSON.parse(data.startPosition) + + doc.save(function(err, rec){ + if (err || ! rec) { return res.json({ error: err }) } + res.json(rec) + }) + }) + }, destroy: function(req, res){ var _id = util.sanitize(req.body._id) diff --git a/server/lib/schemas/Blueprint.js b/server/lib/schemas/Blueprint.js index 78a388f..666f0cf 100644 --- a/server/lib/schemas/Blueprint.js +++ b/server/lib/schemas/Blueprint.js @@ -33,6 +33,15 @@ var BlueprintSchema = new mongoose.Schema({ type: String, default: "" }, + slug: { + type: String, + required: true, + validate: [function (val){ + val = util.sanitize(val || this.displayName || "") + if (! val.length) return false + return true + },"{PATH} name is required"] + }, description: { type: String, default: "" @@ -45,7 +54,7 @@ var BlueprintSchema = new mongoose.Schema({ units: { type: String }, line: { type: String }, - rooms: [mongoose.Schema.Types.Mixed], + shapes: [mongoose.Schema.Types.Mixed], startPosition: mongoose.Schema.Types.Mixed, user_id: { type: mongoose.Schema.ObjectId, index: true }, |
