1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-18 13:07:58 +00:00

Update update CLI code

This commit is contained in:
Romein van Buren 2023-01-21 10:45:44 +01:00
parent 951b24a32b
commit 01166166e9
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49

View File

@ -42,15 +42,18 @@
$: code = buildCode(form);
function buildCode(form) {
const method = form.many ? 'updateMany' : 'updateOne';
let operation = '{ ' + form.parameters.filter(p => p.type).map(p => `${p.type}: ${p.value || '{}'}`).join(', ') + ' }';
if (operation === '{ }') {
operation = '{}';
}
const options = form.upsert ? ', { upsert: true }' : '';
const code = `db.${collection.key}.${method}(${form.query || '{}'}, ${operation}${options});`;
let options = (form.upsert || form.many) ? ', { ' : '';
form.upsert && (options += 'upsert: true');
form.upsert && form.many && (options += ', ');
form.many && (options += 'multi: true');
(form.upsert || form.many) && (options += ' }');
const code = `db.${collection.key}.update(${form.query || '{}'}, ${operation}${options});`;
return code;
}