41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
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'
|
|
}
|
|
});
|
|
|
|
Self.send = async(recipient, data, ctx) => {
|
|
let query = `SELECT vn.messageSendWithUser(?, ?, ?) AS sent`;
|
|
let [result] = await Self.rawSql(query, [ctx.req.accessToken.userId, recipient, data.message]);
|
|
|
|
return result;
|
|
};
|
|
};
|