Skip to content

Commit

Permalink
Refactor createPayload
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamed-elzeni committed Sep 5, 2024
1 parent e87b526 commit 6555c15
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions src/groups/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,33 +67,28 @@ module.exports = function (Groups) {
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 booleanFields = [
'userTitleEnabled',
'hidden',
'private',
'disableJoinRequests',
'disableLeave',
];

if (values.hasOwnProperty('disableJoinRequests')) {
payload.disableJoinRequests = values.disableJoinRequests ? '1' : '0';
}
booleanFields.forEach((field) => {
if (values.hasOwnProperty(field)) {
payload[field] = values[field] ? '1' : '0';
}
});

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

return payload;
}


async function handleSpecialProperties(groupName, values, payload) {
if (values.hasOwnProperty('name')) {
await checkNameChange(groupName, values.name);
Expand Down

0 comments on commit 6555c15

Please sign in to comment.