mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-01-18 21:17:59 +00:00
Update update CLI code
This commit is contained in:
parent
951b24a32b
commit
01166166e9
@ -42,15 +42,18 @@
|
|||||||
$: code = buildCode(form);
|
$: code = buildCode(form);
|
||||||
|
|
||||||
function 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(', ') + ' }';
|
let operation = '{ ' + form.parameters.filter(p => p.type).map(p => `${p.type}: ${p.value || '{}'}`).join(', ') + ' }';
|
||||||
if (operation === '{ }') {
|
if (operation === '{ }') {
|
||||||
operation = '{}';
|
operation = '{}';
|
||||||
}
|
}
|
||||||
|
|
||||||
const options = form.upsert ? ', { upsert: true }' : '';
|
let options = (form.upsert || form.many) ? ', { ' : '';
|
||||||
const code = `db.${collection.key}.${method}(${form.query || '{}'}, ${operation}${options});`;
|
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;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user