From d2512271076660ec8694643323721efe360594cd Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Wed, 7 Feb 2018 13:26:21 +0100 Subject: [PATCH 01/10] changes in logic address-edit --- client/client/src/address-edit/address-edit.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/client/src/address-edit/address-edit.js b/client/client/src/address-edit/address-edit.js index 90009cbe8..7cfc8bd06 100644 --- a/client/client/src/address-edit/address-edit.js +++ b/client/client/src/address-edit/address-edit.js @@ -80,12 +80,13 @@ export default class Controller { let observation = this.observations[i]; let isNewObservation = observation.id === undefined; - if (types.indexOf(observation.observationTypeFk) !== -1) { + if (observation.observationTypeFk && types.indexOf(observation.observationTypeFk) !== -1) { repeatedTypes = true; break; } - types.push(observation.observationTypeFk); + if (observation.observationTypeFk) + types.push(observation.observationTypeFk); if (isNewObservation && observation.observationTypeFk && observation.description) { observationsObj.create.push(observation); From de9f7a5545151b15875360b655165c130f9b9e34 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Wed, 7 Feb 2018 13:48:55 +0100 Subject: [PATCH 02/10] item history --- client/item/src/history/item-history.html | 5 +-- services/item/common/methods/item/getLog.js | 34 ++++++-------------- services/item/common/models/itemLog.js | 3 ++ services/item/common/models/itemLog.json | 35 +++++++++++++++++++++ services/item/server/model-config.json | 3 ++ services_tests.js | 1 - 6 files changed, 52 insertions(+), 29 deletions(-) create mode 100644 services/item/common/models/itemLog.js create mode 100644 services/item/common/models/itemLog.json diff --git a/client/item/src/history/item-history.html b/client/item/src/history/item-history.html index 1a5a65483..fe1c1faf7 100644 --- a/client/item/src/history/item-history.html +++ b/client/item/src/history/item-history.html @@ -1,5 +1,4 @@ - - + Item history @@ -22,12 +21,10 @@ {{::itemLog.description}} - No results - diff --git a/services/item/common/methods/item/getLog.js b/services/item/common/methods/item/getLog.js index 50d563c08..3b214e5c8 100644 --- a/services/item/common/methods/item/getLog.js +++ b/services/item/common/methods/item/getLog.js @@ -1,27 +1,13 @@ module.exports = Self => { - Self.remoteMethod('itemLog', { - description: 'Returns the item changes log', - accessType: 'READ', - accepts: [{ - arg: 'id', - type: 'number', - required: true, - description: 'The item id', - http: {source: 'path'} - }], - returns: { - arg: 'data', - type: ['Object'], - root: true - }, - http: { - path: `/:id/itemLog`, - verb: 'get' - } - }); + Self.installMethod('getLog', filterParams); - Self.itemLog = itemFk => { - let query = `SELECT * FROM vn.itemLog WHERE itemFk = ?`; - return Self.rawSql(query, [itemFk]); - }; + function filterParams(params) { + return { + where: { + itemFk: params.itemFk + }, + skip: (params.page - 1) * params.size, + limit: params.size + }; + } }; diff --git a/services/item/common/models/itemLog.js b/services/item/common/models/itemLog.js new file mode 100644 index 000000000..248cc6abd --- /dev/null +++ b/services/item/common/models/itemLog.js @@ -0,0 +1,3 @@ +module.exports = function(Self) { + require('../methods/item/getLog.js')(Self); +}; diff --git a/services/item/common/models/itemLog.json b/services/item/common/models/itemLog.json new file mode 100644 index 000000000..63777113f --- /dev/null +++ b/services/item/common/models/itemLog.json @@ -0,0 +1,35 @@ +{ + "name": "ItemLog", + "base": "VnModel", + "options": { + "mysql": { + "table": "itemLog", + "database": "vn" + } + }, + "properties": { + "id": { + "type": "Number", + "id": true, + "description": "Identifier" + }, + "creationDate": { + "type": "Date" + }, + "description": { + "type": "String" + } + }, + "relations": { + "originFk": { + "type": "belongsTo", + "model": "Origin", + "foreignKey": "originFk" + }, + "userFk": { + "type": "belongsTo", + "model": "User", + "foreignKey": "userFk" + } + } + } diff --git a/services/item/server/model-config.json b/services/item/server/model-config.json index f001fcba1..09eed1735 100644 --- a/services/item/server/model-config.json +++ b/services/item/server/model-config.json @@ -34,5 +34,8 @@ }, "Tag": { "dataSource": "vn" + }, + "ItemLog": { + "dataSource": "vn" } } diff --git a/services_tests.js b/services_tests.js index 0ce869843..068f8c8f2 100644 --- a/services_tests.js +++ b/services_tests.js @@ -36,4 +36,3 @@ jasmine.addReporter(new SpecReporter({ })); jasmine.execute(); - From c61748ec95f98a00271f9cc4878d5794f17bea93 Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Wed, 7 Feb 2018 14:37:26 +0100 Subject: [PATCH 03/10] Dockerfile Services --- services/auth/Dockerfile | 11 +++++++++++ services/client/Dockerfile | 12 ++++++++++++ services/item/Dockerfile | 12 ++++++++++++ services/mailer/Dockerfile | 11 +++++++++++ services/print/Dockerfile | 11 +++++++++++ services/production/Dockerfile | 11 +++++++++++ services/route/Dockerfile | 11 +++++++++++ services/salix/Dockerfile | 11 +++++++++++ 8 files changed, 90 insertions(+) create mode 100644 services/auth/Dockerfile create mode 100644 services/client/Dockerfile create mode 100644 services/item/Dockerfile create mode 100644 services/mailer/Dockerfile create mode 100644 services/print/Dockerfile create mode 100644 services/production/Dockerfile create mode 100644 services/route/Dockerfile create mode 100644 services/salix/Dockerfile diff --git a/services/auth/Dockerfile b/services/auth/Dockerfile new file mode 100644 index 000000000..3264a1c0a --- /dev/null +++ b/services/auth/Dockerfile @@ -0,0 +1,11 @@ +FROM node:8.9.4 + +COPY . /app +COPY ../loopback /loopback + +WORKDIR /app + +RUN npm install +RUN npm -g install pm2 + +CMD ["pm2-docker", "./server/server.js"] diff --git a/services/client/Dockerfile b/services/client/Dockerfile new file mode 100644 index 000000000..b1197d171 --- /dev/null +++ b/services/client/Dockerfile @@ -0,0 +1,12 @@ +FROM node:8.9.4 + +COPY . /app +COPY ../loopback /loopback + +WORKDIR /app + +RUN npm install +RUN npm -g install pm2 + +CMD ["pm2-docker", "./server/server.js"] + diff --git a/services/item/Dockerfile b/services/item/Dockerfile new file mode 100644 index 000000000..b1197d171 --- /dev/null +++ b/services/item/Dockerfile @@ -0,0 +1,12 @@ +FROM node:8.9.4 + +COPY . /app +COPY ../loopback /loopback + +WORKDIR /app + +RUN npm install +RUN npm -g install pm2 + +CMD ["pm2-docker", "./server/server.js"] + diff --git a/services/mailer/Dockerfile b/services/mailer/Dockerfile new file mode 100644 index 000000000..3264a1c0a --- /dev/null +++ b/services/mailer/Dockerfile @@ -0,0 +1,11 @@ +FROM node:8.9.4 + +COPY . /app +COPY ../loopback /loopback + +WORKDIR /app + +RUN npm install +RUN npm -g install pm2 + +CMD ["pm2-docker", "./server/server.js"] diff --git a/services/print/Dockerfile b/services/print/Dockerfile new file mode 100644 index 000000000..3264a1c0a --- /dev/null +++ b/services/print/Dockerfile @@ -0,0 +1,11 @@ +FROM node:8.9.4 + +COPY . /app +COPY ../loopback /loopback + +WORKDIR /app + +RUN npm install +RUN npm -g install pm2 + +CMD ["pm2-docker", "./server/server.js"] diff --git a/services/production/Dockerfile b/services/production/Dockerfile new file mode 100644 index 000000000..3264a1c0a --- /dev/null +++ b/services/production/Dockerfile @@ -0,0 +1,11 @@ +FROM node:8.9.4 + +COPY . /app +COPY ../loopback /loopback + +WORKDIR /app + +RUN npm install +RUN npm -g install pm2 + +CMD ["pm2-docker", "./server/server.js"] diff --git a/services/route/Dockerfile b/services/route/Dockerfile new file mode 100644 index 000000000..3264a1c0a --- /dev/null +++ b/services/route/Dockerfile @@ -0,0 +1,11 @@ +FROM node:8.9.4 + +COPY . /app +COPY ../loopback /loopback + +WORKDIR /app + +RUN npm install +RUN npm -g install pm2 + +CMD ["pm2-docker", "./server/server.js"] diff --git a/services/salix/Dockerfile b/services/salix/Dockerfile new file mode 100644 index 000000000..3264a1c0a --- /dev/null +++ b/services/salix/Dockerfile @@ -0,0 +1,11 @@ +FROM node:8.9.4 + +COPY . /app +COPY ../loopback /loopback + +WORKDIR /app + +RUN npm install +RUN npm -g install pm2 + +CMD ["pm2-docker", "./server/server.js"] From 249a622e2de31bd32b55e578a173874187cee520 Mon Sep 17 00:00:00 2001 From: "SAMBA\\bernat" Date: Wed, 7 Feb 2018 14:45:04 +0100 Subject: [PATCH 04/10] update fixtures --- services/db/02-fixtures.sql | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/services/db/02-fixtures.sql b/services/db/02-fixtures.sql index d6bd1acae..3b51c91fc 100644 --- a/services/db/02-fixtures.sql +++ b/services/db/02-fixtures.sql @@ -399,7 +399,7 @@ INSERT INTO `salix`.`Address`(`id`, `consignee`, `street`, `city`, `postcode`, ` (107, 'Hank Pym', 'Your pocket', 'Silla', 46460, 1, NULL, NULL, 1, 1, 7, 2, NULL, NULL, 0), (108, 'Charles Xavier', 'Cerebro', 'Silla', 46460, 1, NULL, NULL, 1, 1, 8, 2, NULL, NULL, 0), (109, 'Bruce Banner', 'Somewhere in Thailand', 'Silla', 46460, 1, NULL, NULL, 1, 1, 9, 2, NULL, NULL, 0), - (1010,'Jessica Jones', 'Luke Cages Bar', 'Silla', 46460, 1, NULL, NULL, 1, 1, 10, 2, NULL, NULL, 0); + (110,'Jessica Jones', 'Luke Cages Bar', 'Silla', 46460, 1, NULL, NULL, 1, 1, 10, 2, NULL, NULL, 0); INSERT INTO `salix`.`ClientCredit`(`id`, `clientFk`, `employeeFk`, `amount`, `created`) VALUES @@ -475,16 +475,16 @@ INSERT INTO `vn2008`.`empresa`(`id`, `abbreviation`, `registro`, `gerente_id`, ` INSERT INTO `vn`.`ticket`(`id`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `clientFk`,`nickname`, `addressFk`) VALUES - (1, 1, 1, NULL, CURDATE(), 1, 'Batman', 1), - (2, 1, 1, NULL, CURDATE(), 1, 'Spider-Man', 2), - (3, 2, 2, NULL, CURDATE(), 2, 'Super-Man', 3), - (4, 2, 2, NULL, CURDATE(), 2, 'Iron-Man', 4), - (5, 3, 3, NULL, CURDATE(), 3, 'Magneto', 5), - (6, 3, 3, NULL, CURDATE(), 3, 'Legion', 6), - (7, 4, 4, NULL, CURDATE(), 4, 'Ant-Man', 7), - (8, 4, 4, NULL, CURDATE(), 4, 'Professor X', 8), - (9, 5, 5, NULL, CURDATE(), 5, 'Hulk', 9), - (10, 6, 5, NULL, CURDATE(), 5, 'Jessica Jones', 10); + (1, 1, 1, NULL, CURDATE(), 1, 'Batman', 101), + (2, 1, 1, NULL, CURDATE(), 1, 'Spider-Man', 102), + (3, 2, 2, NULL, CURDATE(), 2, 'Super-Man', 103), + (4, 2, 2, NULL, CURDATE(), 2, 'Iron-Man', 104), + (5, 3, 3, NULL, CURDATE(), 3, 'Magneto', 105), + (6, 3, 3, NULL, CURDATE(), 3, 'Legion', 106), + (7, 4, 4, NULL, CURDATE(), 4, 'Ant-Man', 107), + (8, 4, 4, NULL, CURDATE(), 4, 'Professor X', 108), + (9, 5, 5, NULL, CURDATE(), 5, 'Hulk', 109), + (10, 6, 5, NULL, CURDATE(), 5, 'Jessica Jones', 110); INSERT INTO `vn`.`ticketTracking`(`id`, `ticketFk`, `stateFk`, `workerFk`, `created`) VALUES From 7b7464ecc1186cdee2126785680a754264d10499 Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Wed, 7 Feb 2018 14:45:39 +0100 Subject: [PATCH 05/10] Docker context --- gulpfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index 28f1e37f6..3e36a02c2 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -128,7 +128,7 @@ gulp.task('docker-compose', async () => { container_name: `\${BRANCH_NAME}-${service.name}`, image: `${service.name}:\${TAG}`, build: { - context: `./services/${service.name}`, + context: `./services`, dockerfile: dockerFile }, ports: [`${defaultPort}:${service.port}`] From 87d423fd52f25b257fa5be650e711ae3352895c2 Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Wed, 7 Feb 2018 14:47:08 +0100 Subject: [PATCH 06/10] new testing in address-edit --- .../client/src/address-edit/address-edit.js | 2 +- .../src/address-edit/address-edit.spec.js | 41 ++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/client/client/src/address-edit/address-edit.js b/client/client/src/address-edit/address-edit.js index 7cfc8bd06..3046b2733 100644 --- a/client/client/src/address-edit/address-edit.js +++ b/client/client/src/address-edit/address-edit.js @@ -61,7 +61,7 @@ export default class Controller { } _observationsEquals(ob1, ob2) { - return ob1.observationTypeFk === ob2.observationTypeFk && ob1.description === ob2.description; + return ob1.id === ob2.id && ob1.observationTypeFk === ob2.observationTypeFk && ob1.description === ob2.description; } submit() { diff --git a/client/client/src/address-edit/address-edit.spec.js b/client/client/src/address-edit/address-edit.spec.js index 18fff508f..8f14a2ec9 100644 --- a/client/client/src/address-edit/address-edit.spec.js +++ b/client/client/src/address-edit/address-edit.spec.js @@ -20,7 +20,46 @@ describe('Client', () => { })); it('should define and set address property', () => { - expect(controller.address.id).toBe(1); + expect(controller.address.id).toEqual(1); + }); + + describe('removeObservation(index)', () => { + it('should remove an observation that occupies the index given and restore showAddIcon properties', () => { + let index = 2; + controller.observations = [ + {id: 1, description: 'Spiderman rocks', showAddIcon: false}, + {id: 2, description: 'Batman sucks', showAddIcon: false}, + {id: 3, description: 'Ironman rules', showAddIcon: true} + ]; + + spyOn(controller, '_setIconAdd').and.callThrough(); + + controller.removeObservation(index); + + expect(controller._setIconAdd).toHaveBeenCalledWith(); + expect(controller.observations.length).toEqual(2); + expect(controller.observations[0].showAddIcon).toBeFalsy(); + expect(controller.observations[1].showAddIcon).toBeTruthy(); + expect(controller.observations[index]).toBe(undefined); + }); + }); + + describe('_observationsEquals', () => { + it('should return true if two observations are equals independent of control attributes', () => { + let ob1 = {id: 1, observationTypeFk: 1, description: 'Spiderman rocks', showAddIcon: true}; + let ob2 = {id: 1, observationTypeFk: 1, description: 'Spiderman rocks', showAddIcon: false}; + let equals = controller._observationsEquals(ob2, ob1); + + expect(equals).toBeTruthy(); + }); + + it('should return false if two observations are not equals independent of control attributes', () => { + let ob1 = {id: 1, observationTypeFk: 1, description: 'Spiderman rocks', showAddIcon: true}; + let ob2 = {id: 1, observationTypeFk: 1, description: 'Spiderman sucks', showAddIcon: true}; + let equals = controller._observationsEquals(ob2, ob1); + + expect(equals).toBeFalsy(); + }); }); describe('$onInit()', () => { From 2cc6dfd55353dcd8d880d47dac4cdd46502ee7ba Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Wed, 7 Feb 2018 14:48:11 +0100 Subject: [PATCH 07/10] changes in last test --- client/client/src/address-edit/address-edit.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/client/src/address-edit/address-edit.spec.js b/client/client/src/address-edit/address-edit.spec.js index 8f14a2ec9..5c41d653c 100644 --- a/client/client/src/address-edit/address-edit.spec.js +++ b/client/client/src/address-edit/address-edit.spec.js @@ -24,7 +24,7 @@ describe('Client', () => { }); describe('removeObservation(index)', () => { - it('should remove an observation that occupies the index given and restore showAddIcon properties', () => { + it('should remove an observation that occupies in the index given and restore showAddIcon properties', () => { let index = 2; controller.observations = [ {id: 1, description: 'Spiderman rocks', showAddIcon: false}, From d06ffba8b93d290f26aad288911c56aa7d630e7d Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Wed, 7 Feb 2018 15:02:16 +0100 Subject: [PATCH 08/10] gulp docker --- gulpfile.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 3e36a02c2..311aa2131 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -118,10 +118,10 @@ gulp.task('docker-compose', async () => { let services = await getServices(); for (let service of services) { - let dockerFile = `${__dirname}/Dockerfile`; + let dockerFile = `${__dirname}/${service.name}/Dockerfile`; - if (await fs.exists(`./services/${service.name}/Dockerfile`)) - dockerFile = 'Dockerfile'; + // if (await fs.exists(`./services/${service.name}/Dockerfile`)) + // dockerFile = 'Dockerfile'; composeYml.services[service.name] = { environment: ['NODE_ENV=${NODE_ENV}'], From 03faa09284d1fdfe192968a52371b92e4d5dcdd1 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Wed, 7 Feb 2018 15:06:21 +0100 Subject: [PATCH 09/10] item history functionality, awaiting for clientfilters refactor --- client/item/src/history/item-history.html | 6 +++--- services/item/common/methods/item/getLog.js | 8 +++++++- services/item/common/models/item.js | 1 - services/item/common/models/itemLog.json | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/client/item/src/history/item-history.html b/client/item/src/history/item-history.html index fe1c1faf7..3409dc04b 100644 --- a/client/item/src/history/item-history.html +++ b/client/item/src/history/item-history.html @@ -1,4 +1,4 @@ - + Item history @@ -14,8 +14,8 @@ class="list list-element text-center" pad-small-bottom ng-repeat="itemLog in index.model.instances track by itemLog.id"> - {{::itemLog.originFk}} - {{::itemLog.userFk}} + {{::itemLog.origin.name}} + {{::itemLog.user.name}} {{::itemLog.action}} {{::itemLog.creationDate | date:'dd/MM/yyyy HH:mm'}} {{::itemLog.description}} diff --git a/services/item/common/methods/item/getLog.js b/services/item/common/methods/item/getLog.js index 3b214e5c8..3c0c1e413 100644 --- a/services/item/common/methods/item/getLog.js +++ b/services/item/common/methods/item/getLog.js @@ -7,7 +7,13 @@ module.exports = Self => { itemFk: params.itemFk }, skip: (params.page - 1) * params.size, - limit: params.size + limit: params.size, + include: [{ + relation: "origin" + }, + { + relation: "user" + }] }; } }; diff --git a/services/item/common/models/item.js b/services/item/common/models/item.js index 3cbc622bd..2c193b587 100644 --- a/services/item/common/models/item.js +++ b/services/item/common/models/item.js @@ -1,6 +1,5 @@ module.exports = function(Self) { require('../methods/item/filter.js')(Self); - require('../methods/item/getLog.js')(Self); Self.validatesPresenceOf('name', {message: 'Cannot be blank'}); Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'}); diff --git a/services/item/common/models/itemLog.json b/services/item/common/models/itemLog.json index 63777113f..60a105dff 100644 --- a/services/item/common/models/itemLog.json +++ b/services/item/common/models/itemLog.json @@ -21,12 +21,12 @@ } }, "relations": { - "originFk": { + "origin": { "type": "belongsTo", "model": "Origin", "foreignKey": "originFk" }, - "userFk": { + "user": { "type": "belongsTo", "model": "User", "foreignKey": "userFk" From 433a0d1af4dc949ec00907e1a3fc07ad0c7a1003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20S=C3=A1nchez?= Date: Wed, 7 Feb 2018 15:33:43 +0100 Subject: [PATCH 10/10] services-run con posibilidad de pasar variable de entorno NODE_ENV = test --- gulpfile.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gulpfile.js b/gulpfile.js index 3e36a02c2..61c351585 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -11,6 +11,10 @@ const exec = require('child_process').exec; // Configuration const isWindows = /^win/.test(process.platform); + +if (gutil.env.NODE_ENV) + process.env.NODE_ENV = gutil.env.NODE_ENV; + const env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development'; const langs = ['es', 'en'];