mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-03 04:29:40 +00:00
refactor(challenges): wrap group.challenges as $resources, so they're
convenience functions $join/$leave/etc can be called directly
This commit is contained in:
parent
17ab1d660f
commit
35e8097b0c
1 changed files with 17 additions and 4 deletions
|
|
@ -4,13 +4,26 @@
|
||||||
* Services that persists and retrieves user from localStorage.
|
* Services that persists and retrieves user from localStorage.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
angular.module('groupServices', ['ngResource']).
|
angular.module('groupServices', ['ngResource', 'challengeServices']).
|
||||||
factory('Groups', ['ApiUrlService', '$resource', '$q', '$http', 'User',
|
factory('Groups', ['ApiUrlService', '$resource', '$q', '$http', 'User', 'Challenges',
|
||||||
function(ApiUrlService, $resource, $q, $http, User) {
|
function(ApiUrlService, $resource, $q, $http, User, Challenges) {
|
||||||
|
|
||||||
var Group = $resource(ApiUrlService.get() + '/api/v2/groups/:gid',
|
var Group = $resource(ApiUrlService.get() + '/api/v2/groups/:gid',
|
||||||
{gid:'@_id', messageId: '@_messageId'},
|
{gid:'@_id', messageId: '@_messageId'},
|
||||||
{
|
{
|
||||||
//query: {method: "GET", isArray:false},
|
get: {
|
||||||
|
method: "GET",
|
||||||
|
isArray:false,
|
||||||
|
// Wrap challenges as ngResource so they have functions like $leave or $join
|
||||||
|
transformResponse: function(data, headers) {
|
||||||
|
data = angular.fromJson(data);
|
||||||
|
_.each(data && data.challenges, function(c) {
|
||||||
|
angular.extend(c, Challenges.Challenge.prototype);
|
||||||
|
});
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
postChat: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/chat'},
|
postChat: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/chat'},
|
||||||
deleteChatMessage: {method: "DELETE", url: ApiUrlService.get() + '/api/v2/groups/:gid/chat/:messageId'},
|
deleteChatMessage: {method: "DELETE", url: ApiUrlService.get() + '/api/v2/groups/:gid/chat/:messageId'},
|
||||||
flagChatMessage: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/chat/:messageId/flag'},
|
flagChatMessage: {method: "POST", url: ApiUrlService.get() + '/api/v2/groups/:gid/chat/:messageId/flag'},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue