rewards: code organization, getting ready to code saving/loading of active rewards

v1.18.x
psychobunny 10 years ago
parent 2cc6f0c507
commit 46e0fad2d8

@ -1,24 +1,10 @@
"use strict"; "use strict";
var rewards = {}; var rewards = {},
async = require('async'),
plugins = require('../plugins');
var defaults = {
rewards.get = function(callback) {
callback(false, {
conditions: [
{
"name": "Reputation",
"condition": "reputation"
},
{
"name": "Post Count",
"condition": "postcount"
},
{
"name": "Last Logged in Time",
"condition": "lastLoggedIn"
}
],
conditionals: [ conditionals: [
{ {
"name": ">", "name": ">",
@ -40,31 +26,34 @@ rewards.get = function(callback) {
"name": "string:", "name": "string:",
"conditional": "string" "conditional": "string"
} }
], ]
active: [ };
rewards.get = function(callback) {
async.parallel({
active: getActiveRewards,
conditions: function(next) {
plugins.fireHook('filter:rewards.conditions', [
{ {
"rewardID": 1, "name": "Reputation",
"condition": "postcount", "condition": "reputation"
"conditional": "greaterthan",
"rewards": {
"title": "Here is a title",
"message": "here is a message"
},
"value": 100,
"disabled": false
}, },
{ {
"rewardID": 0, "name": "Post Count",
"condition": "lastLoggedIn", "condition": "postcount"
"conditional": "lesserthan",
"rewards": {
"groupname": "group2"
}, },
"value": 10, {
"disabled": true "name": "Last Logged in Time",
"condition": "lastLoggedIn"
} }
], ], next);
rewards: [ },
conditionals: function(next) {
plugins.fireHook('filter:rewards.conditionals', defaults.conditionals, next);
},
rewards: function(next) {
plugins.fireHook('filter:rewards.rewards', [
{ {
"rewardID": 0, "rewardID": 0,
"name": "Add to Group", "name": "Add to Group",
@ -106,16 +95,39 @@ rewards.get = function(callback) {
} }
] ]
} }
] ], next);
}); }
}, callback);
}; };
function getConditions() { function getConditions() {
} }
function getRewards() { function getActiveRewards(callback) {
callback(false, [
{
"rewardID": 1,
"condition": "postcount",
"conditional": "greaterthan",
"rewards": {
"title": "Here is a title",
"message": "here is a message"
},
"value": 100,
"disabled": false
},
{
"rewardID": 0,
"condition": "lastLoggedIn",
"conditional": "lesserthan",
"rewards": {
"groupname": "group2"
},
"value": 10,
"disabled": true
}
]);
} }
module.exports = rewards; module.exports = rewards;
Loading…
Cancel
Save