Skip to content
This repository has been archived by the owner on Mar 8, 2018. It is now read-only.

Commit

Permalink
make sure images set over the API are displayed
Browse files Browse the repository at this point in the history
At the moment the popit front end doesn't follow the same data model as
popolo for images so when you include and image URL over the API they
aren't displayed by the website. This does the required processing on
the uploads to fix that.

Fixes #432
  • Loading branch information
struan committed Sep 15, 2014
1 parent b223d28 commit e95568b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,13 @@ function popitApiApp(options) {
});

app.post('/:collection', validateBody, function (req, res, next) {
req.collection.create(req.body, function (err, doc) {
var body = req.body;
// if there's an image and no body.images then add one as the popit front end uses
// that at the moment
if ( body.image && !body.images ) {
body.images = [ { url: body.image } ];
}
req.collection.create(body, function (err, doc) {
if (err) {
return next(err);
}
Expand Down Expand Up @@ -275,6 +281,7 @@ function popitApiApp(options) {
doc = new req.collection();
}
delete body.__v;

/* this is to make sure that the _id property is the same for things added via
* the api and the front end. If not then elasticsearch doesn't index it as it
* confuses it's auto mapping.
Expand All @@ -289,6 +296,12 @@ function popitApiApp(options) {
});
body.images = images;
}

// if there's an image and no body.images then add one as the popit front end uses
// that at the moment
if ( body.image && !body.images ) {
body.images = [ { url: body.image } ];
}
doc.set(body);
doc.save(function(err) {
if (err) {
Expand Down

0 comments on commit e95568b

Please sign in to comment.