1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-11-10 23:53:31 -05:00
shimapan/app/public/services/InviteSvc.js
2018-01-14 09:52:00 -05:00

58 lines
1.8 KiB
JavaScript

var angular = require('angular');
angular.module('InviteSvc', []).service('InviteService', ['$http', function ($http) {
this.getInvite = function (code, cb) {
$http({
method: 'GET',
url: '/api/invites/get',
params: {code: code}
}).then(function (res) {
cb(res.data);
});
};
this.getAllInvites = function (cb) {
$http({
method: 'GET',
url: '/api/invites/get'
}).then(function (res) {
cb(res.data);
});
};
this.deleteInvite = function (invite, cb) {
$http({
method: 'POST',
url: '/api/invites/delete',
headers: {'Content-Type': 'application/x-www-form-urlencode'},
transformRequest: function (obj) {
var str = [];
for (var p in obj)
if (obj.hasOwnProperty(p))
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
data: {code: invite.code}
}).then(function (res) {
cb(res.data);
});
};
this.createInvite = function (invite, cb) {
$http({
method: 'POST',
url: '/api/invites/create',
headers: {'Content-Type': 'application/x-www-form-urlencode'},
transformRequest: function (obj) {
var str = [];
for (var p in obj)
if (obj.hasOwnProperty(p))
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
data: invite
}).then(function(res) {
cb(res.data);
});
};
}]);