Added shouldOverwrite to Pass class options to overwrite or append to the existing ones, the properties in main buffer

This commit is contained in:
alexandercerutti
2018-08-20 18:12:06 +02:00
parent f5df49f540
commit ff33cc9d2e
3 changed files with 24 additions and 5 deletions

View File

@@ -19,6 +19,7 @@ class Pass {
this.model = ""; this.model = "";
this.l10n = {}; this.l10n = {};
this.props = {}; this.props = {};
this.shouldOverwrite = !(this.options.hasOwnProperty("shouldOverwrite") && !this.options.shouldOverwrite);
fields.areas.forEach(a => this[a] = new fields.FieldsArea()); fields.areas.forEach(a => this[a] = new fields.FieldsArea());
} }
@@ -370,8 +371,24 @@ class Pass {
delete this.props["barcode"]; delete this.props["barcode"];
// Merging the original and the new properties if (this.shouldOverwrite) {
Object.assign(passFile, this.props); Object.assign(passFile, this.props);
} else {
Object.keys(this.props).forEach(prop => {
if (passFile[prop]) {
if (passFile[prop] instanceof Array) {
passFile[prop].push(...this.props[prop]);
return;
} else if (passFile[prop] instanceof Object) {
Object.assign(passFile[prop], this.props[prop]);
return;
}
return;
} else {
passFile[prop] = this.props[prop];
}
});
}
fields.areas.forEach(area => { fields.areas.forEach(area => {
if (this[area].fields.length) { if (this[area].fields.length) {

View File

@@ -10,7 +10,8 @@ let instance = Joi.object().keys({
passphrase: Joi.string().required(), passphrase: Joi.string().required(),
}).required() }).required()
}).required(), }).required(),
overrides: Joi.object() overrides: Joi.object(),
shouldOverwrite: Joi.boolean()
}); });
let barcode = Joi.object().keys({ let barcode = Joi.object().keys({

View File

@@ -49,7 +49,8 @@ function manageRequest(request, response) {
passphrase: "123456" passphrase: "123456"
} }
}, },
overrides: overrides overrides: overrides,
shouldOverwrite: true
}); });
pass.localize("it", { pass.localize("it", {
@@ -75,7 +76,7 @@ function manageRequest(request, response) {
longitude: 12.320653600000002 longitude: 12.320653600000002
}]); }]);
pass.relevance("maxDistance", 150); pass.relevance("maxDistance", 10);
//pass.localize("zu", {}); //pass.localize("zu", {});