From 289f588923189efaeb53e9716da99a69ccba52b8 Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 21 Jun 2019 07:41:03 +0200 Subject: [PATCH 1/3] #1550 ticket.descriptor polizon cambia estado --- modules/ticket/back/models/stowaway.js | 16 ++ .../ticket/front/descriptor/addStowaway.js | 9 +- package-lock.json | 152 +++++++++--------- package.json | 2 +- 4 files changed, 96 insertions(+), 83 deletions(-) create mode 100644 modules/ticket/back/models/stowaway.js diff --git a/modules/ticket/back/models/stowaway.js b/modules/ticket/back/models/stowaway.js new file mode 100644 index 000000000..714d823b0 --- /dev/null +++ b/modules/ticket/back/models/stowaway.js @@ -0,0 +1,16 @@ +const LoopBackContext = require('loopback-context'); +module.exports = function(Self) { + Self.observe('before save', async function(ctx) { + if (ctx.isNewInstance) { + let where = { + code: 'BOARDING' + }; + let state = await Self.app.models.State.findOne({where}); + let params = {ticketFk: ctx.instance.id, stateFk: state.id}; + const loopBackContext = LoopBackContext.getCurrentContext(); + + let httpCtx = {req: loopBackContext.active}; + await Self.app.models.TicketTracking.changeState(httpCtx, params); + } + }); +}; diff --git a/modules/ticket/front/descriptor/addStowaway.js b/modules/ticket/front/descriptor/addStowaway.js index 514d46503..ac901e751 100644 --- a/modules/ticket/front/descriptor/addStowaway.js +++ b/modules/ticket/front/descriptor/addStowaway.js @@ -1,10 +1,10 @@ import ngModule from '../module'; class Controller { - constructor($state, $scope, $http, vnApp, $translate) { + constructor($state, $, $http, vnApp, $translate) { this.vnApp = vnApp; this.$translate = $translate; - this.$scope = $scope; + this.$ = $; this.$state = $state; this.$http = $http; } @@ -22,15 +22,16 @@ class Controller { .then(() => { this.cardReload(); this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.$.addStowaway.hide(); }); } show() { - this.$scope.dialog.show(); + this.$.dialog.show(); } hide() { - this.$scope.dialog.hide(); + this.$.dialog.hide(); } } diff --git a/package-lock.json b/package-lock.json index e0846e3bb..5f0301ce8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1693,7 +1693,7 @@ }, "util": { "version": "0.10.3", - "resolved": "http://registry.npmjs.org/util/-/util-0.10.3.tgz", + "resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", "integrity": "sha1-evsa/lCAUkZInj23/g7TeTNqwPk=", "dev": true, "requires": { @@ -1971,7 +1971,7 @@ "base": { "version": "0.11.2", "resolved": "https://registry.npmjs.org/base/-/base-0.11.2.tgz", - "integrity": "sha512-5T6P4xPgpp0YDFvSWwEZ4NoE3aM4QBQXDzmVbraCkFj8zHM+mba8SyqB5DbZWyR7mYHo6Y7BdQo3MoA4m0TeQg==", + "integrity": "sha1-e95c7RRbbVUakNuH+DxVi060io8=", "dev": true, "requires": { "cache-base": "^1.0.1", @@ -2563,7 +2563,7 @@ "cache-base": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/cache-base/-/cache-base-1.0.1.tgz", - "integrity": "sha512-AKcdTnFSWATd5/GCPRxr2ChwIJ85CeyrEyjRHlKxQ56d4XJMGym0uAiKn0xbLOGOl3+yRpOTi484dVCEc5AUzQ==", + "integrity": "sha1-Cn9GQWgxyLZi7jb+TnxZ129marI=", "dev": true, "requires": { "collection-visit": "^1.0.0", @@ -2738,7 +2738,7 @@ "class-utils": { "version": "0.3.6", "resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz", - "integrity": "sha512-qOhPa/Fj7s6TY8H8esGu5QNpMMQxz79h+urzrNYN6mn+9BnxlDGf5QZ+XeCDsxSjPqsSR56XOZOJmpeurnLMeg==", + "integrity": "sha1-+TNprouafOAv1B+q0MqDAzGQxGM=", "dev": true, "requires": { "arr-union": "^3.1.0", @@ -2898,7 +2898,7 @@ }, "string_decoder": { "version": "1.1.1", - "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", "dev": true, "requires": { @@ -3435,13 +3435,13 @@ "dependencies": { "jsesc": { "version": "0.5.0", - "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", + "resolved": "http://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", "integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=", "dev": true }, "regexpu-core": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-1.0.0.tgz", + "resolved": "http://registry.npmjs.org/regexpu-core/-/regexpu-core-1.0.0.tgz", "integrity": "sha1-hqdj9Y7k18L2sQLkdkBQ3n7ZDGs=", "dev": true, "requires": { @@ -3452,13 +3452,13 @@ }, "regjsgen": { "version": "0.2.0", - "resolved": "https://registry.npmjs.org/regjsgen/-/regjsgen-0.2.0.tgz", + "resolved": "http://registry.npmjs.org/regjsgen/-/regjsgen-0.2.0.tgz", "integrity": "sha1-bAFq3qxVT3WCP+N6wFuS1aTtsfc=", "dev": true }, "regjsparser": { "version": "0.1.5", - "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.1.5.tgz", + "resolved": "http://registry.npmjs.org/regjsparser/-/regjsparser-0.1.5.tgz", "integrity": "sha1-fuj4Tcb6eS0/0K4ijSS9lJ6tIFw=", "dev": true, "requires": { @@ -4103,7 +4103,7 @@ "dependencies": { "fs-extra": { "version": "0.30.0", - "resolved": "http://registry.npmjs.org/fs-extra/-/fs-extra-0.30.0.tgz", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-0.30.0.tgz", "integrity": "sha1-8jP/zAjU2n1DLapEl3aYnbHfk/A=", "dev": true, "requires": { @@ -5113,7 +5113,7 @@ }, "file-loader": { "version": "1.1.11", - "resolved": "http://registry.npmjs.org/file-loader/-/file-loader-1.1.11.tgz", + "resolved": "https://registry.npmjs.org/file-loader/-/file-loader-1.1.11.tgz", "integrity": "sha512-TGR4HU7HUsGg6GCOPJnFk06RhWgEWFLAGWiT6rcD+GRC2keU3s9RGJ+b3Z6/U73jwwNb2gKLJ7YCrp+jvU4ALg==", "dev": true, "requires": { @@ -6252,7 +6252,7 @@ "global-modules": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/global-modules/-/global-modules-1.0.0.tgz", - "integrity": "sha512-sKzpEkf11GpOFuw0Zzjzmt4B4UZwjOcG757PPvrfhxcLFbq0wpsgpOqxpxtxFiCG4DtG93M6XRVbF2oGdev7bg==", + "integrity": "sha1-bXcPDrUjrHgWTXK15xqIdyZcw+o=", "dev": true, "requires": { "global-prefix": "^1.0.1", @@ -6899,7 +6899,7 @@ "dependencies": { "es6-promise": { "version": "3.3.1", - "resolved": "http://registry.npmjs.org/es6-promise/-/es6-promise-3.3.1.tgz", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.3.1.tgz", "integrity": "sha1-oIzd6EzNvzTQJ6FFG8kdS80ophM=", "dev": true }, @@ -7943,7 +7943,7 @@ "is-plain-object": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", - "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==", + "integrity": "sha1-LBY7P6+xtgbZ0Xko8FwqHDjgdnc=", "dev": true, "requires": { "isobject": "^3.0.1" @@ -8161,7 +8161,7 @@ "jasmine-spec-reporter": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/jasmine-spec-reporter/-/jasmine-spec-reporter-4.2.1.tgz", - "integrity": "sha512-FZBoZu7VE5nR7Nilzy+Np8KuVIOxF4oXDPDknehCYBDE080EnlPu0afdZNmpGDBRCUBv3mj5qgqCRmk6W/K8vg==", + "integrity": "sha1-HWMq7ANBZwrTJPkrqEtLMrNeniI=", "dev": true, "requires": { "colors": "1.1.2" @@ -8930,9 +8930,9 @@ "dev": true }, "loopback": { - "version": "3.25.0", - "resolved": "https://registry.npmjs.org/loopback/-/loopback-3.25.0.tgz", - "integrity": "sha512-898BSxoY2BQMHTUYkfBrfAN0T1XxxEWKW0cQY08oXmU/Rh9I+bSPjokg5aRO9Aa+OHqp3R+BrVBYmTUuWFrYfQ==", + "version": "3.26.0", + "resolved": "https://registry.npmjs.org/loopback/-/loopback-3.26.0.tgz", + "integrity": "sha512-QDREGpTTjLwMgteSIajFXMklW4slbVO5PvY2bPXBn3EUfPzmWXfaDiSlzwbbRbw+cyMUAr2EorL1r0+IsIslWg==", "requires": { "async": "^2.0.1", "bcryptjs": "^2.1.0", @@ -9002,6 +9002,14 @@ "pump": "^3.0.0" } }, + "globalize": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/globalize/-/globalize-1.4.2.tgz", + "integrity": "sha512-IfKeYI5mAITBmT5EnH8kSQB5uGson4Fkj2XtTpyEbIS7IHNfLHoeTyLJ6tfjiKC6cJXng3IhVurDk5C7ORqFhQ==", + "requires": { + "cldrjs": "^0.5.0" + } + }, "invert-kv": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz", @@ -9016,19 +9024,24 @@ } }, "mem": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/mem/-/mem-4.1.0.tgz", - "integrity": "sha512-I5u6Q1x7wxO0kdOpYBB28xueHADYps5uty/zg936CiG8NTe5sJL8EjrCuLneuDW3PlMdZBGDIn8BirEVdovZvg==", + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/mem/-/mem-4.3.0.tgz", + "integrity": "sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w==", "requires": { "map-age-cleaner": "^0.1.1", - "mimic-fn": "^1.0.0", + "mimic-fn": "^2.0.0", "p-is-promise": "^2.0.0" } }, + "mimic-fn": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", + "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==" + }, "ms": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "os-locale": { "version": "3.1.0", @@ -9041,22 +9054,22 @@ } }, "p-is-promise": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.0.0.tgz", - "integrity": "sha512-pzQPhYMCAgLAKPWD2jC3Se9fEfrD9npNos0y150EeqZll7akhEgGhTW/slB6lHku8AvYGiJ+YJ5hfHKePPgFWg==" + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.1.0.tgz", + "integrity": "sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg==" }, "strong-globalize": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/strong-globalize/-/strong-globalize-4.1.2.tgz", - "integrity": "sha512-2ks3/fuQy4B/AQDTAaEvTXYSqH4TWrv9VGlbZ4YujzijEJbIWbptF/9dO13duv87aRhWdM5ABEiTy7ZmnmBhdQ==", + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/strong-globalize/-/strong-globalize-4.1.3.tgz", + "integrity": "sha512-SJegV7w5D4AodEspZJtJ7rls3fmi+Zc0PdyJCqBsg4RN9B8TC80/uAI2fikC+s1Jp9FLvr2vDX8f0Fqc62M4OA==", "requires": { "accept-language": "^3.0.18", - "debug": "^4.0.1", - "globalize": "^1.3.0", + "debug": "^4.1.1", + "globalize": "^1.4.2", "lodash": "^4.17.4", "md5": "^2.2.1", "mkdirp": "^0.5.1", - "os-locale": "^3.0.1", + "os-locale": "^3.1.0", "yamljs": "^0.3.0" }, "dependencies": { @@ -9849,9 +9862,9 @@ } }, "ms": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" } } }, @@ -10414,7 +10427,7 @@ }, "minimist": { "version": "1.2.0", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" }, "minstache": { @@ -10956,7 +10969,7 @@ "dependencies": { "jsesc": { "version": "0.5.0", - "resolved": "http://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", "integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=", "dev": true } @@ -11586,8 +11599,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -11615,7 +11627,6 @@ "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -11630,8 +11641,7 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", @@ -11642,8 +11652,7 @@ "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -11760,8 +11769,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -11773,7 +11781,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -11788,7 +11795,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -11796,14 +11802,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -11822,7 +11826,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -11903,8 +11906,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -11916,7 +11918,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -12002,8 +12003,7 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -12039,7 +12039,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -12059,7 +12058,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -12103,14 +12101,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, @@ -12409,7 +12405,7 @@ "dependencies": { "minimist": { "version": "0.0.10", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=", "dev": true }, @@ -13034,7 +13030,7 @@ }, "pretty-bytes": { "version": "1.0.4", - "resolved": "http://registry.npmjs.org/pretty-bytes/-/pretty-bytes-1.0.4.tgz", + "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-1.0.4.tgz", "integrity": "sha1-CiLoIQYJrTVUL4yNXSFZr/B1HIQ=", "dev": true, "requires": { @@ -13123,7 +13119,7 @@ }, "through2": { "version": "0.2.3", - "resolved": "http://registry.npmjs.org/through2/-/through2-0.2.3.tgz", + "resolved": "https://registry.npmjs.org/through2/-/through2-0.2.3.tgz", "integrity": "sha1-6zKE2k6jEbbMis42U3SKUqvyWj8=", "dev": true, "requires": { @@ -14019,7 +14015,7 @@ }, "safe-regex": { "version": "1.1.0", - "resolved": "http://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz", + "resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz", "integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=", "dev": true, "requires": { @@ -14144,7 +14140,7 @@ "dependencies": { "source-map": { "version": "0.4.4", - "resolved": "http://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz", "integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=", "dev": true, "requires": { @@ -14284,7 +14280,7 @@ "set-value": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-value/-/set-value-2.0.0.tgz", - "integrity": "sha512-hw0yxk9GT/Hr5yJEYnHNKYXkIA8mVJgd9ditYZCe16ZczcaELYYcfvaXesNACk2O8O0nTiPQcQhGUQj8JLzeeg==", + "integrity": "sha1-ca5KiPD+77v1LR6mBPP7MV67YnQ=", "dev": true, "requires": { "extend-shallow": "^2.0.1", @@ -14481,7 +14477,7 @@ "snapdragon-node": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/snapdragon-node/-/snapdragon-node-2.1.1.tgz", - "integrity": "sha512-O27l4xaMYt/RSQ5TR3vpWCAB5Kb/czIcqUFOM/C4fYcLnbZUc1PkjTAMjof2pBWaSTwOUd6qUHcFGVGj7aIwnw==", + "integrity": "sha1-bBdfhv8UvbByRWPo88GwIaKGhTs=", "dev": true, "requires": { "define-property": "^1.0.0", @@ -14532,7 +14528,7 @@ "snapdragon-util": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/snapdragon-util/-/snapdragon-util-3.0.1.tgz", - "integrity": "sha512-mbKkMdQKsjX4BAL4bRYTj21edOf8cN7XHdYUJEe+Zn99hVEYcMvKPct1IqNe7+AZPirn8BCDOQBHQZknqmKlZQ==", + "integrity": "sha1-+VZHlIbyrNeXAGk/b3uAXkWrVuI=", "dev": true, "requires": { "kind-of": "^3.2.0" @@ -14896,7 +14892,7 @@ "split-string": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/split-string/-/split-string-3.1.0.tgz", - "integrity": "sha512-NzNVhJDYpwceVVii8/Hu6DKfD2G+NrQHlS/V/qgv763EYudVwEcMQNxd2lh+0VrUByXN/oJkl5grOhYWvQUYiw==", + "integrity": "sha1-fLCd2jqGWFcFxks5pkZgOGguj+I=", "dev": true, "requires": { "extend-shallow": "^3.0.0" @@ -15088,7 +15084,7 @@ }, "string_decoder": { "version": "1.1.1", - "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", "dev": true, "requires": { @@ -16480,7 +16476,7 @@ "useragent": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/useragent/-/useragent-2.3.0.tgz", - "integrity": "sha512-4AoH4pxuSvHCjqLO04sU6U/uE65BYza8l/KKBS0b0hnUPWi+cQ2BpeTEwejCSx9SPV5/U03nniDTrWx5NrmKdw==", + "integrity": "sha1-IX+UOtVAyyEoZYqyP8lg9qiMmXI=", "dev": true, "requires": { "lru-cache": "4.1.x", @@ -17217,7 +17213,7 @@ }, "globby": { "version": "6.1.0", - "resolved": "http://registry.npmjs.org/globby/-/globby-6.1.0.tgz", + "resolved": "https://registry.npmjs.org/globby/-/globby-6.1.0.tgz", "integrity": "sha1-9abXDoOV4hyFj7BInWTfAkJNUGw=", "dev": true, "requires": { @@ -17230,7 +17226,7 @@ "dependencies": { "pify": { "version": "2.3.0", - "resolved": "http://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", "dev": true } diff --git a/package.json b/package.json index 5d0315e59..cb6806bc6 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "fs-extra": "^5.0.0", "helmet": "^3.15.1", "i18n": "^0.8.3", - "loopback": "^3.25.0", + "loopback": "^3.26.0", "loopback-boot": "^2.27.1", "loopback-component-explorer": "^6.3.1", "loopback-component-storage": "^3.6.1", From dae43bb9b0a6ecf2c16d7335c06e3616a46c860c Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 21 Jun 2019 08:26:59 +0200 Subject: [PATCH 2/3] transactions refactor #1546 --- loopback/locale/es.json | 2 +- .../importToNewRefundTicket.js | 198 ++++++++++-------- .../back/methods/claim/createFromSales.js | 30 +-- modules/item/back/methods/item/clone.js | 39 ++-- .../back/methods/item/specs/clone.spec.js | 2 +- 5 files changed, 142 insertions(+), 129 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 68eb76d15..6df1cb074 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -89,7 +89,7 @@ "Please select at least one sale": "Por favor selecciona al menos una linea", "All sales must belong to the same ticket": "Todas las lineas deben pertenecer al mismo ticket", "NO_ZONE_FOR_THIS_PARAMETERS": "Para este día no hay ninguna zona configurada", - "That item doesn't exists": "El artículo no existe", + "This item doesn't exists": "El artículo no existe", "NOT_ZONE_WITH_THIS_PARAMETERS": "Para este día no hay ninguna zona configurada", "Extension format is invalid": "El formato de la extensión es inválido" } \ No newline at end of file diff --git a/modules/claim/back/methods/claim-beginning/importToNewRefundTicket.js b/modules/claim/back/methods/claim-beginning/importToNewRefundTicket.js index 379eec368..45a9ec0d6 100644 --- a/modules/claim/back/methods/claim-beginning/importToNewRefundTicket.js +++ b/modules/claim/back/methods/claim-beginning/importToNewRefundTicket.js @@ -19,12 +19,112 @@ module.exports = Self => { } }); - async function addSalesToTicket(salesToRefund, ticketFk, options) { + Self.importToNewRefundTicket = async(ctx, id) => { + const models = Self.app.models; + const token = ctx.req.accessToken; + const userId = token.userId; + const tx = await Self.beginTransaction({}); + const filter = { + where: {id: id}, + include: [ + { + relation: 'ticket', + scope: { + fields: ['id', 'clientFk', 'warehouseFk', 'companyFk', 'addressFk'] + } + } + ] + }; + const salesFilter = { + where: {claimFk: id}, + include: [ + { + relation: 'sale', + scope: { + fields: [ + 'id', + 'itemFk', + 'concept', + 'price', + 'discount', + 'reserved', + 'isPicked', + 'created', + 'priceFixed', + 'isPriceFixed'] + } + } + ] + }; + + try { + let options = {transaction: tx}; + const worker = await models.Worker.findOne({ + where: {userFk: userId} + }, options); + + const obsevationType = await models.ObservationType.findOne({ + where: {description: 'comercial'} + }, options); + + const agency = await models.AgencyMode.findOne({ + where: {code: 'refund'} + }, options); + + const state = await models.State.findOne({ + where: {code: 'DELIVERED'} + }, options); + + + const claim = await models.Claim.findOne(filter, options); + const today = new Date(); + + const newRefundTicket = await models.Ticket.new(ctx, { + clientFk: claim.ticket().clientFk, + shipped: today, + landed: today, + warehouseFk: claim.ticket().warehouseFk, + companyFk: claim.ticket().companyFk, + addressFk: claim.ticket().addressFk, + agencyModeFk: agency.id, + userId: userId + }, options); + + await saveObservation({ + description: `Reclama ticket: ${claim.ticketFk}`, + ticketFk: newRefundTicket.id, + observationTypeFk: obsevationType.id + }, options); + + await models.TicketTracking.create({ + ticketFk: newRefundTicket.id, + stateFk: state.id, + workerFk: worker.id + }, options); + + const salesToRefund = await models.ClaimBeginning.find(salesFilter, options); + const createdSales = await addSalesToTicket(salesToRefund, newRefundTicket.id, options); + await insertIntoClaimEnd(createdSales, id, worker.id, options); + + await Self.rawSql('CALL vn.ticketCalculateClon(?, ?)', [ + newRefundTicket.id, claim.ticketFk + ], options); + + await tx.commit(); + + return newRefundTicket; + } catch (e) { + await tx.rollback(); + throw e; + } + }; + + async function addSalesToTicket(salesToRefund, ticketId, options) { let formatedSales = []; salesToRefund.forEach(sale => { let formatedSale = { itemFk: sale.sale().itemFk, - ticketFk: ticketFk, + ticketFk: ticketId, concept: sale.sale().concept, quantity: -Math.abs(sale.quantity), price: sale.sale().price, @@ -39,7 +139,7 @@ module.exports = Self => { } async function insertIntoClaimEnd(createdSales, claimId, workerId, options) { - let formatedSales = []; + const formatedSales = []; createdSales.forEach(sale => { let formatedSale = { saleFk: sale.id, @@ -48,101 +148,17 @@ module.exports = Self => { }; formatedSales.push(formatedSale); }); - return await Self.app.models.ClaimEnd.create(formatedSales, options); + await Self.app.models.ClaimEnd.create(formatedSales, options); } async function saveObservation(observation, options) { - let query = `INSERT INTO vn.ticketObservation(ticketFk, observationTypeFk, description) VALUES(?, ?, ?) - ON DUPLICATE KEY UPDATE description = CONCAT(vn.ticketObservation.description, VALUES(description),' ')`; + const query = `INSERT INTO vn.ticketObservation (ticketFk, observationTypeFk, description) VALUES(?, ?, ?) + ON DUPLICATE KEY + UPDATE description = CONCAT(vn.ticketObservation.description, VALUES(description),' ')`; await Self.rawSql(query, [ observation.ticketFk, observation.observationTypeFk, observation.description ], options); } - - Self.importToNewRefundTicket = async(ctx, id) => { - let models = Self.app.models; - let token = ctx.req.accessToken; - let userId = token.userId; - let worker = await models.Worker.findOne({where: {userFk: userId}}); - let obsevationType = await models.ObservationType.findOne({where: {description: 'comercial'}}); - let agency = await models.AgencyMode.findOne({where: {code: 'refund'}}); - let state = await models.State.findOne({where: {code: 'DELIVERED'}}); - - let filter = { - where: {id: id}, - include: [ - { - relation: 'ticket', - scope: { - fields: ['id', 'clientFk', 'warehouseFk', 'companyFk', 'addressFk'] - } - } - ] - }; - - let claim = await models.Claim.findOne(filter); - - let today = new Date(); - - let params = { - clientFk: claim.ticket().clientFk, - shipped: today, - landed: today, - warehouseFk: claim.ticket().warehouseFk, - companyFk: claim.ticket().companyFk, - addressFk: claim.ticket().addressFk, - agencyModeFk: agency.id, - userId: userId - }; - - let salesFilter = { - where: {claimFk: id}, - include: [ - { - relation: 'sale', - scope: { - fields: ['id', 'itemFk', 'concept', 'price', 'discount', 'reserved', 'isPicked', 'created', 'priceFixed', 'isPriceFixed'] - } - } - ] - }; - - let tx = await Self.beginTransaction({}); - - try { - let options = {transaction: tx}; - - let newRefundTicket = await models.Ticket.new(ctx, params, options); - - let observation = { - description: `Reclama ticket: ${claim.ticketFk}`, - ticketFk: newRefundTicket.id, - observationTypeFk: obsevationType.id - }; - await saveObservation(observation, options); - - await models.TicketTracking.create({ - ticketFk: newRefundTicket.id, - stateFk: state.id, - workerFk: worker.id - }, options); - - let salesToRefund = await models.ClaimBeginning.find(salesFilter); - let createdSales = await addSalesToTicket(salesToRefund, newRefundTicket.id, options); - insertIntoClaimEnd(createdSales, id, worker.id, options); - - await Self.rawSql('CALL vn.ticketCalculateClon(?, ?)', [ - newRefundTicket.id, claim.ticketFk - ], options); - - await tx.commit(); - - return newRefundTicket; - } catch (e) { - await tx.rollback(); - throw e; - } - }; }; diff --git a/modules/claim/back/methods/claim/createFromSales.js b/modules/claim/back/methods/claim/createFromSales.js index 0e4e34603..1d5597da7 100644 --- a/modules/claim/back/methods/claim/createFromSales.js +++ b/modules/claim/back/methods/claim/createFromSales.js @@ -26,26 +26,32 @@ module.exports = Self => { Self.createFromSales = async(ctx, params) => { let model = Self.app.models; + let userId = ctx.req.accessToken.userId; let tx = await Self.beginTransaction({}); + try { let options = {transaction: tx}; - - let userId = ctx.req.accessToken.userId; - let worker = await Self.app.models.Worker.findOne({where: {userFk: userId}}); + const worker = await Self.app.models.Worker.findOne({ + where: {userFk: userId} + }, options); params.claim.workerFk = worker.id; let newClaim = await Self.create(params.claim, options); let promises = []; - for (let i = 0; i < params.sales.length; i++) { - promises.push(model.ClaimBeginning.create({ - saleFk: params.sales[i].id, - claimFk: newClaim.id, - quantity: params.sales[i].quantity - }, options)); - } - await Promise.all(promises); - await tx.commit(); + for (const sale of params.sales) { + const newClaimBeginning = model.ClaimBeginning.create({ + saleFk: sale.id, + claimFk: newClaim.id, + quantity: sale.quantity + }, options); + + promises.push(newClaimBeginning); + } + + await Promise.all(promises); + + await tx.commit(); return newClaim; } catch (e) { await tx.rollback(); diff --git a/modules/item/back/methods/item/clone.js b/modules/item/back/methods/item/clone.js index 501cdc8d7..c4e15aa01 100644 --- a/modules/item/back/methods/item/clone.js +++ b/modules/item/back/methods/item/clone.js @@ -30,7 +30,7 @@ module.exports = Self => { const origin = await Self.findById(itemId, null, options); if (!origin) - throw new UserError(`That item doesn't exists`); + throw new UserError(`This item doesn't exists`); origin.itemTag = undefined; origin.description = undefined; @@ -40,12 +40,9 @@ module.exports = Self => { const newItem = await Self.create(origin, options); - let promises = []; - - await cloneTaxes(origin.id, newItem.id, promises, options); - await cloneBotanical(origin.id, newItem.id, promises, options); - await cloneTags(origin.id, newItem.id, promises, options); - await Promise.all(promises); + await cloneTaxes(origin.id, newItem.id, options); + await cloneBotanical(origin.id, newItem.id, options); + await cloneTags(origin.id, newItem.id, options); await tx.commit(); return newItem; @@ -59,36 +56,32 @@ module.exports = Self => { * Clone original taxes to new item * @param {Integer} originalId - Original item id * @param {Integer} newId - New item id - * @param {Array} promises - Array of promises * @param {Object} options - Transaction options */ - async function cloneTaxes(originalId, newId, promises, options) { + async function cloneTaxes(originalId, newId, options) { const models = Self.app.models; const originalTaxes = await models.ItemTaxCountry.find({ where: {itemFk: originalId}, fields: ['botanical', 'countryFk', 'taxClassFk'] }, options); - originalTaxes.forEach(tax => { + for (tax of originalTaxes) { tax.itemFk = newId; - const newItemTax = models.ItemTaxCountry.upsertWithWhere({ + await models.ItemTaxCountry.upsertWithWhere({ itemFk: newId, countryFk: tax.countryFk, }, tax, options); - - promises.push(newItemTax); - }); + } } /** * Clone original botanical to new item * @param {Integer} originalId - Original item id * @param {Integer} newId - New item id - * @param {Array} promises - Array of promises * @param {Object} options - Transaction options */ - async function cloneBotanical(originalId, newId, promises, options) { + async function cloneBotanical(originalId, newId, options) { const models = Self.app.models; const botanical = await models.ItemBotanical.findOne({ where: {itemFk: originalId}, @@ -97,8 +90,8 @@ module.exports = Self => { if (botanical) { botanical.itemFk = newId; - const newBotanical = models.ItemBotanical.create(botanical, options); - promises.push(newBotanical); + + await models.ItemBotanical.create(botanical, options); } } @@ -106,10 +99,9 @@ module.exports = Self => { * Clone original item tags to new item * @param {Integer} originalId - Original item id * @param {Integer} newId - New item id - * @param {Array} promises - Array of promises * @param {Object} options - Transaction options */ - async function cloneTags(originalId, newId, promises, options) { + async function cloneTags(originalId, newId, options) { const models = Self.app.models; const originalTags = await models.ItemTag.find({ where: { @@ -118,11 +110,10 @@ module.exports = Self => { fields: ['tagFk', 'value', 'priority'] }, options); - originalTags.forEach(tag => { + for (tag of originalTags) { tag.itemFk = newId; - const newTag = models.ItemTag.create(tag, options); - promises.push(newTag); - }); + await models.ItemTag.create(tag, options); + } } }; diff --git a/modules/item/back/methods/item/specs/clone.spec.js b/modules/item/back/methods/item/specs/clone.spec.js index 8ac228485..55142ee63 100644 --- a/modules/item/back/methods/item/specs/clone.spec.js +++ b/modules/item/back/methods/item/specs/clone.spec.js @@ -28,7 +28,7 @@ describe('item clone()', () => { let itemFk = 999; await app.models.Item.clone(itemFk) .catch(e => { - expect(e.message).toContain(`That item doesn't exists`); + expect(e.message).toContain(`This item doesn't exists`); error = e; }); From 340e7b8495cbdeb26d269017800d3cb9a13a8112 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 21 Jun 2019 09:43:47 +0200 Subject: [PATCH 3/3] round worker calendar holidays #1547 --- .../back/methods/worker-calendar/absences.js | 34 +++++++------------ .../worker-calendar/specs/absences.spec.js | 8 ++--- modules/worker/back/models/department.json | 7 ---- 3 files changed, 17 insertions(+), 32 deletions(-) diff --git a/modules/worker/back/methods/worker-calendar/absences.js b/modules/worker/back/methods/worker-calendar/absences.js index fb3cf534e..72e75f227 100644 --- a/modules/worker/back/methods/worker-calendar/absences.js +++ b/modules/worker/back/methods/worker-calendar/absences.js @@ -1,5 +1,4 @@ const UserError = require('vn-loopback/util/user-error'); -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; module.exports = Self => { Self.remoteMethodCtx('absences', { @@ -36,7 +35,7 @@ module.exports = Self => { } }); - Self.absences = async(ctx, workerFk, started, ended) => { + Self.absences = async(ctx, workerFk, yearStarted, yearEnded) => { const models = Self.app.models; const isSubordinate = await models.Worker.isSubordinate(ctx, workerFk); @@ -53,7 +52,7 @@ module.exports = Self => { }, where: { workerFk: workerFk, - dated: {between: [started, ended]} + dated: {between: [yearStarted, yearEnded]} } }); @@ -66,7 +65,7 @@ module.exports = Self => { }); // Get active contracts on current year - const year = started.getFullYear(); + const year = yearStarted.getFullYear(); const contracts = await models.WorkerLabour.find({ include: [{ relation: 'holidays', @@ -87,7 +86,7 @@ module.exports = Self => { relation: 'type' }], where: { - dated: {between: [started, ended]} + dated: {between: [yearStarted, yearEnded]} } } } @@ -97,7 +96,7 @@ module.exports = Self => { and: [ {workerFk: workerFk}, {or: [{ - ended: {gte: [started]} + ended: {gte: [yearStarted]} }, {ended: null}]} ], @@ -106,13 +105,7 @@ module.exports = Self => { // Get number of total holidays contracts.forEach(contract => { - let totalHolidays = contract.holidays().days; - - if (contract.started && contract.ended) - totalHolidays = getHolidaysByContract(started, contract); - - calendar.totalHolidays += totalHolidays; - + calendar.totalHolidays += getHolidaysByContract(contract, yearEnded); let holidayList = contract.workCenter().holidays(); for (let day of holidayList) { @@ -126,19 +119,18 @@ module.exports = Self => { return [calendar, absences, holidays]; }; - function getHolidaysByContract(started, contract) { + function getHolidaysByContract(contract, endOfYear) { const dayTimestamp = 1000 * 60 * 60 * 24; - const endedTime = contract.ended.getTime(); + + const started = contract.started; + const ended = contract.ended; const startedTime = started.getTime(); + const endedTime = ended && ended.getTime() || endOfYear; + const contractDays = Math.floor((endedTime - startedTime) / dayTimestamp); if (contractDays < 365) { - let holidays = contract.holidays().days * (contractDays + 1) / 365; - let integerPart = parseInt(holidays); - let decimalPart = holidays - integerPart; - let decimal = decimalPart >= 0.5 ? 0.5 : 0; - - holidays = integerPart + decimal; + let holidays = Math.round(2 * contract.holidays().days * (contractDays + 1) / 365) / 2; return holidays; } diff --git a/modules/worker/back/methods/worker-calendar/specs/absences.spec.js b/modules/worker/back/methods/worker-calendar/specs/absences.spec.js index da21a7b05..5627c4303 100644 --- a/modules/worker/back/methods/worker-calendar/specs/absences.spec.js +++ b/modules/worker/back/methods/worker-calendar/specs/absences.spec.js @@ -43,7 +43,7 @@ describe('Worker absences()', () => { expect(sixthType).toEqual('Holidays'); }); - it(`should fire the worker 106 on July and see he/she has 13.5`, async() => { + it(`should fire the worker 106 on July and see he/she has 14`, async() => { const firedWorker = await app.models.WorkerLabour.findById(106); const endedDate = new Date(); @@ -71,7 +71,7 @@ describe('Worker absences()', () => { let calendar = result[0]; let absences = result[1]; - expect(calendar.totalHolidays).toEqual(13.5); + expect(calendar.totalHolidays).toEqual(14); expect(calendar.holidaysEnjoyed).toEqual(5); let firstType = absences[0].absenceType().name; @@ -81,7 +81,7 @@ describe('Worker absences()', () => { expect(sixthType).toEqual('Holidays'); }); - it(`should fire the worker 106 on March and see he/she has 6.5`, async() => { + it(`should fire the worker 106 on March and see he/she has 7`, async() => { const firedWorker = await app.models.WorkerLabour.findById(106); const endedDate = new Date(); @@ -109,7 +109,7 @@ describe('Worker absences()', () => { let calendar = result[0]; let absences = result[1]; - expect(calendar.totalHolidays).toEqual(6.5); + expect(calendar.totalHolidays).toEqual(7); expect(calendar.holidaysEnjoyed).toEqual(5); let firstType = absences[0].absenceType().name; diff --git a/modules/worker/back/models/department.json b/modules/worker/back/models/department.json index c89a6ac4e..0b978b56c 100644 --- a/modules/worker/back/models/department.json +++ b/modules/worker/back/models/department.json @@ -14,12 +14,5 @@ "name": { "type": "String" } - }, - "relations": { - "father": { - "type": "belongsTo", - "model": "Department", - "foreignKey": "fatherFk" - } } }