mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
fix: Use module.exports instead of export default
This commit is contained in:
@@ -166,7 +166,7 @@ function _changeTaskValue (user, task, direction, times, cron) {
|
|||||||
return addToDelta;
|
return addToDelta;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function scoreTask (options = {}, req = {}) {
|
module.exports = function scoreTask (options = {}, req = {}) {
|
||||||
let {user, task, direction, times = 1, cron = false} = options;
|
let {user, task, direction, times = 1, cron = false} = options;
|
||||||
let delta = 0;
|
let delta = 0;
|
||||||
let stats = {
|
let stats = {
|
||||||
@@ -247,4 +247,4 @@ export default function scoreTask (options = {}, req = {}) {
|
|||||||
|
|
||||||
user.fns.updateStats(stats, req);
|
user.fns.updateStats(stats, req);
|
||||||
return delta;
|
return delta;
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -342,4 +342,4 @@ api.logout = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default api;
|
module.exports = api;
|
||||||
|
|||||||
@@ -565,4 +565,4 @@ api.selectChallengeWinner = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default api;
|
module.exports = api;
|
||||||
|
|||||||
@@ -392,4 +392,4 @@ api.deleteChat = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default api;
|
module.exports = api;
|
||||||
|
|||||||
@@ -226,4 +226,4 @@ api.exportUserAvatarPng = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default api;
|
module.exports = api;
|
||||||
|
|||||||
@@ -51,4 +51,4 @@ api.unsubscribe = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default api;
|
module.exports = api;
|
||||||
|
|||||||
@@ -497,12 +497,12 @@ async function _inviteByUUID (uuid, group, inviter, req, res) {
|
|||||||
if (group.type === 'guild') {
|
if (group.type === 'guild') {
|
||||||
emailVars.push(
|
emailVars.push(
|
||||||
{name: 'GUILD_NAME', content: group.name},
|
{name: 'GUILD_NAME', content: group.name},
|
||||||
{name: 'GUILD_URL', content: '/#/options/groups/guilds/public'},
|
{name: 'GUILD_URL', content: '/#/options/groups/guilds/public'}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
emailVars.push(
|
emailVars.push(
|
||||||
{name: 'PARTY_NAME', content: group.name},
|
{name: 'PARTY_NAME', content: group.name},
|
||||||
{name: 'PARTY_URL', content: '/#/options/groups/party'},
|
{name: 'PARTY_URL', content: '/#/options/groups/party'}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -642,4 +642,4 @@ api.inviteToGroup = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default api;
|
module.exports = api;
|
||||||
|
|||||||
@@ -189,4 +189,4 @@ api.updateHero = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default api;
|
module.exports = api;
|
||||||
|
|||||||
@@ -231,4 +231,4 @@ api.getChallengeMemberProgress = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default api;
|
module.exports = api;
|
||||||
|
|||||||
@@ -36,4 +36,4 @@ api.getModelPaths = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default api;
|
module.exports = api;
|
||||||
|
|||||||
@@ -448,4 +448,4 @@ api.leaveQuest = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default api;
|
module.exports = api;
|
||||||
|
|||||||
@@ -144,4 +144,4 @@ api.deleteTag = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default api;
|
module.exports = api;
|
||||||
|
|||||||
@@ -923,4 +923,4 @@ api.deleteTask = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default api;
|
module.exports = api;
|
||||||
|
|||||||
@@ -156,4 +156,4 @@ api.castSpell = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default api;
|
module.exports = api;
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ let mockAnalyticsService = {
|
|||||||
trackPurchase: () => { },
|
trackPurchase: () => { },
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
module.exports = {
|
||||||
track,
|
track,
|
||||||
trackPurchase,
|
trackPurchase,
|
||||||
mockAnalyticsService,
|
mockAnalyticsService,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import validator from 'validator';
|
|||||||
import objectPath from 'object-path'; // TODO use lodash's unset once v4 is out
|
import objectPath from 'object-path'; // TODO use lodash's unset once v4 is out
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
export default function baseModel (schema, options = {}) {
|
module.exports = function baseModel (schema, options = {}) {
|
||||||
schema.add({
|
schema.add({
|
||||||
_id: {
|
_id: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -67,4 +67,4 @@ export default function baseModel (schema, options = {}) {
|
|||||||
return result;
|
return result;
|
||||||
}, {});
|
}, {});
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import csvStringify from 'csv-stringify';
|
import csvStringify from 'csv-stringify';
|
||||||
import Q from 'q';
|
import Q from 'q';
|
||||||
|
|
||||||
export default function (input) {
|
module.exports = (input) => {
|
||||||
return Q.promise((resolve, reject) => {
|
return Q.promise((resolve, reject) => {
|
||||||
csvStringify(input, (err, output) => {
|
csvStringify(input, (err, output) => {
|
||||||
if (err) return reject(err);
|
if (err) return reject(err);
|
||||||
return resolve(output);
|
return resolve(output);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -21,4 +21,4 @@ if (IS_PROD) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default logger;
|
module.exports = logger;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ if (gcm) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO test
|
// TODO test
|
||||||
export default function sendNotification (user, title, message, timeToLive = 15) {
|
module.exports = function sendNotification (user, title, message, timeToLive = 15) {
|
||||||
// TODO need investigation:
|
// TODO need investigation:
|
||||||
// https://github.com/HabitRPG/habitrpg/issues/5252
|
// https://github.com/HabitRPG/habitrpg/issues/5252
|
||||||
|
|
||||||
@@ -54,4 +54,4 @@ export default function sendNotification (user, title, message, timeToLive = 15)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { join, resolve } from 'path';
|
|||||||
|
|
||||||
const PATH_TO_CONFIG = join(resolve(__dirname, '../../../../config.json'));
|
const PATH_TO_CONFIG = join(resolve(__dirname, '../../../../config.json'));
|
||||||
|
|
||||||
export default function setupNconf (file) {
|
module.exports = function setupNconf (file) {
|
||||||
let configFile = file || PATH_TO_CONFIG;
|
let configFile = file || PATH_TO_CONFIG;
|
||||||
|
|
||||||
nconf
|
nconf
|
||||||
@@ -14,4 +14,4 @@ export default function setupNconf (file) {
|
|||||||
nconf.set('IS_PROD', nconf.get('NODE_ENV') === 'production');
|
nconf.set('IS_PROD', nconf.get('NODE_ENV') === 'production');
|
||||||
nconf.set('IS_DEV', nconf.get('NODE_ENV') === 'development');
|
nconf.set('IS_DEV', nconf.get('NODE_ENV') === 'development');
|
||||||
nconf.set('IS_TEST', nconf.get('NODE_ENV') === 'test');
|
nconf.set('IS_TEST', nconf.get('NODE_ENV') === 'test');
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -31,4 +31,4 @@ function walkControllers (filePath) {
|
|||||||
|
|
||||||
walkControllers(CONTROLLERS_PATH);
|
walkControllers(CONTROLLERS_PATH);
|
||||||
|
|
||||||
export default router;
|
module.exports = router;
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ if (nconf.get('IS_PROD')) {
|
|||||||
service = mockAnalyticsService;
|
service = mockAnalyticsService;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function attachAnalytics (req, res, next) {
|
module.exports = function attachAnalytics (req, res, next) {
|
||||||
res.analytics = service;
|
res.analytics = service;
|
||||||
|
|
||||||
next();
|
next();
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ export function cron (options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO check that it's used everywhere
|
// TODO check that it's used everywhere
|
||||||
export default async function cronMiddleware (req, res, next) {
|
module.exports = async function cronMiddleware (req, res, next) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
let analytics = res.analytics;
|
let analytics = res.analytics;
|
||||||
|
|
||||||
@@ -335,4 +335,4 @@ export default async function cronMiddleware (req, res, next) {
|
|||||||
.then(() => next())
|
.then(() => next())
|
||||||
.catch(next);
|
.catch(next);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
// it's yet to be decided whether to keep it or not
|
// it's yet to be decided whether to keep it or not
|
||||||
import domainMiddleware from 'domain-middleware';
|
import domainMiddleware from 'domain-middleware';
|
||||||
|
|
||||||
export default function implementDomainMiddleware (server, mongoose) {
|
module.exports = function implementDomainMiddleware (server, mongoose) {
|
||||||
return domainMiddleware({
|
return domainMiddleware({
|
||||||
server: {
|
server: {
|
||||||
close () {
|
close () {
|
||||||
@@ -13,4 +13,4 @@ export default function implementDomainMiddleware (server, mongoose) {
|
|||||||
},
|
},
|
||||||
killTimeout: 10000,
|
killTimeout: 10000,
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
} from '../../libs/api-v3/errors';
|
} from '../../libs/api-v3/errors';
|
||||||
import { map } from 'lodash';
|
import { map } from 'lodash';
|
||||||
|
|
||||||
export default function errorHandler (err, req, res, next) { // eslint-disable-line no-unused-vars
|
module.exports = function errorHandler (err, req, res, next) { // eslint-disable-line no-unused-vars
|
||||||
// Log the original error with some metadata
|
// Log the original error with some metadata
|
||||||
let stack = err.stack || err.message || err;
|
let stack = err.stack || err.message || err;
|
||||||
|
|
||||||
@@ -77,4 +77,4 @@ export default function errorHandler (err, req, res, next) { // eslint-disable-l
|
|||||||
// In some occasions like when invalid JSON is supplied `res.respond` might be not yet avalaible,
|
// In some occasions like when invalid JSON is supplied `res.respond` might be not yet avalaible,
|
||||||
// in this case we use the standard res.status(...).json(...)
|
// in this case we use the standard res.status(...).json(...)
|
||||||
return res.respond ? res.respond(responseErr.httpCode, jsonRes) : res.status(responseErr.httpCode).json(jsonRes);
|
return res.respond ? res.respond(responseErr.httpCode, jsonRes) : res.status(responseErr.httpCode).json(jsonRes);
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ function _attachTranslateFunction (req, res, next) {
|
|||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function getUserLanguage (req, res, next) {
|
module.exports = function getUserLanguage (req, res, next) {
|
||||||
if (req.query.lang) { // In case the language is specified in the request url, use it
|
if (req.query.lang) { // In case the language is specified in the request url, use it
|
||||||
req.language = translations[req.query.lang] ? req.query.lang : 'en';
|
req.language = translations[req.query.lang] ? req.query.lang : 'en';
|
||||||
return _attachTranslateFunction(...arguments);
|
return _attachTranslateFunction(...arguments);
|
||||||
@@ -85,4 +85,4 @@ export default function getUserLanguage (req, res, next) {
|
|||||||
req.language = _getFromUser(null, req);
|
req.language = _getFromUser(null, req);
|
||||||
return _attachTranslateFunction(...arguments);
|
return _attachTranslateFunction(...arguments);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const DISABLE_LOGGING = nconf.get('DISABLE_REQUEST_LOGGING');
|
|||||||
const SESSION_SECRET = nconf.get('SESSION_SECRET');
|
const SESSION_SECRET = nconf.get('SESSION_SECRET');
|
||||||
const TWO_WEEKS = 1000 * 60 * 60 * 24 * 14;
|
const TWO_WEEKS = 1000 * 60 * 60 * 24 * 14;
|
||||||
|
|
||||||
export default function attachMiddlewares (app) {
|
module.exports = function attachMiddlewares (app) {
|
||||||
if (!IS_PROD && !DISABLE_LOGGING) app.use(morgan('dev'));
|
if (!IS_PROD && !DISABLE_LOGGING) app.use(morgan('dev'));
|
||||||
|
|
||||||
// TODO handle errors
|
// TODO handle errors
|
||||||
@@ -45,4 +45,4 @@ export default function attachMiddlewares (app) {
|
|||||||
|
|
||||||
// Error handler middleware, define as the last one
|
// Error handler middleware, define as the last one
|
||||||
app.use(errorHandler);
|
app.use(errorHandler);
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ let env = {
|
|||||||
env[key] = nconf.get(key);
|
env[key] = nconf.get(key);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default function locals (req, res, next) {
|
module.exports = function locals (req, res, next) {
|
||||||
let language = _.find(i18n.availableLanguages, {code: req.language});
|
let language = _.find(i18n.availableLanguages, {code: req.language});
|
||||||
let isStaticPage = req.url.split('/')[1] === 'static'; // If url contains '/static/'
|
let isStaticPage = req.url.split('/')[1] === 'static'; // If url contains '/static/'
|
||||||
|
|
||||||
@@ -59,4 +59,4 @@ export default function locals (req, res, next) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
next();
|
next();
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ import {
|
|||||||
NotFound,
|
NotFound,
|
||||||
} from '../../libs/api-v3/errors';
|
} from '../../libs/api-v3/errors';
|
||||||
|
|
||||||
export default function (req, res, next) {
|
module.exports = function NotFoundMiddleware (req, res, next) {
|
||||||
next(new NotFound());
|
next(new NotFound());
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export default function responseHandler (req, res, next) {
|
module.exports = function responseHandler (req, res, next) {
|
||||||
res.respond = function respond (status = 200, data = {}) {
|
res.respond = function respond (status = 200, data = {}) {
|
||||||
res.status(status).json(data);
|
res.status(status).json(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
next();
|
next();
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// TODO tests?
|
// TODO tests?
|
||||||
export default function setupBodyMiddleware (req, res, next) {
|
module.exports = function setupBodyMiddleware (req, res, next) {
|
||||||
req.body = req.body || {};
|
req.body = req.body || {};
|
||||||
next();
|
next();
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ const MAX_AGE = IS_PROD ? 31536000000 : 0;
|
|||||||
const PUBLIC_DIR = path.join(__dirname, '/../../../public');
|
const PUBLIC_DIR = path.join(__dirname, '/../../../public');
|
||||||
const BUILD_DIR = path.join(__dirname, '/../../../build');
|
const BUILD_DIR = path.join(__dirname, '/../../../build');
|
||||||
|
|
||||||
export default function staticMiddleware (expressApp) {
|
module.exports = function staticMiddleware (expressApp) {
|
||||||
// TODO move all static files to a single location (one for public and one for build)
|
// TODO move all static files to a single location (one for public and one for build)
|
||||||
expressApp.use(express.static(BUILD_DIR, { maxAge: MAX_AGE }));
|
expressApp.use(express.static(BUILD_DIR, { maxAge: MAX_AGE }));
|
||||||
expressApp.use('/common/dist', express.static(`${PUBLIC_DIR}/../../common/dist`, { maxAge: MAX_AGE }));
|
expressApp.use('/common/dist', express.static(`${PUBLIC_DIR}/../../common/dist`, { maxAge: MAX_AGE }));
|
||||||
@@ -15,4 +15,4 @@ export default function staticMiddleware (expressApp) {
|
|||||||
expressApp.use('/common/script/public', express.static(`${PUBLIC_DIR}/../../common/script/public`, { maxAge: MAX_AGE }));
|
expressApp.use('/common/script/public', express.static(`${PUBLIC_DIR}/../../common/script/public`, { maxAge: MAX_AGE }));
|
||||||
expressApp.use('/common/img', express.static(`${PUBLIC_DIR}/../../common/img`, { maxAge: MAX_AGE }));
|
expressApp.use('/common/img', express.static(`${PUBLIC_DIR}/../../common/img`, { maxAge: MAX_AGE }));
|
||||||
expressApp.use(express.static(PUBLIC_DIR));
|
expressApp.use(express.static(PUBLIC_DIR));
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -316,8 +316,8 @@ schema.methods.startQuest = async function startQuest (user) {
|
|||||||
// send notifications in the background without blocking
|
// send notifications in the background without blocking
|
||||||
User.find(
|
User.find(
|
||||||
{ _id: { $in: nonUserQuestMembers } },
|
{ _id: { $in: nonUserQuestMembers } },
|
||||||
'party.quest items.quests auth.facebook auth.local preferences.emailNotifications pushDevices profile.name',
|
'party.quest items.quests auth.facebook auth.local preferences.emailNotifications pushDevices profile.name'
|
||||||
).exec().then(membersToNotify => {
|
).exec().then((membersToNotify) => {
|
||||||
let membersToEmail = _.filter(membersToNotify, (member) => {
|
let membersToEmail = _.filter(membersToNotify, (member) => {
|
||||||
// send push notifications and filter users that disabled emails
|
// send push notifications and filter users that disabled emails
|
||||||
sendPushNotification(member, 'HabitRPG', `${shared.i18n.t('questStarted')}: ${quest.text()}`);
|
sendPushNotification(member, 'HabitRPG', `${shared.i18n.t('questStarted')}: ${quest.text()}`);
|
||||||
|
|||||||
@@ -167,4 +167,4 @@ server.listen(app.get('port'), () => {
|
|||||||
return logger.info(`Express server listening on port ${app.get('port')}`);
|
return logger.info(`Express server listening on port ${app.get('port')}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default server;
|
module.exports = server;
|
||||||
|
|||||||
Reference in New Issue
Block a user