Skip to content

Commit

Permalink
Merge pull request #16 from CMU-313/JasmineRocket-patch-3
Browse files Browse the repository at this point in the history
Refactoring code in src/groups/update.js
  • Loading branch information
JasmineRocket authored Sep 25, 2024
2 parents 1742f8a + b6c3308 commit 7d96899
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions src/groups/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,7 @@ module.exports = function (Groups) {
}
});

const payload = {
description: values.description || '',
icon: values.icon || '',
labelColor: values.labelColor || '#000000',
textColor: values.textColor || '#ffffff',
};

if (values.hasOwnProperty('userTitle')) {
payload.userTitle = values.userTitle || '';
}

if (values.hasOwnProperty('userTitleEnabled')) {
payload.userTitleEnabled = values.userTitleEnabled ? '1' : '0';
}

if (values.hasOwnProperty('hidden')) {
payload.hidden = values.hidden ? '1' : '0';
}

if (values.hasOwnProperty('private')) {
payload.private = values.private ? '1' : '0';
}
const payload = payload_helper(values);

if (values.hasOwnProperty('disableJoinRequests')) {
payload.disableJoinRequests = values.disableJoinRequests ? '1' : '0';
Expand Down Expand Up @@ -90,6 +69,32 @@ module.exports = function (Groups) {
});
};

function payload_helper(values) {
const payload = {
description: values.description || '',
icon: values.icon || '',
labelColor: values.labelColor || '#000000',
textColor: values.textColor || '#ffffff',
};

if (values.hasOwnProperty('userTitle')) {
payload.userTitle = values.userTitle || '';
}

if (values.hasOwnProperty('userTitleEnabled')) {
payload.userTitleEnabled = values.userTitleEnabled ? '1' : '0';
}

if (values.hasOwnProperty('hidden')) {
payload.hidden = values.hidden ? '1' : '0';
}

if (values.hasOwnProperty('private')) {
payload.private = values.private ? '1' : '0';
}
return payload;
}

async function updateVisibility(groupName, hidden) {
if (hidden) {
await db.sortedSetRemoveBulk([
Expand Down

0 comments on commit 7d96899

Please sign in to comment.