mail/src/js/service/invitation.js

57 lines
1.7 KiB
JavaScript
Raw Normal View History

2014-10-02 16:05:44 -04:00
'use strict';
var ngModule = angular.module('woServices');
ngModule.service('invitation', Invitation);
module.exports = Invitation;
2014-10-02 16:05:44 -04:00
/**
* The Invitation is a high level Data Access Object that access the invitation service REST endpoint.
2014-10-02 16:05:44 -04:00
* @param {Object} restDao The REST Data Access Object abstraction
*/
function Invitation(invitationRestDao, appConfig) {
this._restDao = invitationRestDao;
this._appConfig = appConfig;
}
2014-10-02 16:05:44 -04:00
/**
* Create the invitation mail object
* @param {String} options.sender The sender's email address
* @param {String} options.recipient The recipient's email address
* @return {Object} The mail object
*/
Invitation.prototype.createMail = function(options) {
var str = this._appConfig.string;
return {
from: [{
address: options.sender
}],
to: [{
address: options.recipient
}],
cc: [],
bcc: [],
subject: str.invitationSubject,
body: str.invitationMessage
};
};
2014-10-02 16:05:44 -04:00
/**
* Notes an invite for the recipient by the sender in the invitation web service
* @param {String} options.recipient User ID of the recipient
* @param {String} options.sender User ID of the sender
2014-12-10 11:20:55 -05:00
* @return {Promise}
2014-10-02 16:05:44 -04:00
*/
2014-12-10 11:20:55 -05:00
Invitation.prototype.invite = function(options) {
var self = this;
2014-12-11 12:12:37 -05:00
return new Promise(function(resolve) {
2014-12-10 11:20:55 -05:00
if (typeof options !== 'object' || typeof options.recipient !== 'string' || typeof options.sender !== 'string') {
throw new Error('erroneous usage of api: incorrect parameters!');
2013-11-20 06:17:21 -05:00
}
2014-12-10 11:20:55 -05:00
resolve();
2013-11-20 06:17:21 -05:00
2014-12-10 11:20:55 -05:00
}).then(function() {
var uri = '/invitation/recipient/' + options.recipient + '/sender/' + options.sender;
return self._restDao.put({}, uri);
});
};