Problem persisting model programmatically after a Container upload, using Container.afterRemote

7 views
Skip to first unread message

Groo

unread,
Jul 23, 2016, 8:22:38 AM7/23/16
to loopb...@googlegroups.com
I've been stuck for a while trying to make this work, I can't see the issue and no errors but Model(Meal) does not get persisted to MongoDB. Normal calls to meal create from rest api do work properly, any ideas? 

var app = require('../../server/server');

module.exports = function(Container, app) {
Container.afterRemote('upload', function(ctx, unused, next){
console.log(ctx.result.result.fields.meal[0]);
console.log('after remote');

var mealFromMobile = ctx.result.result.fields.meal[0];
console.log('got meal from mobile: ' + mealFromMobile);
var picName = mealFromMobile.mealPicture.substr(mealFromMobile.mealPicture.lastIndexOf('/') + 1);
console.log(picName);

var Meal = app.models.Meal;
var meal = {
"mealDate": mealFromMobile.mealDate,
"mealPicture": picName
};
console.log("meal? : " + meal);
Meal.create(meal, function(error, result) {
if(err){
console.log(err);
next();
}
console.log('persisted');
console.log(result);
next();
});
console.log('exiting afterRemote');
});
};

 Thanks in advance
Reply all
Reply to author
Forward
0 new messages