Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
versx committed Dec 15, 2020
1 parent ca8d54b commit a93cd6f
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -987,17 +987,17 @@ router.post('/lures/delete_all', async (req, res) => {
router.post('/role/add', async (req, res) => {
const { guild_id, roles } = req.body;
const user_id = req.session.user_id;
const roles = getRoles(guild_id, roles);
const cityRoles = getRoles(guild_id, roles);
let error = false;
for (const role of roles) {
const result = await DiscordClient.addRole(guild_id, user_id, role);
for (const cityRole of cityRoles) {
const result = await DiscordClient.addRole(guild_id, user_id, cityRole);
if (!result) {
console.error('Failed to assign role', role, 'to guild', guild_id, 'user', user_id);
console.error('Failed to assign city role', cityRole, 'to guild', guild_id, 'user', user_id);
error = true;
}
}
if (error) {
showError(res, 'role-add', `Failed to assign role(s) to guild ${guild_id} user ${user_id}`);
showError(res, 'role-add', `Failed to assign city role(s) to guild ${guild_id} user ${user_id}`);
return;
}
res.redirect('/roles');
Expand All @@ -1021,7 +1021,7 @@ router.post('/roles/remove_all', async (req, res) => {
const guild = config.discord.guilds.find(x => x.id === guild_id);
if (!guild) {
// Failed to find guild
showError(res, 'roles-remove-all', `Failed to find guild ${guild_id} to remove all roles for user ${userId}`);
showError(res, 'roles-remove-all', `Failed to find guild ${guild_id} to remove all city roles for user ${userId}`);
return;
}
const roles = guild.cityRoles;
Expand Down Expand Up @@ -1093,28 +1093,22 @@ const formatAreas = (guildId, subscriptionAreas) => {
: subscriptionAreas.join(',');
};

const getRoles = (guildId, name) => {
const getRoles = (guildId, cityName) => {
let areas;
if (city === 'all' || city.includes('all')) {
if (cityName === 'all' || cityName.includes('all')) {
config.discord.guilds.map(x => {
if (x.id === guildId) {
areas = x.cityRoles;
}
});
} else if (!Array.isArray(city)) {
areas = [city];
} else if (!Array.isArray(cityName)) {
areas = [cityName];
} else {
areas = city;
areas = cityName;
}
return areas || [];
};

const formatRoles = (guildId, roleNames) => {
return utils.arraysEqual(roleNames, config.discord.guilds.filter(x => x.id === guildId)[0].cityRoles)
? 'All' // TODO: Localize
: roleNames.join(',');
};

const showError = (res, page, message) => {
console.error(message);
const errorData = { ...defaultData };
Expand Down

0 comments on commit a93cd6f

Please sign in to comment.