const { Controller, Action, model } = require ('@onehilltech/blueprint');
const { pick } = require ('lodash');
module.exports = Controller.extend ({
messages: null, // collection of messsages
Message: model ('message'), // load the message model
this._super.call (this, ...arguments);
_nextId: 0, // id of the next message
let id = this._nextId ++;
let data = Object.assign ({id}, pick (req.body.message, ['from','to','date','subject','content']));
let msg = this.controller.Message.create (data);
this.controller.messages.push (msg);
res.status (200).json ({message: msg});