From 11e7a9b9d46a764a20f507c37ff6f298d5dff47e Mon Sep 17 00:00:00 2001 From: Kata Date: Sun, 9 Feb 2020 19:45:48 -0500 Subject: [PATCH] fix(role patch): fix buggy arrayMatches tester --- Server/api/servers.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Server/api/servers.js b/Server/api/servers.js index c937d09..e240fc3 100644 --- a/Server/api/servers.js +++ b/Server/api/servers.js @@ -136,7 +136,11 @@ module.exports = (R, $) => { newRoles = [...newRoles, ...sanitizedAdded] if (!arrayMatches(currentRoles, newRoles)) { + console.log("updating!", { currentRoles, newRoles }); + await $.discord.updateRoles(gm, newRoles) + } else { + console.log("not updating!", { currentRoles, newRoles }); } ctx.body = { ok: true } @@ -146,4 +150,18 @@ module.exports = (R, $) => { }) } -const arrayMatches = (a, b) => a.length === b.length && a.reduce((_, aValue) => b.includes(aValue), true) \ No newline at end of file +// if length is the same, check elements. + +const arrayMatches = (a, b) => { + if (a.length === b.length) { + for (let item of a) { + if (!b.includes(item)) { + return false + } + } + + return true + } + + return false +} \ No newline at end of file