From 8448dc52c63972c7ddc7adf412c8646c9235e97c Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 May 2023 14:13:19 +0200 Subject: [PATCH] refs #4823 Libraries update --- floriday.js | 2 +- models/{index.js => sequelize.js} | 3 +- package-lock.json | 242 +++++++++++++++--------------- package.json | 8 +- utils.js | 130 ++++++---------- 5 files changed, 170 insertions(+), 215 deletions(-) rename models/{index.js => sequelize.js} (98%) diff --git a/floriday.js b/floriday.js index d1bc5dd..49fd8c0 100644 --- a/floriday.js +++ b/floriday.js @@ -1,5 +1,5 @@ import * as utils from './utils.js'; -import { models, checkConn, closeConn } from './models/index.js'; +import { models, checkConn, closeConn } from './models/sequelize.js'; import moment from 'moment'; import chalk from 'chalk'; diff --git a/models/index.js b/models/sequelize.js similarity index 98% rename from models/index.js rename to models/sequelize.js index 4363f7f..434fbe4 100644 --- a/models/index.js +++ b/models/sequelize.js @@ -2,7 +2,7 @@ import { Sequelize } from 'sequelize'; import dotenv from 'dotenv'; import chalk from 'chalk'; import ora from 'ora'; -import { criticalError, updateClientConfig } from './../utils.js'; +import { criticalError, updateClientConfig } from '../utils.js'; dotenv.config(); const env = process.env; @@ -134,7 +134,6 @@ try { targetKey: 'packingConfigurationId', }); - models.botanicalName.belongsTo(models.tradeItem, { foreignKey: 'tradeItemId', as: 'tradeItem_Fk', diff --git a/package-lock.json b/package-lock.json index f289338..5957891 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,26 +8,50 @@ "dependencies": { "chalk": "^5.2.0", "dotenv": "^16.0.3", - "mariadb": "^3.0.2", + "mariadb": "^3.1.2", "moment": "^2.29.4", - "node-fetch": "^3.3.0", + "node-fetch": "^3.3.1", "ora": "^6.3.0", - "sequelize": "^6.26.0", + "sequelize": "^6.31.1", "uuid": "^9.0.0" }, "devDependencies": { - "eslint": "^8.31.0" + "eslint": "^8.40.0" + } + }, + "node_modules/@eslint-community/eslint-utils": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", + "integrity": "sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==", + "dev": true, + "dependencies": { + "eslint-visitor-keys": "^3.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "peerDependencies": { + "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" + } + }, + "node_modules/@eslint-community/regexpp": { + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.5.1.tgz", + "integrity": "sha512-Z5ba73P98O1KUYCCJTUeVpja9RcGoMdncZ6T49FCUl2lN38JtCJ+3WgIDBv0AuY4WChU5PmtJmOCTlN6FZTFKQ==", + "dev": true, + "engines": { + "node": "^12.0.0 || ^14.0.0 || >=16.0.0" } }, "node_modules/@eslint/eslintrc": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.4.1.tgz", - "integrity": "sha512-XXrH9Uarn0stsyldqDYq8r++mROmWRI1xKMXa640Bb//SY1+ECYX6VzT6Lcx5frD0V30XieqJ0oX9I2Xj5aoMA==", + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.0.3.tgz", + "integrity": "sha512-+5gy6OQfk+xx3q0d6jGZZC3f3KzAkXc/IanVxd1is/VIIziRqqt3ongQz0FiTUXqTk0c7aDB3OaFuKnuSoJicQ==", "dev": true, "dependencies": { "ajv": "^6.12.4", "debug": "^4.3.2", - "espree": "^9.4.0", + "espree": "^9.5.2", "globals": "^13.19.0", "ignore": "^5.2.0", "import-fresh": "^3.2.1", @@ -42,6 +66,15 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/@eslint/js": { + "version": "8.40.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.40.0.tgz", + "integrity": "sha512-ElyB54bJIhXQYVKjDSvCkPO1iU1tSAeVQJbllWJq1XQSmmA4dgFk8CbiBGpiOPxleE48vDogxCtmMYku4HSVLA==", + "dev": true, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.8", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz", @@ -134,14 +167,14 @@ "integrity": "sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==" }, "node_modules/@types/validator": { - "version": "13.7.10", - "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.7.10.tgz", - "integrity": "sha512-t1yxFAR2n0+VO6hd/FJ9F2uezAZVWHLmpmlJzm1eX03+H7+HsuTAp7L8QJs+2pQCfWkP1+EXsGK9Z9v7o/qPVQ==" + "version": "13.7.16", + "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.7.16.tgz", + "integrity": "sha512-VyKmLktUHYLbrSbsRi241MSUlGYomQgK/tfCNpej3Gt5qDOM10AZ3nU2aR2s5JritClXuOBu4K7MkywVW/Y6Ow==" }, "node_modules/acorn": { - "version": "8.8.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.1.tgz", - "integrity": "sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==", + "version": "8.8.2", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz", + "integrity": "sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -308,9 +341,9 @@ } }, "node_modules/cli-spinners": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.7.0.tgz", - "integrity": "sha512-qu3pN8Y3qHNgE2AFweciB1IfMnmZ/fsNTEE+NOFjmGB2F/7rLhnhzppvpCnN4FovtP26k8lHyy9ptEbNwWFLzw==", + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.0.tgz", + "integrity": "sha512-4/aL9X3Wh0yiMQlE+eeRhWP6vclO3QRtw1JHKIT0FFUs5FjpFmESqtMvYZ0+lbzBw900b95mS0hohy+qn2VK/g==", "engines": { "node": ">=6" }, @@ -365,9 +398,9 @@ } }, "node_modules/data-uri-to-buffer": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", - "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", "engines": { "node": ">= 12" } @@ -434,9 +467,9 @@ } }, "node_modules/dottie": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.2.tgz", - "integrity": "sha512-fmrwR04lsniq/uSr8yikThDTrM7epXHBAAjH9TbeH3rEA8tdCO7mRzB9hdmdGyJCxF8KERo9CITcm3kGuoyMhg==" + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.3.tgz", + "integrity": "sha512-4liA0PuRkZWQFQjwBypdxPfZaRWiv5tkhMXY2hzsa2pNf5s7U3m9cwUchfNKe8wZQxdGPQQzO6Rm2uGe0rvohQ==" }, "node_modules/escape-string-regexp": { "version": "4.0.0", @@ -451,12 +484,15 @@ } }, "node_modules/eslint": { - "version": "8.31.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.31.0.tgz", - "integrity": "sha512-0tQQEVdmPZ1UtUKXjX7EMm9BlgJ08G90IhWh0PKDCb3ZLsgAOHI8fYSIzYVZej92zsgq+ft0FGsxhJ3xo2tbuA==", + "version": "8.40.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.40.0.tgz", + "integrity": "sha512-bvR+TsP9EHL3TqNtj9sCNJVAFK3fBN8Q7g5waghxyRsPLIMwL73XSKnZFK0hk/O2ANC+iAoq6PWMQ+IfBAJIiQ==", "dev": true, "dependencies": { - "@eslint/eslintrc": "^1.4.1", + "@eslint-community/eslint-utils": "^4.2.0", + "@eslint-community/regexpp": "^4.4.0", + "@eslint/eslintrc": "^2.0.3", + "@eslint/js": "8.40.0", "@humanwhocodes/config-array": "^0.11.8", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", @@ -466,11 +502,10 @@ "debug": "^4.3.2", "doctrine": "^3.0.0", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^7.1.1", - "eslint-utils": "^3.0.0", - "eslint-visitor-keys": "^3.3.0", - "espree": "^9.4.0", - "esquery": "^1.4.0", + "eslint-scope": "^7.2.0", + "eslint-visitor-keys": "^3.4.1", + "espree": "^9.5.2", + "esquery": "^1.4.2", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", "file-entry-cache": "^6.0.1", @@ -491,7 +526,6 @@ "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.1", - "regexpp": "^3.2.0", "strip-ansi": "^6.0.1", "strip-json-comments": "^3.1.0", "text-table": "^0.2.0" @@ -507,9 +541,9 @@ } }, "node_modules/eslint-scope": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.1.tgz", - "integrity": "sha512-QKQM/UXpIiHcLqJ5AOyIW7XZmzjkzQXYE54n1++wb0u9V/abW3l9uQnxX8Z5Xd18xyKIMTUAyQ0k1e8pz6LUrw==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.0.tgz", + "integrity": "sha512-DYj5deGlHBfMt15J7rdtyKNq/Nqlv5KfU4iodrQ019XESsRnwXH9KAE0y3cwtUHDo2ob7CypAnCqefh6vioWRw==", "dev": true, "dependencies": { "esrecurse": "^4.3.0", @@ -517,42 +551,21 @@ }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - } - }, - "node_modules/eslint-utils": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz", - "integrity": "sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==", - "dev": true, - "dependencies": { - "eslint-visitor-keys": "^2.0.0" - }, - "engines": { - "node": "^10.0.0 || ^12.0.0 || >= 14.0.0" }, "funding": { - "url": "https://github.com/sponsors/mysticatea" - }, - "peerDependencies": { - "eslint": ">=5" - } - }, - "node_modules/eslint-utils/node_modules/eslint-visitor-keys": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", - "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", - "dev": true, - "engines": { - "node": ">=10" + "url": "https://opencollective.com/eslint" } }, "node_modules/eslint-visitor-keys": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz", - "integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==", + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.1.tgz", + "integrity": "sha512-pZnmmLwYzf+kWaM/Qgrvpen51upAktaaiI01nsJD/Yr3lMOdNtq0cxkrrg16w64VtisN6okbs7Q8AfGqj4c9fA==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" } }, "node_modules/eslint/node_modules/chalk": { @@ -572,14 +585,14 @@ } }, "node_modules/espree": { - "version": "9.4.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.4.1.tgz", - "integrity": "sha512-XwctdmTO6SIvCzd9810yyNzIrOrqNYV9Koizx4C/mRhf9uq0o4yHoCEU/670pOxOL/MSraektvSAji79kX90Vg==", + "version": "9.5.2", + "resolved": "https://registry.npmjs.org/espree/-/espree-9.5.2.tgz", + "integrity": "sha512-7OASN1Wma5fum5SrNhFMAMJxOUAbhyfQ8dQ//PJaJbNw0URTPWqIghHWt1MmAANKhHZIYOHruW4Kw4ruUWOdGw==", "dev": true, "dependencies": { "acorn": "^8.8.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^3.3.0" + "eslint-visitor-keys": "^3.4.1" }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -589,9 +602,9 @@ } }, "node_modules/esquery": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.4.0.tgz", - "integrity": "sha512-cCDispWt5vHHtwMY2YrAQ4ibFkAL8RbH5YGBnZBc90MolvvfkkQcJro/aZiAQUlQ3qgrYS6D6v8Gc5G5CQsc9w==", + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz", + "integrity": "sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==", "dev": true, "dependencies": { "estraverse": "^5.1.0" @@ -776,9 +789,9 @@ } }, "node_modules/globals": { - "version": "13.19.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.19.0.tgz", - "integrity": "sha512-dkQ957uSRWHw7CFXLUtUHQI3g3aWApYhfNR2O6jn/907riyTYKVBmxYVROkBcY614FSSeSJh7Xm7SrUWCxvJMQ==", + "version": "13.20.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.20.0.tgz", + "integrity": "sha512-Qg5QtVkCy/kv3FUSlu4ukeZDVf9ee0iXLAUYX13gbR17bnejFTzr4iS9bY7kwCf1NztRNm1t91fjOiyx4CSwPQ==", "dev": true, "dependencies": { "type-fest": "^0.20.2" @@ -951,9 +964,9 @@ "dev": true }, "node_modules/js-sdsl": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.2.0.tgz", - "integrity": "sha512-dyBIzQBDkCqCu+0upx25Y2jGdbTGxE9fshMsCdK0ViOongpV+n5tXRcZY9v7CaVQ79AGS9KA1KHtojxiM7aXSQ==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.4.0.tgz", + "integrity": "sha512-FfVSdx6pJ41Oa+CF7RDaFmTnCaFhua+SNYQX74riGOpl96x+2jQCqEfQ2bnXu/5DPCqlRuiqyvTJM0Qjz26IVg==", "dev": true, "funding": { "type": "opencollective", @@ -1039,24 +1052,23 @@ } }, "node_modules/lru-cache": { - "version": "7.14.1", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.14.1.tgz", - "integrity": "sha512-ysxwsnTKdAx96aTRdhDOCQfDgbHnt8SK0KY8SEjO0wHinhWOFTESbjVCMPbU1uGXg/ch4lifqx0wfjOawU2+WA==", + "version": "7.18.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", + "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", "engines": { "node": ">=12" } }, "node_modules/mariadb": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/mariadb/-/mariadb-3.0.2.tgz", - "integrity": "sha512-dVjiQZ6RW0IXFnX+T/ZEmnqs724DgkQsXqfCyInXn0XxVfO2Px6KbS4M3Ny6UiBg0zJ93SHHvfVBgYO4ZnFvvw==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/mariadb/-/mariadb-3.1.2.tgz", + "integrity": "sha512-ILlC54fkXkvizTJZC1uP7f/REBxuu1k+OWzpiIITIEdS+dGIjFe/Ob3EW9KrdtBa38l3z+odz6elva0RG/y5og==", "dependencies": { "@types/geojson": "^7946.0.10", "@types/node": "^17.0.45", "denque": "^2.1.0", "iconv-lite": "^0.6.3", - "lru-cache": "^7.14.0", - "moment-timezone": "^0.5.38" + "lru-cache": "^7.14.0" }, "engines": { "node": ">= 12" @@ -1091,11 +1103,11 @@ } }, "node_modules/moment-timezone": { - "version": "0.5.39", - "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.39.tgz", - "integrity": "sha512-hoB6suq4ISDj7BDgctiOy6zljBsdYT0++0ZzZm9rtxIvJhIbQ3nmbgSWe7dNFGurl6/7b1OUkHlmN9JWgXVz7w==", + "version": "0.5.43", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.43.tgz", + "integrity": "sha512-72j3aNyuIsDxdF1i7CEgV2FfxM1r6aaqJyLB2vwb33mXYyoyLly+F1zbWqhA3/bVIoJ4szlUoMbUnVdid32NUQ==", "dependencies": { - "moment": ">= 2.9.0" + "moment": "^2.29.4" }, "engines": { "node": "*" @@ -1131,9 +1143,9 @@ } }, "node_modules/node-fetch": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.0.tgz", - "integrity": "sha512-BKwRP/O0UvoMKp7GNdwPlObhYGB5DQqwhEDQlNKuoqwVYSxkSZCSbHjnFFmUEtwSKRPU4kNK8PbDYYitwaE3QA==", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.1.tgz", + "integrity": "sha512-cRVc/kyto/7E5shrWca1Wsea4y6tL9iYJE5FBCius3JQfb/4P4I295PfhgbJQBLTx6lATE4z+wK0rPM4VS2uow==", "dependencies": { "data-uri-to-buffer": "^4.0.0", "fetch-blob": "^3.1.4", @@ -1318,9 +1330,9 @@ } }, "node_modules/punycode": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", - "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", + "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==", "dev": true, "engines": { "node": ">=6" @@ -1359,18 +1371,6 @@ "node": ">= 6" } }, - "node_modules/regexpp": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", - "integrity": "sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==", - "dev": true, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/mysticatea" - } - }, "node_modules/resolve-from": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", @@ -1396,9 +1396,9 @@ } }, "node_modules/retry-as-promised": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/retry-as-promised/-/retry-as-promised-6.1.0.tgz", - "integrity": "sha512-Hj/jY+wFC+SB9SDlIIFWiGOHnNG0swYbGYsOj2BJ8u2HKUaobNKab0OIC0zOLYzDy0mb7A4xA5BMo4LMz5YtEA==" + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/retry-as-promised/-/retry-as-promised-7.0.4.tgz", + "integrity": "sha512-XgmCoxKWkDofwH8WddD0w85ZfqYz+ZHlr5yo+3YUCfycWawU56T5ckWXsScsj5B8tqUcIG67DxXByo3VUgiAdA==" }, "node_modules/reusify": { "version": "1.0.4", @@ -1473,9 +1473,9 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "node_modules/semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.0.tgz", + "integrity": "sha512-+XC0AD/R7Q2mPSRuy2Id0+CGTZ98+8f+KvwirxOKIEyid+XSx6HbC63p+O4IndTHuX5Z+JxQ0TghCkO5Cg/2HA==", "dependencies": { "lru-cache": "^6.0.0" }, @@ -1498,9 +1498,9 @@ } }, "node_modules/sequelize": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/sequelize/-/sequelize-6.26.0.tgz", - "integrity": "sha512-Xv82z1FdSn/qwB1IObSxIHV519cFk/vSD28vWs8Y0VucQLn7pK2x2jYjf2Qg/rBUQbCVprDdU7RPf+55rrkc0A==", + "version": "6.31.1", + "resolved": "https://registry.npmjs.org/sequelize/-/sequelize-6.31.1.tgz", + "integrity": "sha512-cahWtRrYLjqoZP/aurGBoaxn29qQCF4bxkAUPEQ/ozjJjt6mtL4Q113S3N39mQRmX5fgxRbli+bzZARP/N51eg==", "funding": [ { "type": "opencollective", @@ -1515,9 +1515,9 @@ "inflection": "^1.13.2", "lodash": "^4.17.21", "moment": "^2.29.1", - "moment-timezone": "^0.5.34", + "moment-timezone": "^0.5.35", "pg-connection-string": "^2.5.0", - "retry-as-promised": "^6.1.0", + "retry-as-promised": "^7.0.3", "semver": "^7.3.5", "sequelize-pool": "^7.1.0", "toposort-class": "^1.0.1", @@ -1716,9 +1716,9 @@ } }, "node_modules/validator": { - "version": "13.7.0", - "resolved": "https://registry.npmjs.org/validator/-/validator-13.7.0.tgz", - "integrity": "sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw==", + "version": "13.9.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.9.0.tgz", + "integrity": "sha512-B+dGG8U3fdtM0/aNK4/X8CXq/EcxU2WPrPEkJGslb47qyHsxmbggTWK0yEA4qnYVNF+nxNlN88o14hIcPmSIEA==", "engines": { "node": ">= 0.10" } diff --git a/package.json b/package.json index 55ba3c8..465548e 100644 --- a/package.json +++ b/package.json @@ -5,14 +5,14 @@ "dependencies": { "chalk": "^5.2.0", "dotenv": "^16.0.3", - "mariadb": "^3.0.2", + "mariadb": "^3.1.2", "moment": "^2.29.4", - "node-fetch": "^3.3.0", + "node-fetch": "^3.3.1", "ora": "^6.3.0", - "sequelize": "^6.26.0", + "sequelize": "^6.31.1", "uuid": "^9.0.0" }, "devDependencies": { - "eslint": "^8.31.0" + "eslint": "^8.40.0" } } diff --git a/utils.js b/utils.js index 52f3514..c6c74e9 100644 --- a/utils.js +++ b/utils.js @@ -1,6 +1,6 @@ import moment from 'moment'; import fetch from 'node-fetch'; -import { models } from './models/index.js'; +import { models } from './models/sequelize.js'; import { v4 as uuidv4 } from 'uuid'; import chalk from 'chalk'; import ora, { spinners } from 'ora'; @@ -404,19 +404,18 @@ export async function syncConn(){ export async function syncTradeItems(){ const spinner = ora(`Syncing trade items...`).start(); - const suppliers = await models.supplier.findAll(); + const suppliers = await models.supplier.findAll({ + where: { isConnected: true } + }); let i = 1; for (let supplier of suppliers) { - if (!supplier.isConnected) continue; - - let query = `${env.API_URL}/trade-items?supplierOrganizationId=${supplier.supplierOrganizationId}`; let headers = { 'Content-Type': 'application/json', 'Authorization': `Bearer ${await getCurrentToken()}`, 'X-Api-Key': process.env.API_KEY }; try { - let request = await fetch(query, { + let request = await fetch(`${env.API_URL}/trade-items?supplierOrganizationId=${supplier.supplierOrganizationId}`, { method: 'GET', headers }); @@ -607,127 +606,84 @@ export async function syncSupplyLines(){ export async function insertItem(tradeItem, supplier) { try { - // Temporal connection to all suppliers that have trade items - - let currentSupp = await models.supplier.findOne({ - where: { - supplierOrganizationId: tradeItem.supplierOrganizationId - } - }); - - currentSupp.isConnected = true; - - let tx = await models.sequelize.transaction(); - await currentSupp.save({transaction: tx}); + const tx = await models.sequelize.transaction(); + // Upsert supplier connection await models.connection.upsert({ supplierOrganizationId: tradeItem.supplierOrganizationId, connect: true, - }, {transaction: tx}); - - // ----- + }, { transaction: tx }); + // Upsert trade item await models.tradeItem.upsert({ - tradeItemId: tradeItem.tradeItemId, - supplierOrganizationId: tradeItem.supplierOrganizationId, - code: tradeItem.code, - gtin: tradeItem.gtin, - vbnProductCode: tradeItem.vbnProductCode, - name: tradeItem.name, + ...tradeItem, isDeleted: tradeItem.isDeleted, - sequenceNumber: tradeItem.sequenceNumber, - tradeItemVersion: tradeItem.tradeItemVersion, isCustomerSpecific: tradeItem.isCustomerSpecific, isHiddenInCatalog: tradeItem.isHiddenInCatalog, - }, - {transaction: tx}); + }, { transaction: tx }); - let characteristics = tradeItem.characteristics; - - for (let characteristic of characteristics) { + // Upsert characteristics + for (const characteristic of tradeItem.characteristics) { await models.characteristic.upsert({ - vbnCode: characteristic.vbnCode, - vbnValueCode: characteristic.vbnValueCode, + ...characteristic, tradeItemId: tradeItem.tradeItemId, - }, {transaction: tx}); + }, { transaction: tx }); } - let seasonalPeriods = tradeItem.seasonalPeriods; - - for (let seasonalPeriod of seasonalPeriods) { + // Upsert seasonal periods + for (const seasonalPeriod of tradeItem.seasonalPeriods) { await models.seasonalPeriod.upsert({ - startWeek: seasonalPeriod.startWeek, - endWeek: seasonalPeriod.endWeek, + ...seasonalPeriod, tradeItemId: tradeItem.tradeItemId, - }, {transaction: tx}); + }, { transaction: tx }); } - let photos = tradeItem.photos; - - for (let photo of photos) + // Upsert photos + for (const photo of tradeItem.photos) { await models.photo.upsert({ - id: photo.id, - url: photo.url, - type: photo.type, - primary: photo.primary, + ...photo, tradeItemId: tradeItem.tradeItemId, - }, {transaction: tx}); + }, { transaction: tx }); + } - let packingConfigurations = tradeItem.packingConfigurations; - - for (let packingConfiguration of packingConfigurations) { - - let uuid = uuidv4(); + // Upsert packing configurations + for (const packingConfiguration of tradeItem.packingConfigurations) { + const uuid = uuidv4(); await models.packingConfiguration.upsert({ packingConfigurationId: uuid, - piecesPerPackage: packingConfiguration.piecesPerPackage, - bunchesPerPackage: packingConfiguration.bunchesPerPackage, - photoUrl: packingConfiguration.photoUrl, - packagesPerLayer: packingConfiguration.packagesPerLayer, - layersPerLoadCarrier: packingConfiguration.layersPerLoadCarrier, - additionalPricePerPiece : JSON.stringify(packingConfiguration.additionalPricePerPiece), - transportHeightInCm: packingConfiguration.transportHeightInCm, - loadCarrierType: packingConfiguration.loadCarrierType, - isPrimary: packingConfiguration.isPrimary, + ...packingConfiguration, + additionalPricePerPiece: JSON.stringify(packingConfiguration.additionalPricePerPiece), tradeItemId: tradeItem.tradeItemId, - }, {transaction: tx}); - + }, { transaction: tx }); + await models.package.upsert({ - vbnPackageCode: packingConfiguration.package.vbnPackageCode, - customPackageId: packingConfiguration.package.customPackageId, + ...packingConfiguration.package, packingConfigurationFk: uuid, - }, {transaction: tx}); + }, { transaction: tx }); } - let countryOfOriginIsoCodes = tradeItem.countryOfOriginIsoCodes; - - countryOfOriginIsoCodes ??= 0; - - for (let countryOfOriginIsoCode of countryOfOriginIsoCodes) { + // Upsert country of origin ISO codes + for (const isoCode of tradeItem.countryOfOriginIsoCodes || []) { await models.countryOfOriginIsoCode.upsert({ - isoCode: countryOfOriginIsoCode, + isoCode, tradeItemId: tradeItem.tradeItemId, - }, {transaction: tx}); + }, { transaction: tx }); } - let botanicalNames = tradeItem.botanicalNames; - - for (let botanicalName of botanicalNames) { + // Upsert botanical names + for (const botanicalName of tradeItem.botanicalNames) { await models.botanicalName.upsert({ - name: botanicalName.name, + ...botanicalName, tradeItemId: tradeItem.tradeItemId, - }, {transaction: tx}); + }, { transaction: tx }); } await tx.commit(); - - } catch (error) { + } catch (err) { + console.log(err); await tx.rollback(); - console.log('Error while syncing trade items for: ', supplier.commercialName); - console.log(error); } - } /**