From f54c3236abe4904c7a749420c66f47965f0902fd Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Fri, 29 Aug 2014 12:41:25 -0700 Subject: [PATCH] Refactored Achievement's getExpFunction to use the new defaults system, now on the server side. --- server/achievements/Achievement.coffee | 8 ++++---- server_setup.coffee | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/server/achievements/Achievement.coffee b/server/achievements/Achievement.coffee index 4b0f38bc7..649bc4527 100644 --- a/server/achievements/Achievement.coffee +++ b/server/achievements/Achievement.coffee @@ -4,6 +4,7 @@ log = require 'winston' utils = require '../../app/lib/utils' plugins = require('../plugins/plugins') AchievablePlugin = require '../plugins/achievements' +TreemaUtils = require '../../bower_components/treema/treema-utils.js' # `pre` and `post` are not called for update operations executed directly on the database, # including `Model.update`,`.findByIdAndUpdate`,`.findOneAndUpdate`, `.findOneAndRemove`,and `.findByIdAndRemove`.order @@ -25,10 +26,9 @@ AchievementSchema.methods.stringifyQuery = -> @set('query', JSON.stringify(@get('query'))) if typeof @get('query') != 'string' AchievementSchema.methods.getExpFunction = -> - # TODO DEFAULTS - kind = @get('function')?.kind or jsonschema.properties.function.default.kind - parameters = @get('function')?.parameters or jsonschema.properties.function.default.parameters - return utils.functionCreators[kind](parameters) if kind of utils.functionCreators + func = @get('function') ? {} + TreemaUtils.populateDefaults(func, jsonschema.properties.function) + return utils.functionCreators[func.kind](func.parameters) if func.kind of utils.functionCreators AchievementSchema.methods.isRecalculable = -> @get('recalculable') isnt false diff --git a/server_setup.coffee b/server_setup.coffee index 10a586713..8a76573ef 100644 --- a/server_setup.coffee +++ b/server_setup.coffee @@ -13,6 +13,7 @@ logging = require './server/commons/logging' config = require './server_config' auth = require './server/routes/auth' UserHandler = require './server/users/user_handler' +global.tv4 = require 'tv4' # required for TreemaUtils to work productionLogging = (tokens, req, res) -> status = res.statusCode