Browse Source

fix: fixed autosuggest

Kristian Vos 4 years ago
parent
commit
0be1043f3b
1 changed files with 16 additions and 13 deletions
  1. 16 13
      backend/logic/util.js

+ 16 - 13
backend/logic/util.js

@@ -25,18 +25,21 @@ module.exports = class extends coreClass {
 			this.accountSchemaModel = await this.mongoModule.model("accountSchema");
 			this.accountModel = await this.mongoModule.model("account");
 
-			/*async.waterfall([
+			async.waterfall([
 				(next) => {
-					this.accountSchemaModel.find({}, null, { sort: "-version", limit: 1 }, next);
+					this.accountSchemaModel.find({}, null, { sort: "-version" }, next);
 				},
 
 				(schemas, next) => {
-					schemas[0].fields.forEach(field => {
-						field.fieldTypes.forEach(fieldType => {
-							if (fieldType.type === "text" && fieldType.autosuggestGroup) {
-								this._autosuggestMap[`${field.fieldId}.${fieldType.fieldTypeId}`] = fieldType.autosuggestGroup;
-								this._autosuggestCache[fieldType.autosuggestGroup] = [];
-							}
+					schemas.forEach(schema => {
+						this._autosuggestMap[schema.version] = {};
+						schema.fields.forEach(field => {
+							field.fieldTypes.forEach(fieldType => {
+								if (fieldType.type === "text" && fieldType.autosuggestGroup) {
+									this._autosuggestMap[schema.version][`${field.fieldId}.${fieldType.fieldTypeId}`] = fieldType.autosuggestGroup;
+									this._autosuggestCache[fieldType.autosuggestGroup] = [];
+								}
+							});
 						});
 					});
 
@@ -45,8 +48,8 @@ module.exports = class extends coreClass {
 
 				(accounts, next) => {
 					accounts.forEach(account => {
-						Object.keys(this._autosuggestMap).forEach(key => {
-							let autosuggestGroup = this._autosuggestMap[key];
+						Object.keys(this._autosuggestMap[account.version]).forEach(key => {
+							let autosuggestGroup = this._autosuggestMap[account.version][key];
 							let fieldId = key.split(".")[0];
 							let fieldTypeId = key.split(".")[1];
 							account.fields[fieldId].forEach(field => {
@@ -61,7 +64,7 @@ module.exports = class extends coreClass {
 			], (err) => {
 				if (err) reject(new Error(err));
 				else resolve();
-			});*/
+			});
 
 			resolve();
 		})
@@ -83,8 +86,8 @@ module.exports = class extends coreClass {
 
 	async addAutosuggestAccount(account) {
 		try { await this._validateHook(); } catch { return; }
-		Object.keys(this._autosuggestMap).forEach(key => {
-			let autosuggestGroup = this._autosuggestMap[key];
+		Object.keys(this._autosuggestMap[account.version]).forEach(key => {
+			let autosuggestGroup = this._autosuggestMap[account.version][key];
 			let fieldId = key.split(".")[0];
 			let fieldTypeId = key.split(".")[1];
 			account.fields[fieldId].forEach(field => {