From 79c42d04f9fc5a0574d36f45e7166bb77a74f48f Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 25 May 2022 14:59:28 +0200 Subject: [PATCH] feat(mdb): start section --- db/changes/10470-family/00-aclMdb.sql | 14 ++++ db/changes/10470-family/delete.keep | 0 db/dump/fixtures.sql | 9 +++ docker-compose.yml | 1 + loopback/server/datasources.json | 20 +++++ .../mdbVersion/specs/filterValue.spec.js | 76 +++++++++++++++++++ modules/mdb/back/methods/mdbVersion/upload.js | 50 ++++++++++++ modules/mdb/back/model-config.json | 11 +++ modules/mdb/back/models/mdb-container.json | 10 +++ modules/mdb/back/models/mdbBranch.json | 16 ++++ modules/mdb/back/models/mdbVersion.js | 3 + modules/mdb/back/models/mdbVersion.json | 25 ++++++ 12 files changed, 235 insertions(+) create mode 100644 db/changes/10470-family/00-aclMdb.sql delete mode 100644 db/changes/10470-family/delete.keep create mode 100644 modules/mdb/back/methods/mdbVersion/specs/filterValue.spec.js create mode 100644 modules/mdb/back/methods/mdbVersion/upload.js create mode 100644 modules/mdb/back/model-config.json create mode 100644 modules/mdb/back/models/mdb-container.json create mode 100644 modules/mdb/back/models/mdbBranch.json create mode 100644 modules/mdb/back/models/mdbVersion.js create mode 100644 modules/mdb/back/models/mdbVersion.json diff --git a/db/changes/10470-family/00-aclMdb.sql b/db/changes/10470-family/00-aclMdb.sql new file mode 100644 index 000000000..e14fa3daa --- /dev/null +++ b/db/changes/10470-family/00-aclMdb.sql @@ -0,0 +1,14 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES('MdbVersion', '*', '*', 'ALLOW', 'ROLE', 'developer'); + +CREATE TABLE `vn`.`mdbBranch` ( + `name` VARCHAR(255), + PRIMARY KEY(`name`) +); + +CREATE TABLE `vn`.`mdbVersion` ( + `app` VARCHAR(255) NOT NULL, + `branchFk` VARCHAR(255) NOT NULL, + `version` INT, + CONSTRAINT `mdbVersion_branchFk` FOREIGN KEY (`branchFk`) REFERENCES `vn`.`mdbBranch` (`name`) ON DELETE CASCADE ON UPDATE CASCADE +); diff --git a/db/changes/10470-family/delete.keep b/db/changes/10470-family/delete.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index c69012f41..087d66ac5 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2577,3 +2577,12 @@ INSERT INTO `vn`.`machineWorker` (`workerFk`, `machineFk`, `inTimed`, `outTimed` (1106, 2, CURDATE(), NULL), (1106, 2, DATE_ADD(CURDATE(), INTERVAL + 1 DAY), DATE_ADD(CURDATE(), INTERVAL +1 DAY)); +INSERT INTO `vn`.`mdbBranch` (`name`) + VALUES + ('test'), + ('master'); + +INSERT INTO `vn`.`mdbVersion` (`app`, `branchFk`, `version`) + VALUES + ('tpv', 'test', '1'), + ('lab', 'master', '2'); \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 1d80a4b62..4fc5dc811 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,6 +32,7 @@ services: - /mnt/appdata/pdfs:/var/lib/salix/pdfs - /mnt/appdata/dms:/var/lib/salix/dms - /mnt/appdata/image:/var/lib/salix/image + - /mnt/appdata/vn-access:/var/lib/salix/vn-access deploy: replicas: ${BACK_REPLICAS:?} placement: diff --git a/loopback/server/datasources.json b/loopback/server/datasources.json index f51beeb19..73f3a7bf0 100644 --- a/loopback/server/datasources.json +++ b/loopback/server/datasources.json @@ -98,5 +98,25 @@ "image/jpg", "video/mp4" ] + }, + "mdbStorage": { + "name": "mdbStorage", + "connector": "loopback-component-storage", + "provider": "filesystem", + "root": "./storage/mdb", + "maxFileSize": "262144000", + "allowedContentTypes": [ + "application/x-7z-compressed", + "application/x-zip-compressed", + "application/x-rar-compressed", + "application/octet-stream", + "application/pdf", + "application/zip", + "application/rar", + "multipart/x-zip", + "image/png", + "image/jpeg", + "image/jpg" + ] } } \ No newline at end of file diff --git a/modules/mdb/back/methods/mdbVersion/specs/filterValue.spec.js b/modules/mdb/back/methods/mdbVersion/specs/filterValue.spec.js new file mode 100644 index 000000000..9e5cf2da2 --- /dev/null +++ b/modules/mdb/back/methods/mdbVersion/specs/filterValue.spec.js @@ -0,0 +1,76 @@ +const models = require('vn-loopback/server/server').models; + +describe('tag filterValue()', () => { + const colorTagId = 1; + it('should return a list of color values', async() => { + const tx = await models.Item.beginTransaction({}); + const options = {transaction: tx}; + + try { + const filter = {limit: 5}; + const result = await models.Tag.filterValue(colorTagId, filter, options); + + expect(result.length).toEqual(5); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the values matching color "Blue"', async() => { + const tx = await models.Item.beginTransaction({}); + const options = {transaction: tx}; + + try { + const filter = {where: {value: 'Blue'}, limit: 5}; + const result = await models.Tag.filterValue(colorTagId, filter, options); + + expect(result.length).toEqual(2); + expect(result[0].value).toEqual('Blue'); + expect(result[1].value).toEqual('Blue/Silver'); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the values matching color "Blue/Silver"', async() => { + const tx = await models.Item.beginTransaction({}); + const options = {transaction: tx}; + + try { + const filter = {where: {value: 'Blue/Silver'}, limit: 5}; + const result = await models.Tag.filterValue(colorTagId, filter, options); + + expect(result.length).toEqual(1); + expect(result[0].value).toEqual('Blue/Silver'); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the values matching color "Silver"', async() => { + const tx = await models.Item.beginTransaction({}); + const options = {transaction: tx}; + + try { + const filter = {where: {value: 'Silver'}, limit: 5}; + const result = await models.Tag.filterValue(colorTagId, filter, options); + + expect(result.length).toEqual(2); + expect(result[0].value).toEqual('Silver'); + expect(result[1].value).toEqual('Blue/Silver'); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/mdb/back/methods/mdbVersion/upload.js b/modules/mdb/back/methods/mdbVersion/upload.js new file mode 100644 index 000000000..96b8347b2 --- /dev/null +++ b/modules/mdb/back/methods/mdbVersion/upload.js @@ -0,0 +1,50 @@ +module.exports = Self => { + Self.remoteMethodCtx('upload', { + description: 'Returns a list of tag values', + accepts: [ + { + arg: 'appName', + type: 'string', + required: true, + description: 'The app name' + }, + { + arg: 'newVersion', + type: 'number', + required: true, + description: `The new version number` + }, + { + arg: 'branch', + type: 'string', + required: true, + description: `The branch name` + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/upload`, + verb: 'POST' + } + }); + + Self.upload = async(ctx, appName, newVersion, branch, options) => { + const models = Self.app.models; + const myOptions = {}; + + const moduleFile = ctx.req; + if (!moduleFile) return; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const newMdb = await models.mdbVersion.create({ + app: appName, + version: newVersion, + branchFk: branch + }, myOptions); + }; +}; diff --git a/modules/mdb/back/model-config.json b/modules/mdb/back/model-config.json new file mode 100644 index 000000000..fbb7e1a33 --- /dev/null +++ b/modules/mdb/back/model-config.json @@ -0,0 +1,11 @@ +{ + "MdbBranch": { + "dataSource": "vn" + }, + "MdbVersion": { + "dataSource": "vn" + }, + "MdbContainer": { + "dataSource": "mdbStorage" + } +} diff --git a/modules/mdb/back/models/mdb-container.json b/modules/mdb/back/models/mdb-container.json new file mode 100644 index 000000000..9d8052d80 --- /dev/null +++ b/modules/mdb/back/models/mdb-container.json @@ -0,0 +1,10 @@ +{ + "name": "MdbContainer", + "base": "Container", + "acls": [{ + "accessType": "*", + "principalType": "ROLE", + "principalId": "developer", + "permission": "ALLOW" + }] +} \ No newline at end of file diff --git a/modules/mdb/back/models/mdbBranch.json b/modules/mdb/back/models/mdbBranch.json new file mode 100644 index 000000000..486dfaf25 --- /dev/null +++ b/modules/mdb/back/models/mdbBranch.json @@ -0,0 +1,16 @@ +{ + "name": "MdbBranch", + "base": "VnModel", + "options": { + "mysql": { + "table": "mdbBranch" + } + }, + "properties": { + "name": { + "id": true, + "type": "string", + "description": "Identifier" + } + } +} \ No newline at end of file diff --git a/modules/mdb/back/models/mdbVersion.js b/modules/mdb/back/models/mdbVersion.js new file mode 100644 index 000000000..b36ee2a60 --- /dev/null +++ b/modules/mdb/back/models/mdbVersion.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/mdbVersion/upload')(Self); +}; diff --git a/modules/mdb/back/models/mdbVersion.json b/modules/mdb/back/models/mdbVersion.json new file mode 100644 index 000000000..dc17531d6 --- /dev/null +++ b/modules/mdb/back/models/mdbVersion.json @@ -0,0 +1,25 @@ +{ + "name": "MdbVersion", + "base": "VnModel", + "options": { + "mysql": { + "table": "mdbVersion" + } + }, + "properties": { + "app": { + "type": "string", + "description": "The app name" + }, + "version": { + "type": "number" + } + }, + "relations": { + "branch": { + "type": "belongsTo", + "model": "MdbBranch", + "foreignKey": "name" + } + } +} \ No newline at end of file