mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
refactor: remove dupe code
This commit is contained in:
@@ -8,22 +8,10 @@ module.exports = function (module) {
|
||||
return;
|
||||
}
|
||||
value = Array.isArray(value) ? value : [value];
|
||||
value = value.map(helpers.valueToString);
|
||||
value.reverse();
|
||||
const exists = await module.isObjectField(key, 'array');
|
||||
if (exists) {
|
||||
await module.client.collection('objects').updateOne({
|
||||
_key: key,
|
||||
}, {
|
||||
$push: {
|
||||
array: {
|
||||
$each: value,
|
||||
$position: 0,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
upsert: true,
|
||||
});
|
||||
await listPush(key, value, { $position: 0 });
|
||||
} else {
|
||||
await module.listAppend(key, value);
|
||||
}
|
||||
@@ -34,19 +22,24 @@ module.exports = function (module) {
|
||||
return;
|
||||
}
|
||||
value = Array.isArray(value) ? value : [value];
|
||||
value = value.map(helpers.valueToString);
|
||||
await listPush(key, value);
|
||||
};
|
||||
|
||||
async function listPush(key, values, position) {
|
||||
values = values.map(helpers.valueToString);
|
||||
await module.client.collection('objects').updateOne({
|
||||
_key: key,
|
||||
}, {
|
||||
$push: {
|
||||
array: {
|
||||
$each: value,
|
||||
$each: values,
|
||||
...(position || {}),
|
||||
},
|
||||
},
|
||||
}, {
|
||||
upsert: true,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
module.listRemoveLast = async function (key) {
|
||||
if (!key) {
|
||||
|
||||
Reference in New Issue
Block a user