From 3e0a7b3b6a97038913cfa816dea6a003a4cb3ce5 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 22 Oct 2024 09:48:53 +0200 Subject: [PATCH] fix: refs #4774 models and back --- back/model-config.json | 18 +++++++++ back/models/inkI18n.json | 22 +++++++++++ back/models/itemCategoryI18n.json | 22 +++++++++++ back/models/itemTypeI18n.json | 22 +++++++++++ back/models/originI18n.json | 22 +++++++++++ back/models/stateI18n.json | 22 +++++++++++ back/models/tagI18n.json | 22 +++++++++++ .../methods/application/getI18nTables.js | 37 +++++++++++++++++++ loopback/common/models/application.js | 1 + 9 files changed, 188 insertions(+) create mode 100644 back/models/inkI18n.json create mode 100644 back/models/itemCategoryI18n.json create mode 100644 back/models/itemTypeI18n.json create mode 100644 back/models/originI18n.json create mode 100644 back/models/stateI18n.json create mode 100644 back/models/tagI18n.json create mode 100644 loopback/common/methods/application/getI18nTables.js diff --git a/back/model-config.json b/back/model-config.json index eda9114ac..851ae2505 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -213,5 +213,23 @@ }, "CompanyI18n": { "dataSource": "vn" + }, + "ItemTypeI18n": { + "dataSource": "vn" + }, + "InkI18n": { + "dataSource": "vn" + }, + "OriginI18n": { + "dataSource": "vn" + }, + "StateI18n": { + "dataSource": "vn" + }, + "TagI18n": { + "dataSource": "vn" + }, + "itemCategoryI18n": { + "dataSource": "vn" } } diff --git a/back/models/inkI18n.json b/back/models/inkI18n.json new file mode 100644 index 000000000..f808dd9f5 --- /dev/null +++ b/back/models/inkI18n.json @@ -0,0 +1,22 @@ +{ + "name": "InkI18n", + "base": "VnModel", + "options": { + "mysql": { + "table": "inkI18n" + } + }, + "properties": { + "inkFk": { + "type": "number", + "id": 1 + }, + "lang": { + "type": "string", + "id": 2 + }, + "name": { + "type": "string" + } + } +} diff --git a/back/models/itemCategoryI18n.json b/back/models/itemCategoryI18n.json new file mode 100644 index 000000000..3226c923d --- /dev/null +++ b/back/models/itemCategoryI18n.json @@ -0,0 +1,22 @@ +{ + "name": "ItemCategoryI18n", + "base": "VnModel", + "options": { + "mysql": { + "table": "itemCategoryI18n" + } + }, + "properties": { + "categoryFk": { + "type": "number", + "id": 1 + }, + "lang": { + "type": "string", + "id": 2 + }, + "name": { + "type": "string" + } + } +} diff --git a/back/models/itemTypeI18n.json b/back/models/itemTypeI18n.json new file mode 100644 index 000000000..a76cfb933 --- /dev/null +++ b/back/models/itemTypeI18n.json @@ -0,0 +1,22 @@ +{ + "name": "ItemTypeI18n", + "base": "VnModel", + "options": { + "mysql": { + "table": "itemTypeI18n" + } + }, + "properties": { + "typeFk": { + "type": "number", + "id": 1 + }, + "lang": { + "type": "string", + "id": 2 + }, + "name": { + "type": "string" + } + } +} diff --git a/back/models/originI18n.json b/back/models/originI18n.json new file mode 100644 index 000000000..a0066ab49 --- /dev/null +++ b/back/models/originI18n.json @@ -0,0 +1,22 @@ +{ + "name": "OriginI18n", + "base": "VnModel", + "options": { + "mysql": { + "table": "originI18n" + } + }, + "properties": { + "originFk": { + "type": "number", + "id": 1 + }, + "lang": { + "type": "string", + "id": 2 + }, + "name": { + "type": "string" + } + } +} diff --git a/back/models/stateI18n.json b/back/models/stateI18n.json new file mode 100644 index 000000000..b136dc9f3 --- /dev/null +++ b/back/models/stateI18n.json @@ -0,0 +1,22 @@ +{ + "name": "StateI18n", + "base": "VnModel", + "options": { + "mysql": { + "table": "stateI18n" + } + }, + "properties": { + "stateFk": { + "type": "number", + "id": 1 + }, + "lang": { + "type": "string", + "id": 2 + }, + "name": { + "type": "string" + } + } +} diff --git a/back/models/tagI18n.json b/back/models/tagI18n.json new file mode 100644 index 000000000..b1d62ed59 --- /dev/null +++ b/back/models/tagI18n.json @@ -0,0 +1,22 @@ +{ + "name": "TagI18n", + "base": "VnModel", + "options": { + "mysql": { + "table": "tagI18n" + } + }, + "properties": { + "tagFk": { + "type": "number", + "id": 1 + }, + "lang": { + "type": "string", + "id": 2 + }, + "name": { + "type": "string" + } + } +} diff --git a/loopback/common/methods/application/getI18nTables.js b/loopback/common/methods/application/getI18nTables.js new file mode 100644 index 000000000..cd00b09e2 --- /dev/null +++ b/loopback/common/methods/application/getI18nTables.js @@ -0,0 +1,37 @@ +module.exports = Self => { + Self.remoteMethod('getI18nTables', { + description: 'Return tables with name end with i18n', + accessType: 'READ', + accepts: [], + returns: { + type: 'Array', + root: true + }, + http: { + path: `/get-i18n-tables`, + verb: 'GET' + } + }); + + Self.getI18nTables = async() => { + const tables = await Self.rawSql(` + SELECT c.table_name tableName, c.column_name primaryKey + FROM information_schema.columns c + WHERE + c.table_name LIKE '%i18n' + AND c.COLUMN_KEY = 'PRI' + AND c.COLUMN_NAME <> 'lang'`); + + const columns = await Self.rawSql(` + SELECT c.table_name tableName, c.column_name field + FROM information_schema.columns c + WHERE + c.table_name LIKE '%i18n' + AND c.COLUMN_KEY <> 'PRI' + `); + + for (const column of columns) + tables.find(t => t.tableName == column.tableName).field = column.field; + return tables; + }; +}; diff --git a/loopback/common/models/application.js b/loopback/common/models/application.js index 80c58ddc1..38e58d5ee 100644 --- a/loopback/common/models/application.js +++ b/loopback/common/models/application.js @@ -5,4 +5,5 @@ module.exports = function(Self) { require('../methods/application/executeProc')(Self); require('../methods/application/executeFunc')(Self); require('../methods/application/getEnumValues')(Self); + require('../methods/application/getI18nTables')(Self); };