fix exports

This commit is contained in:
Matteo Pagliazzi
2019-10-01 17:53:48 +02:00
parent 4faa06f37d
commit cca5b8492b
144 changed files with 271 additions and 315 deletions

View File

@@ -3,7 +3,7 @@ import get from 'lodash/get';
// TODO used only in client, move there?
module.exports = function addTag (user, req = {}) {
export default function addTag (user, req = {}) {
if (!user.tags) {
user.tags = [];
}
@@ -14,4 +14,4 @@ module.exports = function addTag (user, req = {}) {
});
return user.tags;
};
}

View File

@@ -3,7 +3,7 @@ import clone from 'lodash/clone';
// TODO move to client since it's only used there?
module.exports = function addTask (user, req = {body: {}}) {
export default function addTask (user, req = {body: {}}) {
let task = taskDefaults(req.body, user);
user.tasksOrder[`${task.type}s`].unshift(task._id);
user[`${task.type}s`].unshift(task);
@@ -15,4 +15,4 @@ module.exports = function addTask (user, req = {body: {}}) {
task._advanced = !user.preferences.advancedCollapsed;
return task;
};
}

View File

@@ -4,7 +4,7 @@ import {
BadRequest,
} from '../libs/errors';
module.exports = function blockUser (user, req = {}) {
export default function blockUser (user, req = {}) {
if (!validator.isUUID(req.params.uuid)) throw new BadRequest(i18n.t('invalidUUID', req.language));
if (req.params.uuid === user._id) throw new BadRequest(i18n.t('blockYourself', req.language));
@@ -19,4 +19,4 @@ module.exports = function blockUser (user, req = {}) {
return [
user.inbox.blocks,
];
};
}

View File

@@ -20,7 +20,7 @@ import {BuyHourglassMountOperation} from './buyMount';
// @TODO: when we are sure buy is the only function used, let's move the buy files to a folder
module.exports = function buy (user, req = {}, analytics, options = {quantity: 1, hourglass: false}) {
export default function buy (user, req = {}, analytics, options = {quantity: 1, hourglass: false}) {
let key = get(req, 'params.key');
const hourglass = options.hourglass;
const quantity = options.quantity;
@@ -103,4 +103,4 @@ module.exports = function buy (user, req = {}, analytics, options = {quantity: 1
}
return buyRes;
};
}

View File

@@ -2,7 +2,7 @@ import content from '../../content/index';
import filter from 'lodash/filter';
import isEmpty from 'lodash/isEmpty';
import pick from 'lodash/pick';
import count from '../../count';
import * as count from '../../count';
import splitWhitespace from '../../libs/splitWhitespace';
import {
NotAuthorized,

View File

@@ -9,7 +9,7 @@ import {
} from '../../libs/errors';
import errorMessage from '../../libs/errorMessage';
module.exports = function buyMysterySet (user, req = {}, analytics) {
export default function buyMysterySet (user, req = {}, analytics) {
let key = get(req, 'params.key');
if (!key) throw new BadRequest(errorMessage('missingKeyParam'));
@@ -46,4 +46,4 @@ module.exports = function buyMysterySet (user, req = {}, analytics) {
{ items: user.items, purchasedPlanConsecutive: user.purchased.plan.consecutive },
i18n.t('hourglassPurchaseSet', req.language),
];
};
}

View File

@@ -9,7 +9,7 @@ import {
} from '../../libs/errors';
import errorMessage from '../../libs/errorMessage';
module.exports = function purchaseHourglass (user, req = {}, analytics, quantity = 1) {
export default function purchaseHourglass (user, req = {}, analytics, quantity = 1) {
let key = get(req, 'params.key');
if (!key) throw new BadRequest(errorMessage('missingKeyParam'));
@@ -72,4 +72,4 @@ module.exports = function purchaseHourglass (user, req = {}, analytics, quantity
{ items: user.items, purchasedPlanConsecutive: user.purchased.plan.consecutive },
i18n.t('hourglassPurchase', req.language),
];
};
}

View File

@@ -68,7 +68,7 @@ function purchaseItem (user, item, price, type, key) {
const acceptedTypes = ['eggs', 'hatchingPotions', 'food', 'gear', 'bundles'];
const singlePurchaseTypes = ['gear'];
module.exports = function purchase (user, req = {}, analytics) {
export default function purchase (user, req = {}, analytics) {
let type = get(req.params, 'type');
let key = get(req.params, 'key');
@@ -122,4 +122,4 @@ module.exports = function purchase (user, req = {}, analytics) {
return [
pick(user, splitWhitespace('items balance')),
];
};
}

View File

@@ -33,7 +33,7 @@ function resetClass (user, req = {}) {
return balanceRemoved;
}
module.exports = function changeClass (user, req = {}, analytics) {
export default function changeClass (user, req = {}, analytics) {
let klass = get(req, 'query.class');
let balanceRemoved = 0;
// user.flags.classSelected is set to false after the user paid the 3 gems
@@ -75,4 +75,4 @@ module.exports = function changeClass (user, req = {}, analytics) {
return [
pick(user, splitWhitespace('stats flags items preferences')),
];
};
}

View File

@@ -6,7 +6,7 @@ import { NotFound } from '../libs/errors';
// TODO used only in client, move there?
module.exports = function deleteTag (user, req = {}) {
export default function deleteTag (user, req = {}) {
let tid = get(req, 'params.id');
let index = findIndex(user.tags, {
@@ -31,4 +31,4 @@ module.exports = function deleteTag (user, req = {}) {
});
return user.tags;
};
}

View File

@@ -5,7 +5,7 @@ import findIndex from 'lodash/findIndex';
// TODO used only in client, move there?
module.exports = function deleteTask (user, req = {}) {
export default function deleteTask (user, req = {}) {
let tid = get(req, 'params.id');
let taskType = get(req, 'params.taskType');
@@ -20,4 +20,4 @@ module.exports = function deleteTask (user, req = {}) {
user[`${taskType}s`].splice(index, 1);
return {};
};
}

View File

@@ -2,7 +2,7 @@ import splitWhitespace from '../libs/splitWhitespace';
import { capByLevel } from '../statHelpers';
import pick from 'lodash/pick';
module.exports = function disableClasses (user) {
export default function disableClasses (user) {
user.stats.class = 'warrior';
user.flags.classSelected = true;
user.preferences.disableClasses = true;
@@ -13,4 +13,4 @@ module.exports = function disableClasses (user) {
return [
pick(user, splitWhitespace('stats flags preferences')),
];
};
}

View File

@@ -8,7 +8,7 @@ import {
import get from 'lodash/get';
import errorMessage from '../libs/errorMessage';
module.exports = function equip (user, req = {}) {
export default function equip (user, req = {}) {
// Being type a parameter followed by another parameter
// when using the API it must be passes specifically in the URL, it's won't default to equipped
let type = get(req, 'params.type', 'equipped');
@@ -74,4 +74,4 @@ module.exports = function equip (user, req = {}) {
let res = [user.items];
if (message) res.push(message);
return res;
};
}

View File

@@ -30,7 +30,7 @@ function evolve (user, pet, req) {
}, req.language);
}
module.exports = function feed (user, req = {}) {
export default function feed (user, req = {}) {
let pet = get(req, 'params.pet');
let foodK = get(req, 'params.food');
@@ -116,4 +116,4 @@ module.exports = function feed (user, req = {}) {
userPets[pet.key],
message,
];
};
}

View File

@@ -12,7 +12,7 @@ import {
} from '../libs/errors';
import errorMessage from '../libs/errorMessage';
module.exports = function hatch (user, req = {}) {
export default function hatch (user, req = {}) {
let egg = get(req, 'params.egg');
let hatchingPotion = get(req, 'params.hatchingPotion');
@@ -66,4 +66,4 @@ module.exports = function hatch (user, req = {}) {
user.items,
i18n.t('messageHatched', req.language),
];
};
}

View File

@@ -32,7 +32,7 @@ import scoreTask from './scoreTask';
import markPmsRead from './markPMSRead';
import * as pinnedGearUtils from './pinnedGearUtils';
module.exports = {
export default {
sleep,
revive,
reset,

View File

@@ -1,10 +1,10 @@
import i18n from '../i18n';
module.exports = function markPmsRead (user) {
export default function markPmsRead (user) {
user.inbox.newMessages = 0;
return [
user.inbox.newMessages,
i18n.t('pmsMarkedRead'),
];
};
}

View File

@@ -13,7 +13,7 @@ function markNotificationAsRead (user) {
if (index !== -1) user.notifications.splice(index, 1);
}
module.exports = function openMysteryItem (user, req = {}, analytics) {
export default function openMysteryItem (user, req = {}, analytics) {
const mysteryItems = user.purchased.plan.mysteryItems;
let item = mysteryItems.shift();
@@ -47,4 +47,4 @@ module.exports = function openMysteryItem (user, req = {}, analytics) {
item,
i18n.t('mysteryItemOpened', req.language),
];
};
}

View File

@@ -2,7 +2,6 @@ import content from '../content/index';
import getItemInfo from '../libs/getItemInfo';
import { BadRequest } from '../libs/errors';
import i18n from '../i18n';
import isPinned from '../libs/isPinned';
import getItemByPathAndType from '../libs/getItemByPathAndType';
import getOfficialPinnedItems from '../libs/getOfficialPinnedItems';
@@ -31,12 +30,12 @@ function checkForNullEntries (array) {
return array.filter(e => Boolean(e));
}
function checkPinnedAreasForNullEntries (user) {
export function checkPinnedAreasForNullEntries (user) {
user.pinnedItems = checkForNullEntries(user.pinnedItems);
user.unpinnedItems = checkForNullEntries(user.unpinnedItems);
}
function selectGearToPin (user) {
export function selectGearToPin (user) {
let changes = [];
each(content.gearTypes, (type) => {
@@ -50,7 +49,7 @@ function selectGearToPin (user) {
return sortBy(changes, (change) => sortOrder[change.type]);
}
function addPinnedGear (user, type, path) {
export function addPinnedGear (user, type, path) {
const foundIndex = pathExistsInArray(user.pinnedItems, path);
if (foundIndex === -1 && type && path) {
@@ -61,7 +60,7 @@ function addPinnedGear (user, type, path) {
}
}
function addPinnedGearByClass (user) {
export function addPinnedGearByClass (user) {
let newPinnedItems = selectGearToPin(user);
for (let item of newPinnedItems) {
@@ -71,7 +70,7 @@ function addPinnedGearByClass (user) {
}
}
function removeItemByPath (user, path) {
export function removeItemByPath (user, path) {
const foundIndex = pathExistsInArray(user.pinnedItems, path);
if (foundIndex >= 0) {
@@ -82,7 +81,7 @@ function removeItemByPath (user, path) {
return false;
}
function removePinnedGearByClass (user) {
export function removePinnedGearByClass (user) {
let currentPinnedItems = selectGearToPin(user);
for (let item of currentPinnedItems) {
@@ -92,7 +91,7 @@ function removePinnedGearByClass (user) {
}
}
function removePinnedGearAddPossibleNewOnes (user, itemPath, newItemKey) {
export function removePinnedGearAddPossibleNewOnes (user, itemPath, newItemKey) {
removeItemByPath(user, itemPath);
// an item of the users current "new" gear was bought
@@ -112,7 +111,7 @@ function removePinnedGearAddPossibleNewOnes (user, itemPath, newItemKey) {
* removes all pinned gear that the user already owns (like class starter gear which has been pinned before)
* @param user
*/
function removePinnedItemsByOwnedGear (user) {
export function removePinnedItemsByOwnedGear (user) {
each(user.items.gear.owned, (bool, key) => {
if (bool) {
removeItemByPath(user, `gear.flat.${key}`);
@@ -125,7 +124,7 @@ const PATHS_WITHOUT_ITEM = ['special.gems', 'special.rebirth_orb', 'special.fort
/**
* @returns {boolean} TRUE added the item / FALSE removed it
*/
function togglePinnedItem (user, {item, type, path}, req = {}) {
export function togglePinnedItem (user, {item, type, path}, req = {}) {
let arrayToChange;
let officialPinnedItems = getOfficialPinnedItems(user);
@@ -178,15 +177,4 @@ function togglePinnedItem (user, {item, type, path}, req = {}) {
}
}
module.exports = {
addPinnedGearByClass,
addPinnedGear,
removePinnedGearByClass,
removePinnedGearAddPossibleNewOnes,
removePinnedItemsByOwnedGear,
togglePinnedItem,
removeItemByPath,
selectGearToPin,
checkPinnedAreasForNullEntries,
isPinned,
};
export { default as isPinned } from '../libs/isPinned';

View File

@@ -22,7 +22,7 @@ function markNotificationAsRead (user, cardType) {
}
module.exports = function readCard (user, req = {}) {
export default function readCard (user, req = {}) {
let cardType = get(req.params, 'cardType');
if (!cardType) {
@@ -42,4 +42,4 @@ module.exports = function readCard (user, req = {}) {
{ specialItems: user.items.special, cardReceived: user.flags.cardReceived },
i18n.t('readCard', {cardType}, req.language),
];
};
}

View File

@@ -11,7 +11,7 @@ import isFreeRebirth from '../libs/isFreeRebirth';
const USERSTATSLIST = ['per', 'int', 'con', 'str', 'points', 'gp', 'exp', 'mp'];
module.exports = function rebirth (user, tasks = [], req = {}, analytics) {
export default function rebirth (user, tasks = [], req = {}, analytics) {
const notFree = !isFreeRebirth(user);
if (user.balance < 1.5 && notFree) {
@@ -113,4 +113,4 @@ module.exports = function rebirth (user, tasks = [], req = {}, analytics) {
{user, tasks},
i18n.t('rebirthComplete'),
];
};
}

View File

@@ -7,7 +7,7 @@ import {
import splitWhitespace from '../libs/splitWhitespace';
import pick from 'lodash/pick';
module.exports = function releaseBoth (user, req = {}) {
export default function releaseBoth (user, req = {}) {
let animal;
if (!user.achievements.triadBingo) {
@@ -92,4 +92,4 @@ module.exports = function releaseBoth (user, req = {}) {
pick(user, splitWhitespace('achievements items balance')),
i18n.t('mountsAndPetsReleased'),
];
};
}

View File

@@ -5,7 +5,7 @@ import {
NotAuthorized,
} from '../libs/errors';
module.exports = function releaseMounts (user, req = {}, analytics) {
export default function releaseMounts (user, req = {}, analytics) {
if (user.balance < 1) {
throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
}
@@ -53,4 +53,4 @@ module.exports = function releaseMounts (user, req = {}, analytics) {
user.items.mounts,
i18n.t('mountsReleased'),
];
};
}

View File

@@ -5,7 +5,7 @@ import {
NotAuthorized,
} from '../libs/errors';
module.exports = function releasePets (user, req = {}, analytics) {
export default function releasePets (user, req = {}, analytics) {
if (user.balance < 1) {
throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
}
@@ -53,4 +53,4 @@ module.exports = function releasePets (user, req = {}, analytics) {
user.items.pets,
i18n.t('petsReleased'),
];
};
}

View File

@@ -4,7 +4,7 @@ import {
NotAuthorized,
} from '../libs/errors';
module.exports = function reroll (user, tasks = [], req = {}, analytics) {
export default function reroll (user, tasks = [], req = {}, analytics) {
if (user.balance < 1) {
throw new NotAuthorized(i18n.t('notEnoughGems', req.language));
}
@@ -34,4 +34,4 @@ module.exports = function reroll (user, tasks = [], req = {}, analytics) {
{user, tasks},
i18n.t('fortifyComplete'),
];
};
}

View File

@@ -1,7 +1,7 @@
import resetGear from '../fns/resetGear';
import i18n from '../i18n';
module.exports = function reset (user, tasks = []) {
export default function reset (user, tasks = []) {
user.stats.hp = 50;
user.stats.lvl = 1;
user.stats.gp = 0;
@@ -27,4 +27,4 @@ module.exports = function reset (user, tasks = []) {
{user, tasksToRemove},
i18n.t('resetComplete'),
];
};
}

View File

@@ -12,7 +12,7 @@ import predictableRandom from '../fns/predictableRandom';
import { removePinnedGearByClass, addPinnedGearByClass, addPinnedGear } from './pinnedGearUtils';
import getItemInfo from '../libs/getItemInfo';
module.exports = function revive (user, req = {}, analytics) {
export default function revive (user, req = {}, analytics) {
if (user.stats.hp > 0) {
throw new NotAuthorized(i18n.t('cannotRevive', req.language));
}
@@ -119,4 +119,4 @@ module.exports = function revive (user, req = {}, analytics) {
user.items,
message,
];
};
}

View File

@@ -184,7 +184,7 @@ function _updateCounter (task, direction, times) {
}
}
module.exports = function scoreTask (options = {}, req = {}) {
export default function scoreTask (options = {}, req = {}) {
let {user, task, direction, times = 1, cron = false} = options;
let delta = 0;
let stats = {
@@ -330,4 +330,4 @@ module.exports = function scoreTask (options = {}, req = {}) {
req.yesterDailyScored = task.yesterDailyScored;
updateStats(user, stats, req);
return [delta];
};
}

View File

@@ -12,7 +12,7 @@ import {
// @TODO: 'special' type throws NotAuthorized error
const ACCEPTEDTYPES = ['eggs', 'hatchingPotions', 'food'];
module.exports = function sell (user, req = {}) {
export default function sell (user, req = {}) {
let key = get(req.params, 'key');
let type = get(req.params, 'type');
let amount = get(req.query, 'amount', 1);
@@ -55,4 +55,4 @@ module.exports = function sell (user, req = {}) {
return [
pick(user, splitWhitespace('stats items')),
];
};
}

View File

@@ -1,4 +1,4 @@
module.exports = function sleep (user, req = {}, analytics) {
export default function sleep (user, req = {}, analytics) {
user.preferences.sleep = !user.preferences.sleep;
if (analytics) {
@@ -11,4 +11,4 @@ module.exports = function sleep (user, req = {}, analytics) {
}
return [user.preferences.sleep];
};
}

View File

@@ -3,7 +3,7 @@ import get from 'lodash/get';
// TODO used only in client, move there?
module.exports = function sortTag (user, req = {}) {
export default function sortTag (user, req = {}) {
let to = get(req, 'query.to');
let fromParam = get(req, 'query.from');
@@ -16,4 +16,4 @@ module.exports = function sortTag (user, req = {}) {
user.tags.splice(to, 0, user.tags.splice(fromParam, 1)[0]);
return user.tags;
};
}

View File

@@ -9,7 +9,7 @@ import findIndex from 'lodash/findIndex';
// TODO used only in client, move there?
module.exports = function sortTask (user, req = {}) {
export default function sortTask (user, req = {}) {
let id = get(req, 'params.id');
let to = get(req, 'query.to');
let fromParam = get(req, 'query.from');
@@ -47,4 +47,4 @@ module.exports = function sortTask (user, req = {}) {
}
return tasks;
};
}

View File

@@ -10,7 +10,7 @@ import i18n from '../../i18n';
import errorMessage from '../../libs/errorMessage';
import hasClass from '../../libs/hasClass';
module.exports = function allocate (user, req = {}) {
export default function allocate (user, req = {}) {
let stat = get(req, 'query.stat', 'str');
if (ATTRIBUTES.indexOf(stat) === -1) {
@@ -34,4 +34,4 @@ module.exports = function allocate (user, req = {}) {
return [
user.stats,
];
};
}

View File

@@ -10,7 +10,7 @@ import i18n from '../../i18n';
import errorMessage from '../../libs/errorMessage';
import hasClass from '../../libs/hasClass';
module.exports = function allocateBulk (user, req = {}) {
export default function allocateBulk (user, req = {}) {
const stats = get(req, 'body.stats');
if (!stats) throw new BadRequest(errorMessage('statsObjectRequired'));
@@ -47,4 +47,4 @@ module.exports = function allocateBulk (user, req = {}) {
return [
user.stats,
];
};
}

View File

@@ -1,11 +1,11 @@
import times from 'lodash/times';
import autoAllocate from '../../fns/autoAllocate';
module.exports = function allocateNow (user) {
export default function allocateNow (user) {
times(user.stats.points, () => autoAllocate(user));
user.stats.points = 0;
return [
user.stats,
];
};
}

View File

@@ -15,7 +15,7 @@ import content from '../content/index';
// If item is already purchased -> equip it
// Otherwise unlock it
module.exports = function unlock (user, req = {}, analytics) {
export default function unlock (user, req = {}, analytics) {
let path = get(req.query, 'path');
if (!path) {
@@ -138,4 +138,4 @@ module.exports = function unlock (user, req = {}, analytics) {
if (!alreadyOwns) response.push(i18n.t('unlocked', req.language));
return response;
};
}

View File

@@ -5,7 +5,7 @@ import { NotFound } from '../libs/errors';
// TODO used only in client, move there?
module.exports = function updateTag (user, req = {}) {
export default function updateTag (user, req = {}) {
let tid = get(req, 'params.id');
let index = findIndex(user.tags, {
@@ -18,4 +18,4 @@ module.exports = function updateTag (user, req = {}) {
user.tags[index].name = get(req, 'body.name');
return user.tags[index];
};
}

View File

@@ -2,7 +2,7 @@ import merge from 'lodash/merge';
import omit from 'lodash/omit';
// From server pass task.toObject() not the task document directly
module.exports = function updateTask (task, req = {}) {
export default function updateTask (task, req = {}) {
let body = req.body || {};
// If reminders are updated -> replace the original ones
@@ -32,4 +32,4 @@ module.exports = function updateTask (task, req = {}) {
}
return [task];
};
}