2018-04-20 13:16:03 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('send', {
|
|
|
|
description: 'Send message to user',
|
|
|
|
accessType: 'WRITE',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'recipient',
|
|
|
|
type: 'string',
|
|
|
|
required: true,
|
|
|
|
description: 'The user/alias name',
|
|
|
|
http: {source: 'path'}
|
|
|
|
}, {
|
|
|
|
arg: 'data',
|
|
|
|
type: 'object',
|
|
|
|
required: true,
|
|
|
|
description: 'Message data',
|
|
|
|
http: {source: 'body'}
|
|
|
|
}, {
|
|
|
|
arg: 'context',
|
|
|
|
type: 'object',
|
|
|
|
http: function(ctx) {
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: 'boolean',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/:recipient/send`,
|
|
|
|
verb: 'post'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-05-31 12:48:10 +00:00
|
|
|
Self.send = async(recipient, data, ctx) => {
|
2018-04-20 13:16:03 +00:00
|
|
|
let query = `SELECT vn.messageSendWithUser(?, ?, ?) AS sent`;
|
|
|
|
let [result] = await Self.rawSql(query, [ctx.req.accessToken.userId, recipient, data.message]);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
};
|