From 7a4de34f9ce53241b7a476326e075602654ed254 Mon Sep 17 00:00:00 2001 From: Xziy Date: Thu, 20 Jul 2023 09:27:36 +0300 Subject: [PATCH] fix warnings --- adapters/rms/RMSAdapter.js | 4 ++-- adapters/rms/RMSAdapter.ts | 4 ++-- hook/afterHook.js | 17 ++++++++------- hook/afterHook.ts | 24 +++++++++++----------- interfaces/Modifier.d.ts | 6 ++++-- interfaces/Modifier.ts | 9 ++++++-- models/Dish.d.ts | 1 - models/Dish.js | 42 ++++++++++++++++++++++++++++++-------- models/Dish.ts | 42 ++++++++++++++++++++++++++++++-------- models/Group.d.ts | 2 +- models/Settings.js | 6 +++++- models/Settings.ts | 10 +++++++-- 12 files changed, 115 insertions(+), 52 deletions(-) diff --git a/adapters/rms/RMSAdapter.js b/adapters/rms/RMSAdapter.js index 1c5896d0..f394738f 100644 --- a/adapters/rms/RMSAdapter.js +++ b/adapters/rms/RMSAdapter.js @@ -61,7 +61,7 @@ class RMSAdapter { // Get ids of all current RMS groups const rmsGroupIds = currentRMSGroupsFlatTree.map(group => group.rmsId); // Set all groups not in the list to inactive - await Group.update({ where: { rmsId: { not: rmsGroupIds } } }, { isDeleted: true }).fetch(); + await Group.update({ where: { rmsId: { "!=": rmsGroupIds } } }, { isDeleted: true }).fetch(); for (const group of currentRMSGroupsFlatTree) { emitter.emit("rms-sync:before-each-group-item", group); // Update or create group @@ -86,7 +86,7 @@ class RMSAdapter { const inactiveGroups = await Group.find({ isDeleted: true }); const inactiveGroupIds = inactiveGroups.map(group => group.id); // Delete all dishes in inactive groups or not in the updated list - await Dish.update({ where: { or: [{ parentGroup: { in: inactiveGroupIds } }, { rmsId: { not: allProductIds } }, { parentGroup: null }] } }, { isDeleted: true }); + await Dish.update({ where: { or: [{ parentGroup: { in: inactiveGroupIds } }, { rmsId: { "!=": allProductIds } }, { parentGroup: null }] } }, { isDeleted: true }); } this.syncProductsExecuted = false; return; diff --git a/adapters/rms/RMSAdapter.ts b/adapters/rms/RMSAdapter.ts index 255d5084..84a4541d 100644 --- a/adapters/rms/RMSAdapter.ts +++ b/adapters/rms/RMSAdapter.ts @@ -98,7 +98,7 @@ export default abstract class RMSAdapter { const rmsGroupIds = currentRMSGroupsFlatTree.map(group => group.rmsId); // Set all groups not in the list to inactive - await Group.update({ where:{ rmsId: { not: rmsGroupIds }}},{ isDeleted: true }).fetch(); + await Group.update({ where:{ rmsId: { "!=": rmsGroupIds }}},{ isDeleted: true }).fetch(); for (const group of currentRMSGroupsFlatTree) { emitter.emit("rms-sync:before-each-group-item", group); @@ -132,7 +132,7 @@ export default abstract class RMSAdapter { const inactiveGroupIds = inactiveGroups.map(group => group.id); // Delete all dishes in inactive groups or not in the updated list - await Dish.update({ where:{ or: [ { parentGroup: { in: inactiveGroupIds }}, { rmsId: { not: allProductIds }}, {parentGroup: null} ]}}, { isDeleted: true }); + await Dish.update({ where:{ or: [ { parentGroup: { in: inactiveGroupIds }}, { rmsId: { "!=": allProductIds }}, {parentGroup: null} ]}}, { isDeleted: true }); } this.syncProductsExecuted = false return diff --git a/hook/afterHook.js b/hook/afterHook.js index 537a8613..71833160 100644 --- a/hook/afterHook.js +++ b/hook/afterHook.js @@ -1,6 +1,5 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -const index_1 = require("../adapters/index"); /** * Initial RMS and set timezone if it given */ @@ -10,19 +9,19 @@ async function default_1() { * rmsAdapter */ const rmsAdapterName = await Settings.use("rmsAdapter", "restocore"); - const rmsAdapterConfig = await Settings.use(rmsAdapterName, "restocore"); + const rmsAdapterConfig = await Settings.use("rmsAdapterName", "restocore"); const imagesConfig = await Settings.use("images", "restocore"); const timeSyncMenu = await Settings.use("timeSyncMenu", "restocore"); const timeSyncBalance = await Settings.use("timeSyncBalance", "restocore"); const timeSyncStreets = await Settings.use("timeSyncStreets", "restocore"); const timeSyncPayments = await Settings.use("timeSyncPayments", "restocore"); - /** - * run instance RMSadapter - */ - if (rmsAdapterName) { - const rmsAdapter = await index_1.RMS.getAdapter(rmsAdapterName); - rmsAdapter.getInstance(rmsAdapterConfig, imagesConfig, timeSyncMenu, timeSyncBalance, timeSyncStreets); - } + // /** + // * run instance RMSadapter + // */ + // if (rmsAdapterName) { + // const rmsAdapter = await RMS.getAdapter(rmsAdapterName); + // rmsAdapter.getInstance(rmsAdapterConfig, imagesConfig, timeSyncMenu, timeSyncBalance, timeSyncStreets); + // } /** * TIMEZONE */ diff --git a/hook/afterHook.ts b/hook/afterHook.ts index b99ededb..6fc36cf9 100644 --- a/hook/afterHook.ts +++ b/hook/afterHook.ts @@ -10,20 +10,20 @@ export default async function () { * rmsAdapter */ const rmsAdapterName = await Settings.use("rmsAdapter", "restocore") as string; - const rmsAdapterConfig = await Settings.use(rmsAdapterName, "restocore"); - const imagesConfig = await Settings.use("images","restocore"); - const timeSyncMenu = await Settings.use("timeSyncMenu","restocore"); - const timeSyncBalance = await Settings.use("timeSyncBalance","restocore"); - const timeSyncStreets = await Settings.use("timeSyncStreets","restocore"); + const rmsAdapterConfig = await Settings.use("rmsAdapterName", "restocore") as any; + const imagesConfig = await Settings.use("images","restocore") as any; + const timeSyncMenu = await Settings.use("timeSyncMenu","restocore") as number; + const timeSyncBalance = await Settings.use("timeSyncBalance","restocore") as number; + const timeSyncStreets = await Settings.use("timeSyncStreets","restocore") as number; const timeSyncPayments = await Settings.use("timeSyncPayments","restocore") as number; - /** - * run instance RMSadapter - */ - if (rmsAdapterName) { - const rmsAdapter = await RMS.getAdapter(rmsAdapterName); - rmsAdapter.getInstance(rmsAdapterConfig, imagesConfig, timeSyncMenu, timeSyncBalance, timeSyncStreets); - } + // /** + // * run instance RMSadapter + // */ + // if (rmsAdapterName) { + // const rmsAdapter = await RMS.getAdapter(rmsAdapterName); + // rmsAdapter.getInstance(rmsAdapterConfig, imagesConfig, timeSyncMenu, timeSyncBalance, timeSyncStreets); + // } /** * TIMEZONE diff --git a/interfaces/Modifier.d.ts b/interfaces/Modifier.d.ts index 29cce66b..7e0b2100 100644 --- a/interfaces/Modifier.d.ts +++ b/interfaces/Modifier.d.ts @@ -3,11 +3,13 @@ import Dish from "../models/Dish"; interface BaseModifier { modifierId: string; amount?: number; - dish?: Dish; + dish?: Dish | string; maxAmount?: number; minAmount?: number; defaultAmount?: number; freeAmount?: number; + required: boolean | null; + freeOfChargeAmount?: number | null; } export interface OrderModifier { id: string; @@ -21,7 +23,7 @@ export interface Modifier extends BaseModifier { export interface GroupModifier extends BaseModifier { id?: string; childModifiers: Modifier[]; - group?: Group | any; + group?: Group | string; groupId?: string; isSingleModifierGroupWrapper?: boolean; } diff --git a/interfaces/Modifier.ts b/interfaces/Modifier.ts index 38abc018..a69cdf9a 100644 --- a/interfaces/Modifier.ts +++ b/interfaces/Modifier.ts @@ -4,11 +4,13 @@ import Dish from "../models/Dish"; interface BaseModifier { modifierId: string; amount?: number; - dish?: Dish; + dish?: Dish | string; maxAmount?: number; minAmount?: number; defaultAmount?: number; freeAmount?: number; + required: boolean | null; + freeOfChargeAmount?: number | null; } export interface OrderModifier { @@ -25,7 +27,10 @@ export interface Modifier extends BaseModifier { export interface GroupModifier extends BaseModifier { id?: string; // id не обязательный для поддержки вирутальных групп childModifiers: Modifier[]; - group?: Group | any; + group?: Group | string; groupId?: string; isSingleModifierGroupWrapper?: boolean; } + + + diff --git a/models/Dish.d.ts b/models/Dish.d.ts index 80ae3b80..1f904d7d 100644 --- a/models/Dish.d.ts +++ b/models/Dish.d.ts @@ -52,7 +52,6 @@ declare let attributes: { /** */ productCategoryId: string; /** Type */ - type: string; /** Weight */ weight: number; /** Sorting order */ diff --git a/models/Dish.js b/models/Dish.js index 2cf36dd5..1c0e3ff8 100644 --- a/models/Dish.js +++ b/models/Dish.js @@ -62,19 +62,40 @@ let attributes = { /** The amount of carbohydrates per (100g)*/ carbohydrateAmount: "number", /** The amount of carbohydrates in the dish */ - carbohydrateFullAmount: "number", + carbohydrateFullAmount: { + type: "number", + allowNull: true + }, /** Energy value (100 g) */ - energyAmount: "number", + energyAmount: { + type: "number", + allowNull: true + }, /** Energy value */ - energyFullAmount: "number", + energyFullAmount: { + type: "number", + allowNull: true + }, /** The amount of fat (100 g) */ - fatAmount: "number", + fatAmount: { + type: "number", + allowNull: true + }, /** The amount of fat in the dish */ - fatFullAmount: "number", + fatFullAmount: { + type: "number", + allowNull: true + }, /** The number of proteins (100g) */ - fiberAmount: "number", + fiberAmount: { + type: "number", + allowNull: true + }, /** The amount of proteins in the dish */ - fiberFullAmount: "number", + fiberFullAmount: { + type: "number", + allowNull: true + }, /** The group identifier in which the dish is located */ groupId: { type: "string", @@ -93,9 +114,12 @@ let attributes = { allowNull: true, }, /** Type */ - type: "string", + // type: "string", //TODO: ??? /** Weight */ - weight: "number", + weight: { + type: "number", + allowNull: true + }, /** Sorting order */ sortOrder: "number", /** The dish is removed */ diff --git a/models/Dish.ts b/models/Dish.ts index 5e1246ab..fe02d4f3 100644 --- a/models/Dish.ts +++ b/models/Dish.ts @@ -83,25 +83,46 @@ let attributes = { carbohydrateAmount: "number" as unknown as number, /** The amount of carbohydrates in the dish */ - carbohydrateFullAmount: "number" as unknown as number, + carbohydrateFullAmount: { + type: "number", + allowNull: true + } as unknown as number, /** Energy value (100 g) */ - energyAmount: "number" as unknown as number, + energyAmount: { + type: "number", + allowNull: true + } as unknown as number, /** Energy value */ - energyFullAmount: "number" as unknown as number, + energyFullAmount: { + type: "number", + allowNull: true + } as unknown as number, /** The amount of fat (100 g) */ - fatAmount: "number" as unknown as number, + fatAmount: { + type: "number", + allowNull: true + } as unknown as number, /** The amount of fat in the dish */ - fatFullAmount: "number" as unknown as number, + fatFullAmount: { + type: "number", + allowNull: true + } as unknown as number, /** The number of proteins (100g) */ - fiberAmount: "number" as unknown as number, + fiberAmount: { + type: "number", + allowNull: true + } as unknown as number, /** The amount of proteins in the dish */ - fiberFullAmount: "number" as unknown as number, + fiberFullAmount: { + type: "number", + allowNull: true + } as unknown as number, /** The group identifier in which the dish is located */ groupId: { @@ -125,10 +146,13 @@ let attributes = { } as unknown as string, /** Type */ - type: "string", //TODO: ??? + // type: "string", //TODO: ??? /** Weight */ - weight: "number" as unknown as number, + weight: { + type: "number", + allowNull: true + } as unknown as number, /** Sorting order */ sortOrder: "number" as unknown as number, diff --git a/models/Group.d.ts b/models/Group.d.ts index c70e1284..e1097b13 100644 --- a/models/Group.d.ts +++ b/models/Group.d.ts @@ -26,7 +26,7 @@ declare let attributes: { sortOrder: number; dishes: Dish[]; parentGroup: any; - childGroups: Group[] | string[]; + childGroups: string[] | Group[]; /** Icon */ icon: { type: string; diff --git a/models/Settings.js b/models/Settings.js index 308e2201..0553d91c 100644 --- a/models/Settings.js +++ b/models/Settings.js @@ -89,7 +89,7 @@ let Model = { return value; } } - sails.log.warn(`Settings: ( ${key} ) not found`); + sails.log.silly(`Settings: ( ${key} ) not found`); return undefined; }, async get(key) { @@ -159,6 +159,10 @@ module.exports = { ...Model, }; function toScreamingSnake(str) { + if (!str) { + console.log("STR", str); + return ''; + } // Test123___Test_test -> TEST123_TEST_TEST return str.replace(/\.?([A-Z]+)/g, function (x, y) { return "_" + y.toLowerCase(); }).replace(/^_/, "").replace(/_{1,}/g, "_").toUpperCase(); } diff --git a/models/Settings.ts b/models/Settings.ts index d3d19751..2343c86a 100644 --- a/models/Settings.ts +++ b/models/Settings.ts @@ -116,7 +116,7 @@ let Model = { return value; } } - sails.log.warn(`Settings: ( ${key} ) not found`); + sails.log.silly(`Settings: ( ${key} ) not found`); return undefined; }, @@ -197,6 +197,12 @@ declare global { function toScreamingSnake(str: string): string { + if (!str) { + console.log("STR", str) + return ''; + } + // Test123___Test_test -> TEST123_TEST_TEST return str.replace(/\.?([A-Z]+)/g, function (x,y){return "_" + y.toLowerCase()}).replace(/^_/, "").replace(/_{1,}/g,"_").toUpperCase(); -} \ No newline at end of file +} +