storemw-core-api 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.d.ts +2 -0
- package/dist/app.js +46 -0
- package/dist/configs/config.d.ts +7 -0
- package/dist/configs/config.js +30 -0
- package/dist/configs/index.d.ts +1 -0
- package/dist/configs/index.js +5 -0
- package/dist/configs/production.env +6 -0
- package/dist/controllers/auth/authController.d.ts +3 -0
- package/dist/controllers/auth/authController.js +53 -0
- package/dist/controllers/index.d.ts +6 -0
- package/dist/controllers/index.js +39 -0
- package/dist/controllers/injection_field/injectionFieldController.d.ts +11 -0
- package/dist/controllers/injection_field/injectionFieldController.js +183 -0
- package/dist/controllers/item/itemController.d.ts +13 -0
- package/dist/controllers/item/itemController.js +344 -0
- package/dist/controllers/location/locationController.d.ts +13 -0
- package/dist/controllers/location/locationController.js +383 -0
- package/dist/controllers/region/regionController.d.ts +13 -0
- package/dist/controllers/region/regionController.js +328 -0
- package/dist/controllers/user/userController.d.ts +13 -0
- package/dist/controllers/user/userController.js +474 -0
- package/dist/generated/generated/prisma/client.d.ts +1 -0
- package/dist/generated/generated/prisma/client.js +4 -0
- package/dist/generated/generated/prisma/default.d.ts +1 -0
- package/dist/generated/generated/prisma/default.js +4 -0
- package/dist/generated/generated/prisma/edge.d.ts +1 -0
- package/dist/generated/generated/prisma/edge.js +2470 -0
- package/dist/generated/generated/prisma/index-browser.js +2456 -0
- package/dist/generated/generated/prisma/index.d.ts +198861 -0
- package/dist/generated/generated/prisma/index.js +2491 -0
- package/dist/generated/generated/prisma/libquery_engine-darwin-arm64.dylib.node +0 -0
- package/dist/generated/generated/prisma/package.json +183 -0
- package/dist/generated/generated/prisma/query_engine_bg.js +2 -0
- package/dist/generated/generated/prisma/query_engine_bg.wasm +0 -0
- package/dist/generated/generated/prisma/runtime/edge-esm.js +34 -0
- package/dist/generated/generated/prisma/runtime/edge.js +34 -0
- package/dist/generated/generated/prisma/runtime/index-browser.d.ts +370 -0
- package/dist/generated/generated/prisma/runtime/index-browser.js +16 -0
- package/dist/generated/generated/prisma/runtime/library.d.ts +3976 -0
- package/dist/generated/generated/prisma/runtime/library.js +146 -0
- package/dist/generated/generated/prisma/runtime/react-native.js +83 -0
- package/dist/generated/generated/prisma/runtime/wasm-compiler-edge.js +84 -0
- package/dist/generated/generated/prisma/runtime/wasm-engine-edge.js +36 -0
- package/dist/generated/generated/prisma/schema.prisma +2663 -0
- package/dist/generated/generated/prisma/wasm-edge-light-loader.mjs +4 -0
- package/dist/generated/generated/prisma/wasm-worker-loader.mjs +4 -0
- package/dist/generated/generated/prisma/wasm.d.ts +1 -0
- package/dist/generated/generated/prisma/wasm.js +2477 -0
- package/dist/generated/prisma/client.d.ts +1 -0
- package/dist/generated/prisma/client.js +4 -0
- package/dist/generated/prisma/default.d.ts +1 -0
- package/dist/generated/prisma/default.js +4 -0
- package/dist/generated/prisma/edge.d.ts +1 -0
- package/dist/generated/prisma/edge.js +2467 -0
- package/dist/generated/prisma/index-browser.js +2453 -0
- package/dist/generated/prisma/index.d.ts +185588 -0
- package/dist/generated/prisma/index.js +2488 -0
- package/dist/generated/prisma/libquery_engine-darwin-arm64.dylib.node +0 -0
- package/dist/generated/prisma/package.json +183 -0
- package/dist/generated/prisma/query_engine_bg.js +2 -0
- package/dist/generated/prisma/query_engine_bg.wasm +0 -0
- package/dist/generated/prisma/runtime/edge-esm.js +34 -0
- package/dist/generated/prisma/runtime/edge.js +34 -0
- package/dist/generated/prisma/runtime/index-browser.d.ts +370 -0
- package/dist/generated/prisma/runtime/index-browser.js +16 -0
- package/dist/generated/prisma/runtime/library.d.ts +3976 -0
- package/dist/generated/prisma/runtime/library.js +146 -0
- package/dist/generated/prisma/runtime/react-native.js +83 -0
- package/dist/generated/prisma/runtime/wasm-compiler-edge.js +84 -0
- package/dist/generated/prisma/runtime/wasm-engine-edge.js +36 -0
- package/dist/generated/prisma/schema.prisma +2597 -0
- package/dist/generated/prisma/wasm-edge-light-loader.mjs +4 -0
- package/dist/generated/prisma/wasm-worker-loader.mjs +4 -0
- package/dist/generated/prisma/wasm.d.ts +1 -0
- package/dist/generated/prisma/wasm.js +2474 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +5 -0
- package/dist/helpers/prismaHelper.d.ts +2 -0
- package/dist/helpers/prismaHelper.js +75 -0
- package/dist/helpers/unuse/queryHelper.d.ts +19 -0
- package/dist/helpers/unuse/queryHelper.js +60 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +13 -0
- package/dist/lib/prisma.d.ts +13 -0
- package/dist/lib/prisma.js +32 -0
- package/dist/middlewares/request/index.d.ts +3 -0
- package/dist/middlewares/request/index.js +12 -0
- package/dist/middlewares/request/initialPrisma.d.ts +2 -0
- package/dist/middlewares/request/initialPrisma.js +10 -0
- package/dist/middlewares/request/validateAuthorization.d.ts +2 -0
- package/dist/middlewares/request/validateAuthorization.js +40 -0
- package/dist/middlewares/request/validateCors.d.ts +6 -0
- package/dist/middlewares/request/validateCors.js +20 -0
- package/dist/middlewares/request/validateHeader.d.ts +2 -0
- package/dist/middlewares/request/validateHeader.js +49 -0
- package/dist/middlewares/request/validateSignature.d.ts +10 -0
- package/dist/middlewares/request/validateSignature.js +48 -0
- package/dist/middlewares/route/index.d.ts +6 -0
- package/dist/middlewares/route/index.js +33 -0
- package/dist/middlewares/route/validateAuth.d.ts +2 -0
- package/dist/middlewares/route/validateAuth.js +8 -0
- package/dist/middlewares/route/validateDocument.d.ts +2 -0
- package/dist/middlewares/route/validateDocument.js +33 -0
- package/dist/middlewares/route/validateInjectionField.d.ts +3 -0
- package/dist/middlewares/route/validateInjectionField.js +38 -0
- package/dist/middlewares/route/validateItem.d.ts +6 -0
- package/dist/middlewares/route/validateItem.js +23 -0
- package/dist/middlewares/route/validateLocation.d.ts +6 -0
- package/dist/middlewares/route/validateLocation.js +22 -0
- package/dist/middlewares/route/validateRegion.d.ts +5 -0
- package/dist/middlewares/route/validateRegion.js +39 -0
- package/dist/middlewares/route/validateRepository.d.ts +2 -0
- package/dist/middlewares/route/validateRepository.js +33 -0
- package/dist/middlewares/route/validateUser.d.ts +6 -0
- package/dist/middlewares/route/validateUser.js +23 -0
- package/dist/middlewares/unuse/errorHandler.d.ts +2 -0
- package/dist/middlewares/unuse/errorHandler.js +9 -0
- package/dist/models/ModelFactory.d.ts +38 -0
- package/dist/models/ModelFactory.js +137 -0
- package/dist/models/account/AccountModel.d.ts +144 -0
- package/dist/models/account/AccountModel.js +15 -0
- package/dist/models/branch/BranchModel.d.ts +259 -0
- package/dist/models/branch/BranchModel.js +15 -0
- package/dist/models/branch_user/BranchUserModel.d.ts +140 -0
- package/dist/models/branch_user/BranchUserModel.js +15 -0
- package/dist/models/business/BusinessModel.d.ts +214 -0
- package/dist/models/business/BusinessModel.js +15 -0
- package/dist/models/default.d.ts +41 -0
- package/dist/models/default.js +54 -0
- package/dist/models/group/GroupModel.d.ts +158 -0
- package/dist/models/group/GroupModel.js +15 -0
- package/dist/models/group/GroupOwnerModel.d.ts +151 -0
- package/dist/models/group/GroupOwnerModel.js +15 -0
- package/dist/models/index.d.ts +58 -0
- package/dist/models/index.js +91 -0
- package/dist/models/injection_field/DocumentInjectionFieldModel.d.ts +431 -0
- package/dist/models/injection_field/DocumentInjectionFieldModel.js +15 -0
- package/dist/models/injection_field/InjectionFieldModel.d.ts +193 -0
- package/dist/models/injection_field/InjectionFieldModel.js +46 -0
- package/dist/models/injection_field/ItemInjectionFieldModel.d.ts +347 -0
- package/dist/models/injection_field/ItemInjectionFieldModel.js +15 -0
- package/dist/models/injection_field/LogisticInjectionFieldModel.d.ts +158 -0
- package/dist/models/injection_field/LogisticInjectionFieldModel.js +15 -0
- package/dist/models/injection_field/RepositoryInjectionFieldModel.d.ts +193 -0
- package/dist/models/injection_field/RepositoryInjectionFieldModel.js +15 -0
- package/dist/models/injection_field/UserInjectionFieldModel.d.ts +263 -0
- package/dist/models/injection_field/UserInjectionFieldModel.js +15 -0
- package/dist/models/item/BrandModel.d.ts +147 -0
- package/dist/models/item/BrandModel.js +15 -0
- package/dist/models/item/CategoryModel.d.ts +154 -0
- package/dist/models/item/CategoryModel.js +15 -0
- package/dist/models/item/ItemModel.d.ts +294 -0
- package/dist/models/item/ItemModel.js +15 -0
- package/dist/models/item/ProductModel.d.ts +182 -0
- package/dist/models/item/ProductModel.js +15 -0
- package/dist/models/item/UomModel.d.ts +168 -0
- package/dist/models/item/UomModel.js +15 -0
- package/dist/models/location/LocationModel.d.ts +235 -0
- package/dist/models/location/LocationModel.js +15 -0
- package/dist/models/location/LocationRackModel.d.ts +172 -0
- package/dist/models/location/LocationRackModel.js +15 -0
- package/dist/models/location/LocationSlotModel.d.ts +165 -0
- package/dist/models/location/LocationSlotModel.js +15 -0
- package/dist/models/region/AreaModel.d.ts +154 -0
- package/dist/models/region/AreaModel.js +15 -0
- package/dist/models/region/CountryModel.d.ts +154 -0
- package/dist/models/region/CountryModel.js +15 -0
- package/dist/models/region/StateModel.d.ts +147 -0
- package/dist/models/region/StateModel.js +15 -0
- package/dist/models/user/AdministratorModel.d.ts +133 -0
- package/dist/models/user/AdministratorModel.js +15 -0
- package/dist/models/user/CustomerModel.d.ts +196 -0
- package/dist/models/user/CustomerModel.js +15 -0
- package/dist/models/user/UserModel.d.ts +189 -0
- package/dist/models/user/UserModel.js +15 -0
- package/dist/models/user/UserPropModel.d.ts +175 -0
- package/dist/models/user/UserPropModel.js +15 -0
- package/dist/models/user/UserStatusModel.d.ts +154 -0
- package/dist/models/user/UserStatusModel.js +15 -0
- package/dist/models/user/WorkerModel.d.ts +140 -0
- package/dist/models/user/WorkerModel.js +15 -0
- package/dist/models/user/bk_UserModel.d.ts +43 -0
- package/dist/models/user/bk_UserModel.js +79 -0
- package/dist/routes/auth/authRoutes.d.ts +1 -0
- package/dist/routes/auth/authRoutes.js +13 -0
- package/dist/routes/index.d.ts +11 -0
- package/dist/routes/index.js +25 -0
- package/dist/routes/injection_field/injectionFieldRoutes.d.ts +1 -0
- package/dist/routes/injection_field/injectionFieldRoutes.js +22 -0
- package/dist/routes/injection_field/injectionFieldsRoutes.d.ts +1 -0
- package/dist/routes/injection_field/injectionFieldsRoutes.js +15 -0
- package/dist/routes/item/itemRoutes.d.ts +1 -0
- package/dist/routes/item/itemRoutes.js +20 -0
- package/dist/routes/item/itemsRoutes.d.ts +1 -0
- package/dist/routes/item/itemsRoutes.js +15 -0
- package/dist/routes/location/locationRoutes.d.ts +1 -0
- package/dist/routes/location/locationRoutes.js +20 -0
- package/dist/routes/location/locationsRoutes.d.ts +1 -0
- package/dist/routes/location/locationsRoutes.js +25 -0
- package/dist/routes/region/regionRoutes.d.ts +1 -0
- package/dist/routes/region/regionRoutes.js +25 -0
- package/dist/routes/region/regionsRoutes.d.ts +1 -0
- package/dist/routes/region/regionsRoutes.js +33 -0
- package/dist/routes/user/userRoutes.d.ts +1 -0
- package/dist/routes/user/userRoutes.js +19 -0
- package/dist/routes/user/usersRoutes.d.ts +1 -0
- package/dist/routes/user/usersRoutes.js +15 -0
- package/dist/schema/common/index.d.ts +2 -0
- package/dist/schema/common/index.js +9 -0
- package/dist/schema/common/unuse/response.d.ts +54 -0
- package/dist/schema/common/unuse/response.js +22 -0
- package/dist/schema/middleware/request/index.d.ts +2 -0
- package/dist/schema/middleware/request/index.js +6 -0
- package/dist/schema/middleware/request/schemaAuthorization.d.ts +1 -0
- package/dist/schema/middleware/request/schemaAuthorization.js +8 -0
- package/dist/schema/middleware/request/schemaHeader.d.ts +9 -0
- package/dist/schema/middleware/request/schemaHeader.js +10 -0
- package/dist/schema/middleware/request/validateQuery_bk250827.d.ts +27 -0
- package/dist/schema/middleware/request/validateQuery_bk250827.js +62 -0
- package/dist/schema/middleware/route/index.d.ts +13 -0
- package/dist/schema/middleware/route/index.js +17 -0
- package/dist/schema/middleware/route/schemaDocument.d.ts +10 -0
- package/dist/schema/middleware/route/schemaDocument.js +9 -0
- package/dist/schema/middleware/route/schemaItem.d.ts +10 -0
- package/dist/schema/middleware/route/schemaItem.js +9 -0
- package/dist/schema/middleware/route/schemaLocation.d.ts +10 -0
- package/dist/schema/middleware/route/schemaLocation.js +9 -0
- package/dist/schema/middleware/route/schemaQueryList.d.ts +88 -0
- package/dist/schema/middleware/route/schemaQueryList.js +139 -0
- package/dist/schema/middleware/route/schemaRegion.d.ts +10 -0
- package/dist/schema/middleware/route/schemaRegion.js +9 -0
- package/dist/schema/middleware/route/schemaRepository.d.ts +10 -0
- package/dist/schema/middleware/route/schemaRepository.js +9 -0
- package/dist/schema/middleware/route/schemaUser.d.ts +10 -0
- package/dist/schema/middleware/route/schemaUser.js +9 -0
- package/dist/schema/payload/auth/schemaAuthToken.d.ts +43 -0
- package/dist/schema/payload/auth/schemaAuthToken.js +16 -0
- package/dist/schema/payload/index.d.ts +28 -0
- package/dist/schema/payload/index.js +48 -0
- package/dist/schema/payload/injection_field/schemaInjectionField.d.ts +548 -0
- package/dist/schema/payload/injection_field/schemaInjectionField.js +141 -0
- package/dist/schema/payload/item/schemaItem.d.ts +33 -0
- package/dist/schema/payload/item/schemaItem.js +13 -0
- package/dist/schema/payload/item/schemaItemBrand.d.ts +131 -0
- package/dist/schema/payload/item/schemaItemBrand.js +32 -0
- package/dist/schema/payload/item/schemaItemCategory.d.ts +145 -0
- package/dist/schema/payload/item/schemaItemCategory.js +34 -0
- package/dist/schema/payload/item/schemaItemItem.d.ts +244 -0
- package/dist/schema/payload/item/schemaItemItem.js +70 -0
- package/dist/schema/payload/item/schemaItemUom.d.ts +173 -0
- package/dist/schema/payload/item/schemaItemUom.js +38 -0
- package/dist/schema/payload/location/schemaLocationLocation.d.ts +297 -0
- package/dist/schema/payload/location/schemaLocationLocation.js +61 -0
- package/dist/schema/payload/region/schemaRegionArea.d.ts +91 -0
- package/dist/schema/payload/region/schemaRegionArea.js +32 -0
- package/dist/schema/payload/region/schemaRegionCountry.d.ts +62 -0
- package/dist/schema/payload/region/schemaRegionCountry.js +28 -0
- package/dist/schema/payload/region/schemaRegionState.d.ts +127 -0
- package/dist/schema/payload/region/schemaRegionState.js +44 -0
- package/dist/schema/payload/schemaUser.d.ts +101 -0
- package/dist/schema/payload/schemaUser.js +78 -0
- package/dist/schema/payload/user/schemaUser.d.ts +33 -0
- package/dist/schema/payload/user/schemaUser.js +13 -0
- package/dist/schema/payload/user/schemaUserAdministrator.d.ts +244 -0
- package/dist/schema/payload/user/schemaUserAdministrator.js +70 -0
- package/dist/schema/payload/user/schemaUserCustomer.d.ts +389 -0
- package/dist/schema/payload/user/schemaUserCustomer.js +70 -0
- package/dist/schema/payload/user/schemaUserWorker.d.ts +277 -0
- package/dist/schema/payload/user/schemaUserWorker.js +71 -0
- package/dist/services/account/AccountService.d.ts +28 -0
- package/dist/services/account/AccountService.js +152 -0
- package/dist/services/auth/AuthService.d.ts +39 -0
- package/dist/services/auth/AuthService.js +123 -0
- package/dist/services/branch/BranchService.d.ts +32 -0
- package/dist/services/branch/BranchService.js +120 -0
- package/dist/services/branch_user/BranchUserService.d.ts +12 -0
- package/dist/services/branch_user/BranchUserService.js +148 -0
- package/dist/services/index.d.ts +14 -0
- package/dist/services/index.js +21 -0
- package/dist/services/injection_field/DocumentInjectionFieldService.d.ts +135 -0
- package/dist/services/injection_field/DocumentInjectionFieldService.js +79 -0
- package/dist/services/injection_field/InjectionFieldService.d.ts +137 -0
- package/dist/services/injection_field/InjectionFieldService.js +266 -0
- package/dist/services/injection_field/ItemInjectionFieldService.d.ts +92 -0
- package/dist/services/injection_field/ItemInjectionFieldService.js +68 -0
- package/dist/services/injection_field/LogisticInjectionFieldService.d.ts +45 -0
- package/dist/services/injection_field/LogisticInjectionFieldService.js +72 -0
- package/dist/services/injection_field/RepositoryInjectionFieldService.d.ts +61 -0
- package/dist/services/injection_field/RepositoryInjectionFieldService.js +66 -0
- package/dist/services/injection_field/UserInjectionFieldService.d.ts +98 -0
- package/dist/services/injection_field/UserInjectionFieldService.js +79 -0
- package/dist/services/item/ItemBrandService.d.ts +84 -0
- package/dist/services/item/ItemBrandService.js +151 -0
- package/dist/services/item/ItemCategoryService.d.ts +89 -0
- package/dist/services/item/ItemCategoryService.js +234 -0
- package/dist/services/item/ItemItemService.d.ts +141 -0
- package/dist/services/item/ItemItemService.js +263 -0
- package/dist/services/item/ItemProductService.d.ts +146 -0
- package/dist/services/item/ItemProductService.js +284 -0
- package/dist/services/item/ItemService.d.ts +65 -0
- package/dist/services/item/ItemService.js +226 -0
- package/dist/services/item/ItemUomService.d.ts +101 -0
- package/dist/services/item/ItemUomService.js +159 -0
- package/dist/services/location/LocationLocationService.d.ts +144 -0
- package/dist/services/location/LocationLocationService.js +270 -0
- package/dist/services/location/LocationRackService.d.ts +98 -0
- package/dist/services/location/LocationRackService.js +275 -0
- package/dist/services/location/LocationService.d.ts +52 -0
- package/dist/services/location/LocationService.js +152 -0
- package/dist/services/location/LocationSlotService.d.ts +91 -0
- package/dist/services/location/LocationSlotService.js +142 -0
- package/dist/services/region/AreaService.d.ts +87 -0
- package/dist/services/region/AreaService.js +142 -0
- package/dist/services/region/CountryService.d.ts +103 -0
- package/dist/services/region/CountryService.js +155 -0
- package/dist/services/region/RegionService.d.ts +45 -0
- package/dist/services/region/RegionService.js +152 -0
- package/dist/services/region/StateService.d.ts +85 -0
- package/dist/services/region/StateService.js +189 -0
- package/dist/services/supabase/supabaseClient.d.ts +1 -0
- package/dist/services/supabase/supabaseClient.js +8 -0
- package/dist/services/user/AdministratorService.d.ts +73 -0
- package/dist/services/user/AdministratorService.js +263 -0
- package/dist/services/user/CustomerService.d.ts +123 -0
- package/dist/services/user/CustomerService.js +268 -0
- package/dist/services/user/UserPropService.d.ts +40 -0
- package/dist/services/user/UserPropService.js +139 -0
- package/dist/services/user/UserService.d.ts +92 -0
- package/dist/services/user/UserService.js +260 -0
- package/dist/services/user/WorkerService.d.ts +83 -0
- package/dist/services/user/WorkerService.js +227 -0
- package/dist/utils/dateUtils.d.ts +4 -0
- package/dist/utils/dateUtils.js +23 -0
- package/dist/utils/exceptionUtils.d.ts +8 -0
- package/dist/utils/exceptionUtils.js +25 -0
- package/dist/utils/index.d.ts +15 -0
- package/dist/utils/index.js +52 -0
- package/dist/utils/injectionFieldUtils.d.ts +1 -0
- package/dist/utils/injectionFieldUtils.js +22 -0
- package/dist/utils/jwtUtils.d.ts +3 -0
- package/dist/utils/jwtUtils.js +22 -0
- package/dist/utils/logUtils.d.ts +3 -0
- package/dist/utils/logUtils.js +60 -0
- package/dist/utils/queryBuilder.d.ts +74 -0
- package/dist/utils/queryBuilder.js +163 -0
- package/dist/utils/requestUtils.d.ts +3 -0
- package/dist/utils/requestUtils.js +11 -0
- package/dist/utils/responseUtils.d.ts +14 -0
- package/dist/utils/responseUtils.js +42 -0
- package/dist/utils/schemaUtils.d.ts +21 -0
- package/dist/utils/schemaUtils.js +95 -0
- package/dist/utils/serviceUtils.d.ts +12 -0
- package/dist/utils/serviceUtils.js +11 -0
- package/dist/utils/services/storage.d.ts +22 -0
- package/dist/utils/services/storage.js +64 -0
- package/dist/utils/shapeUtils.d.ts +1 -0
- package/dist/utils/shapeUtils.js +36 -0
- package/dist/utils/smwUtils.d.ts +1 -0
- package/dist/utils/smwUtils.js +9 -0
- package/dist/utils/zodUtils.d.ts +6 -0
- package/dist/utils/zodUtils.js +17 -0
- package/package.json +94 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocationLocationService = exports.locationLocationDataTypes = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const models_1 = require("../../models");
|
|
6
|
+
const utils_2 = require("../../utils");
|
|
7
|
+
exports.locationLocationDataTypes = {
|
|
8
|
+
rackSlot: "rack_slot",
|
|
9
|
+
// branch: "branch",
|
|
10
|
+
// locationArea: "location_area",
|
|
11
|
+
zoneCount: "zone_count",
|
|
12
|
+
rackCount: "rack_count"
|
|
13
|
+
};
|
|
14
|
+
const getCreatePayload = (data) => {
|
|
15
|
+
if ("location" in data) {
|
|
16
|
+
return {
|
|
17
|
+
[`${models_1.ModelLocationFields.is_default}`]: data.location.isDefault ? 1 : 0,
|
|
18
|
+
[`${models_1.ModelLocationFields.address_1}`]: data.location.address1,
|
|
19
|
+
[`${models_1.ModelLocationFields.address_2}`]: data.location.address2,
|
|
20
|
+
// [`${ModelLocationFields.area}`]: data.location.area,
|
|
21
|
+
[`${models_1.ModelLocationFields.area_id}`]: data.location.areaId,
|
|
22
|
+
[`${models_1.ModelLocationFields.country_id}`]: data.location.countryId,
|
|
23
|
+
[`${models_1.ModelLocationFields.state_id}`]: data.location.stateId,
|
|
24
|
+
[`${models_1.ModelLocationFields.postcode}`]: data.location.postcode,
|
|
25
|
+
[`${models_1.ModelLocationFields.location_code}`]: data.location.locationCode,
|
|
26
|
+
[`${models_1.ModelLocationFields.location_name}`]: data.location.locationName,
|
|
27
|
+
[`${models_1.ModelLocationFields.location_type}`]: data.location.locationType,
|
|
28
|
+
[`${models_1.ModelLocationFields.person_contact}`]: data.location.personContact,
|
|
29
|
+
[`${models_1.ModelLocationFields.person_email}`]: data.location.personEmail,
|
|
30
|
+
[`${models_1.ModelLocationFields.person_name}`]: data.location.personName,
|
|
31
|
+
[`${models_1.ModelLocationFields.status}`]: data.location.status ? 1 : 0,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
};
|
|
36
|
+
const getUpdatePayload = (data) => {
|
|
37
|
+
if ("location" in data) {
|
|
38
|
+
return {
|
|
39
|
+
[`${models_1.ModelLocationFields.is_default}`]: data.location.isDefault ? 1 : 0,
|
|
40
|
+
[`${models_1.ModelLocationFields.address_1}`]: data.location.address1,
|
|
41
|
+
[`${models_1.ModelLocationFields.address_1}`]: data.location.address1,
|
|
42
|
+
[`${models_1.ModelLocationFields.address_2}`]: data.location.address2,
|
|
43
|
+
// [`${ModelLocationFields.area}`]: data.location.area,
|
|
44
|
+
[`${models_1.ModelLocationFields.area_id}`]: data.location.areaId,
|
|
45
|
+
[`${models_1.ModelLocationFields.country_id}`]: data.location.countryId,
|
|
46
|
+
[`${models_1.ModelLocationFields.state_id}`]: data.location.stateId,
|
|
47
|
+
[`${models_1.ModelLocationFields.postcode}`]: data.location.postcode,
|
|
48
|
+
[`${models_1.ModelLocationFields.location_code}`]: data.location.locationCode,
|
|
49
|
+
[`${models_1.ModelLocationFields.location_name}`]: data.location.locationName,
|
|
50
|
+
[`${models_1.ModelLocationFields.location_type}`]: data.location.locationType,
|
|
51
|
+
[`${models_1.ModelLocationFields.person_contact}`]: data.location.personContact,
|
|
52
|
+
[`${models_1.ModelLocationFields.person_email}`]: data.location.personEmail,
|
|
53
|
+
[`${models_1.ModelLocationFields.person_name}`]: data.location.personName,
|
|
54
|
+
[`${models_1.ModelLocationFields.status}`]: data.location.status ? 1 : 0,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
};
|
|
59
|
+
let mainSqlSelect = {
|
|
60
|
+
[`locc.${models_1.ModelLocationFields.location_id}`]: "location_id",
|
|
61
|
+
[`locc.${models_1.ModelLocationFields.location_code}`]: "location_code",
|
|
62
|
+
[`locc.${models_1.ModelLocationFields.location_name}`]: "location_name",
|
|
63
|
+
[`locc.${models_1.ModelLocationFields.location_type}`]: "location_type",
|
|
64
|
+
[`locc.${models_1.ModelLocationFields.address_1}`]: "address_1",
|
|
65
|
+
[`locc.${models_1.ModelLocationFields.address_2}`]: "address_2",
|
|
66
|
+
[`locc.${models_1.ModelLocationFields.area_id}`]: "area_id",
|
|
67
|
+
[`locc.${models_1.ModelLocationFields.country_id}`]: "country_id",
|
|
68
|
+
[`locc.${models_1.ModelLocationFields.is_default}`]: "is_default",
|
|
69
|
+
[`locc.${models_1.ModelLocationFields.person_contact}`]: "person_contact",
|
|
70
|
+
[`locc.${models_1.ModelLocationFields.person_email}`]: "person_email",
|
|
71
|
+
[`locc.${models_1.ModelLocationFields.person_name}`]: "person_name",
|
|
72
|
+
};
|
|
73
|
+
let regionSqlSelect = {
|
|
74
|
+
[`ctry.${models_1.ModelCountryFields.country_name}`]: "country_name",
|
|
75
|
+
[`state.${models_1.ModelStateFields.state_name}`]: "state_name",
|
|
76
|
+
[`area.${models_1.ModelAreaFields.area_name}`]: "area_name",
|
|
77
|
+
};
|
|
78
|
+
let defaultSqlSelect = {
|
|
79
|
+
[`locc.${models_1.ModelLocationFields.createdatetime}`]: "createdatetime",
|
|
80
|
+
[`creator.${models_1.ModelUserFields.login_username}`]: "createusername",
|
|
81
|
+
[`locc.${models_1.ModelLocationFields.updatedatetime}`]: "updatedatetime",
|
|
82
|
+
[`updater.${models_1.ModelUserFields.login_username}`]: "updateusername",
|
|
83
|
+
[`locc.${models_1.ModelLocationFields.isdelete}`]: "isdelete",
|
|
84
|
+
[`locc.${models_1.ModelLocationFields.istrash}`]: "istrash",
|
|
85
|
+
[`locc.${models_1.ModelLocationFields.accountid}`]: "accountid",
|
|
86
|
+
};
|
|
87
|
+
const LocationLocationService = (props) => {
|
|
88
|
+
const { prisma, accountId = 0, actionUserId = 0 } = props;
|
|
89
|
+
const locationModel = (0, models_1.LocationModel)({ prisma, accountId, actionUserId });
|
|
90
|
+
const createLocation = async ({ data }) => {
|
|
91
|
+
const _data = getCreatePayload(data);
|
|
92
|
+
if (!_data) {
|
|
93
|
+
throw new Error(`Invalid create customer payload: ${JSON.stringify(_data)}`);
|
|
94
|
+
}
|
|
95
|
+
let response = await locationModel.create({ data: _data });
|
|
96
|
+
return response;
|
|
97
|
+
};
|
|
98
|
+
const updateLocation = async ({ locationId, data }) => {
|
|
99
|
+
const _data = getUpdatePayload(data);
|
|
100
|
+
if (!_data) {
|
|
101
|
+
throw new Error(`Invalid update location payload: ${JSON.stringify(_data)}`);
|
|
102
|
+
}
|
|
103
|
+
let response = await locationModel.update({ where: { [`${models_1.ModelLocationFields.location_id}`]: locationId }, data: _data });
|
|
104
|
+
return response;
|
|
105
|
+
};
|
|
106
|
+
const getLocation = async ({ id, datatypes = [] }) => {
|
|
107
|
+
let { data } = await listLocations({
|
|
108
|
+
limit: 1,
|
|
109
|
+
offset: 0,
|
|
110
|
+
filters: [{ field: "location_id", operator: "=", value: id }],
|
|
111
|
+
sortfield: "location_id",
|
|
112
|
+
sortorder: "ASC",
|
|
113
|
+
datatypes
|
|
114
|
+
});
|
|
115
|
+
return data[0] ?? null;
|
|
116
|
+
};
|
|
117
|
+
const listLocations = async ({ limit, offset, filters, sortfield, sortorder, datatypes = [] }) => {
|
|
118
|
+
let data = [];
|
|
119
|
+
let sqlSelect = [
|
|
120
|
+
`COUNT(locc.*) OVER() as filtered_count`,
|
|
121
|
+
(0, utils_2.buildSqlSelect)(``, mainSqlSelect),
|
|
122
|
+
(0, utils_2.buildSqlSelect)(``, regionSqlSelect),
|
|
123
|
+
(0, utils_2.buildSqlSelect)(``, defaultSqlSelect)
|
|
124
|
+
];
|
|
125
|
+
let sqlRelation = [
|
|
126
|
+
(0, utils_2.buildSqlRelation)("left", "locc", "countries", "ctry", ["locc.country_id = ctry.country_id", "ctry.isdelete = false", "ctry.istrash = false"]),
|
|
127
|
+
(0, utils_2.buildSqlRelation)("left", "locc", "states", "state", ["locc.state_id = state.state_id", "state.isdelete = false", "state.istrash = false"]),
|
|
128
|
+
(0, utils_2.buildSqlRelation)("left", "locc", "areas", "area", ["locc.area_id = area.area_id", "area.isdelete = false", "area.istrash = false"]),
|
|
129
|
+
(0, utils_2.buildSqlRelation)("left", "locc", "users", "creator", ["locc.createuserid = creator.user_id", "creator.isdelete = false", "creator.istrash = false"]),
|
|
130
|
+
(0, utils_2.buildSqlRelation)("left", "locc", "users", "updater", ["locc.updateuserid = updater.user_id", "updater.isdelete = false", "updater.istrash = false"])
|
|
131
|
+
];
|
|
132
|
+
let sqlGroupBy = [...Object.keys(mainSqlSelect), ...Object.keys(regionSqlSelect), ...Object.keys(defaultSqlSelect)];
|
|
133
|
+
let filterColumns = { ...mainSqlSelect, ...regionSqlSelect, ...defaultSqlSelect };
|
|
134
|
+
// if (datatypes.includes(locationLocationDataTypes.customerInjectionFields)) {
|
|
135
|
+
// let injectionFieldSqlSelect = {
|
|
136
|
+
// [`uip.usr_cust_cust_qty`]: "inf_usr_cust_cust_qty",
|
|
137
|
+
// // [`uip.${ModelUserFields.login_username}`]: "login_username",
|
|
138
|
+
// // [`uip.${ModelUserFields.user_type}`]: "user_type",
|
|
139
|
+
// // [`uip.${ModelUserFields.firstname}`]: "firstname",
|
|
140
|
+
// // [`uip.${ModelUserFields.lastname}`]: "lastname",
|
|
141
|
+
// // [`uip.${ModelUserFields.contact}`]: "contact",
|
|
142
|
+
// // [`uip.${ModelUserFields.email}`]: "email",
|
|
143
|
+
// }
|
|
144
|
+
// filterColumns = { ...filterColumns, ...injectionFieldSqlSelect }
|
|
145
|
+
// sqlSelect = [...sqlSelect, buildSqlSelect(``, injectionFieldSqlSelect)]
|
|
146
|
+
// sqlRelation = [...sqlRelation, buildSqlRelation("left", "locc", "user_injection_fields", "uip", ["locc.user_id = uip.user_id", "uip.field_ref = 'user'", "uip.isdelete = false", "uip.istrash = false"])]
|
|
147
|
+
// sqlGroupBy = [...sqlGroupBy, ...Object.keys(injectionFieldSqlSelect)]
|
|
148
|
+
// }
|
|
149
|
+
// if (datatypes.includes(locationLocationDataTypes.branch)) {
|
|
150
|
+
// let branchSqlSelect = {
|
|
151
|
+
// [`COALESCE(
|
|
152
|
+
// JSON_AGG(
|
|
153
|
+
// DISTINCT JSONB_BUILD_OBJECT(
|
|
154
|
+
// '${ModelBranchFields.type}', brn.type,
|
|
155
|
+
// '${ModelBranchFields.branch_id}', brn.branch_id,
|
|
156
|
+
// '${ModelBranchFields.branch_code}', brn.branch_code,
|
|
157
|
+
// '${ModelBranchFields.branch_name}', brn.branch_name,
|
|
158
|
+
// '${ModelBranchFields.address_1}', brn.address_1,
|
|
159
|
+
// '${ModelBranchFields.address_2}', brn.address_2,
|
|
160
|
+
// '${ModelBranchFields.area}', brn.area,
|
|
161
|
+
// '${ModelBranchFields.area_id}', brn.area_id,
|
|
162
|
+
// '${ModelBranchFields.branch_contact}', brn.branch_contact,
|
|
163
|
+
// '${ModelBranchFields.branch_email}', brn.branch_email,
|
|
164
|
+
// '${ModelBranchFields.country_id}', brn.country_id,
|
|
165
|
+
// '${ModelBranchFields.is_hq}', brn.is_hq,
|
|
166
|
+
// '${ModelBranchFields.remark}', brn.remark,
|
|
167
|
+
// '${ModelBranchFields.pic_contact}', brn.pic_contact,
|
|
168
|
+
// '${ModelBranchFields.pic_email}', brn.pic_email,
|
|
169
|
+
// '${ModelBranchFields.pic_contact}', brn.pic_contact,
|
|
170
|
+
// '${ModelBranchFields.postcode}', brn.postcode,
|
|
171
|
+
// '${ModelBranchFields.state_id}', brn.state_id,
|
|
172
|
+
// '${ModelBranchFields.status}', brn.status,
|
|
173
|
+
// '${ModelBranchFields.user_id}', brn.user_id
|
|
174
|
+
// )
|
|
175
|
+
// ) FILTER (WHERE brn.branch_id IS NOT NULL AND brn.isdelete = false AND brn.istrash = false),
|
|
176
|
+
// '[]'
|
|
177
|
+
// )`]: "branches"
|
|
178
|
+
// }
|
|
179
|
+
// filterColumns = { ...filterColumns, ...branchSqlSelect }
|
|
180
|
+
// sqlSelect = [...sqlSelect, buildSqlSelect(``, branchSqlSelect)]
|
|
181
|
+
// sqlRelation = [...sqlRelation, buildSqlRelation("left", "locc", "branches", "brn", ["locc.user_id = brn.user_id", "brn.isdelete = false", "brn.istrash = false"])]
|
|
182
|
+
// }
|
|
183
|
+
if (datatypes.includes(exports.locationLocationDataTypes.rackSlot)) {
|
|
184
|
+
let rackSlotSqlSelect = {
|
|
185
|
+
[`COALESCE(
|
|
186
|
+
JSON_AGG(
|
|
187
|
+
DISTINCT JSONB_BUILD_OBJECT(
|
|
188
|
+
'${models_1.ModelLocationRackFields.is_default}', loccrack1.is_default,
|
|
189
|
+
'${models_1.ModelLocationRackFields.location_rack_id}', loccrack1.location_rack_id,
|
|
190
|
+
'${models_1.ModelLocationRackFields.rack_name}', loccrack1.rack_name,
|
|
191
|
+
'${models_1.ModelLocationRackFields.rack_sequence}', loccrack1.rack_sequence,
|
|
192
|
+
'${models_1.ModelLocationRackFields.rack_type}', loccrack1.rack_type,
|
|
193
|
+
'slots', COALESCE(
|
|
194
|
+
(
|
|
195
|
+
SELECT JSON_AGG(
|
|
196
|
+
JSONB_BUILD_OBJECT(
|
|
197
|
+
'${models_1.ModelLocationSlotFields.location_slot_id}', loccslot1.location_slot_id,
|
|
198
|
+
'${models_1.ModelLocationSlotFields.rack_id}', loccslot1.rack_id,
|
|
199
|
+
'${models_1.ModelLocationSlotFields.slot_name}', loccslot1.slot_name,
|
|
200
|
+
'${models_1.ModelLocationSlotFields.slot_sequence}', loccslot1.slot_sequence,
|
|
201
|
+
'${models_1.ModelLocationSlotFields.status}', loccslot1.status
|
|
202
|
+
)
|
|
203
|
+
)
|
|
204
|
+
FROM location_slots loccslot1
|
|
205
|
+
WHERE loccslot1.rack_id = loccrack1.location_rack_id
|
|
206
|
+
AND loccslot1.isdelete = false
|
|
207
|
+
AND loccslot1.istrash = false
|
|
208
|
+
), '[]'::json
|
|
209
|
+
)
|
|
210
|
+
)
|
|
211
|
+
) FILTER (WHERE loccrack1.location_rack_id IS NOT NULL AND loccrack1.isdelete = false AND loccrack1.istrash = false),
|
|
212
|
+
'[]'
|
|
213
|
+
)`]: "racks"
|
|
214
|
+
};
|
|
215
|
+
filterColumns = { ...filterColumns, ...rackSlotSqlSelect };
|
|
216
|
+
sqlSelect = [...sqlSelect, (0, utils_2.buildSqlSelect)(``, rackSlotSqlSelect)];
|
|
217
|
+
sqlRelation = [...sqlRelation, (0, utils_2.buildSqlRelation)("left", "locc", "location_racks", "loccrack1", ["locc.location_id = loccrack1.location_id", "loccrack1.isdelete = false", "loccrack1.istrash = false"])];
|
|
218
|
+
}
|
|
219
|
+
if (datatypes.includes(exports.locationLocationDataTypes.rackCount)) {
|
|
220
|
+
let zoneCountSqlSelect = {
|
|
221
|
+
[`COUNT(DISTINCT loccrack.${models_1.ModelLocationRackFields.location_rack_id})::INT`]: "rack_count"
|
|
222
|
+
};
|
|
223
|
+
filterColumns = { ...filterColumns, ...zoneCountSqlSelect };
|
|
224
|
+
sqlSelect = [...sqlSelect, (0, utils_2.buildSqlSelect)(``, zoneCountSqlSelect)];
|
|
225
|
+
sqlRelation = [...sqlRelation, (0, utils_2.buildSqlRelation)("left", "locc", "location_racks", "loccrack", ["locc.location_id = loccrack.location_id", "loccrack.isdelete = false", "loccrack.istrash = false"])];
|
|
226
|
+
}
|
|
227
|
+
let sqlWhere = [
|
|
228
|
+
`locc.isdelete = false`,
|
|
229
|
+
`locc.istrash = false`,
|
|
230
|
+
...(filters.length ? [(0, utils_2.buildSqlWhere)(filters, filterColumns)] : []),
|
|
231
|
+
];
|
|
232
|
+
let sqlOrderby = (0, utils_2.buildSqlOrderBy)(sortfield, sortorder);
|
|
233
|
+
let sqlLimitOffset = (0, utils_2.buildSqlLimitOffset)(limit, offset);
|
|
234
|
+
const sqlRaw = (0, utils_2.buildSqlRawSelect)({
|
|
235
|
+
tableName: "locations",
|
|
236
|
+
mainAlias: "locc",
|
|
237
|
+
accountId,
|
|
238
|
+
sqlSelect,
|
|
239
|
+
sqlRelation,
|
|
240
|
+
sqlWhere,
|
|
241
|
+
sqlGroupBy,
|
|
242
|
+
sqlOrderby,
|
|
243
|
+
sqlLimitOffset
|
|
244
|
+
});
|
|
245
|
+
data = await locationModel.raw(sqlRaw);
|
|
246
|
+
const response = {
|
|
247
|
+
data: data.map(({ filtered_count, ...rest }) => rest),
|
|
248
|
+
total: data.length ? Number(data[0].filtered_count) : 0
|
|
249
|
+
};
|
|
250
|
+
return response;
|
|
251
|
+
};
|
|
252
|
+
const removeLocations = async ({ locationIds }) => {
|
|
253
|
+
if (!locationIds.length)
|
|
254
|
+
(0, utils_1.throwError)('locationIds is required');
|
|
255
|
+
const response = await locationModel.remove({ where: { [`${models_1.ModelLocationFields.location_id}`]: { in: locationIds } } });
|
|
256
|
+
return response;
|
|
257
|
+
};
|
|
258
|
+
const getDataTypes = () => {
|
|
259
|
+
return Object.values(exports.locationLocationDataTypes);
|
|
260
|
+
};
|
|
261
|
+
return {
|
|
262
|
+
createLocation,
|
|
263
|
+
updateLocation,
|
|
264
|
+
getLocation,
|
|
265
|
+
listLocations,
|
|
266
|
+
removeLocations,
|
|
267
|
+
getDataTypes
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
exports.LocationLocationService = LocationLocationService;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { QueryList, QueryGet } from "../../schema/common";
|
|
2
|
+
import { DefaultServiceProps } from "../../utils";
|
|
3
|
+
export type LocationType = "rack";
|
|
4
|
+
export declare const locationRackDataTypes: {};
|
|
5
|
+
export type LocationRackDataType = keyof typeof locationRackDataTypes;
|
|
6
|
+
export type LocationRackServiceProps = DefaultServiceProps & {};
|
|
7
|
+
export type LocationRackGetProps = QueryGet & {
|
|
8
|
+
id: number;
|
|
9
|
+
datatypes: LocationRackDataType[];
|
|
10
|
+
};
|
|
11
|
+
export type LocationRackListProps = QueryList & {
|
|
12
|
+
datatypes: LocationRackDataType[];
|
|
13
|
+
};
|
|
14
|
+
export type LocationRackRemoveProps = {
|
|
15
|
+
locationRackIds: BigInt[];
|
|
16
|
+
};
|
|
17
|
+
export type LocationRackCreateProps = {
|
|
18
|
+
data: {
|
|
19
|
+
rack: {
|
|
20
|
+
rackId: number;
|
|
21
|
+
isDefault: boolean;
|
|
22
|
+
locationId: number;
|
|
23
|
+
rackName: string;
|
|
24
|
+
rackSequence: number;
|
|
25
|
+
rackType: "normal" | "reserve";
|
|
26
|
+
status: boolean;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export type LocationRackUpdateProps = {
|
|
31
|
+
locationRackId: number;
|
|
32
|
+
data: {
|
|
33
|
+
rack: {
|
|
34
|
+
isDefault: boolean;
|
|
35
|
+
locationId: number;
|
|
36
|
+
rackName: string;
|
|
37
|
+
rackSequence: number;
|
|
38
|
+
rackType: "normal" | "reserve";
|
|
39
|
+
status: boolean;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export declare const LocationRackService: (props: LocationRackServiceProps) => {
|
|
44
|
+
createLocationRack: ({ data }: LocationRackCreateProps) => Promise<{
|
|
45
|
+
status: number;
|
|
46
|
+
createdatetime: Date | null;
|
|
47
|
+
createuserid: bigint;
|
|
48
|
+
updatedatetime: Date | null;
|
|
49
|
+
updateuserid: bigint;
|
|
50
|
+
isdelete: boolean | null;
|
|
51
|
+
istrash: boolean | null;
|
|
52
|
+
accountid: bigint;
|
|
53
|
+
location_id: bigint;
|
|
54
|
+
is_default: number | null;
|
|
55
|
+
location_rack_id: bigint;
|
|
56
|
+
rack_name: string;
|
|
57
|
+
rack_sequence: bigint | null;
|
|
58
|
+
rack_type: string | null;
|
|
59
|
+
}>;
|
|
60
|
+
updateLocationRack: ({ locationRackId, data }: LocationRackUpdateProps) => Promise<{
|
|
61
|
+
status: number;
|
|
62
|
+
createdatetime: Date | null;
|
|
63
|
+
createuserid: bigint;
|
|
64
|
+
updatedatetime: Date | null;
|
|
65
|
+
updateuserid: bigint;
|
|
66
|
+
isdelete: boolean | null;
|
|
67
|
+
istrash: boolean | null;
|
|
68
|
+
accountid: bigint;
|
|
69
|
+
location_id: bigint;
|
|
70
|
+
is_default: number | null;
|
|
71
|
+
location_rack_id: bigint;
|
|
72
|
+
rack_name: string;
|
|
73
|
+
rack_sequence: bigint | null;
|
|
74
|
+
rack_type: string | null;
|
|
75
|
+
}>;
|
|
76
|
+
getLocationRack: ({ id, datatypes }: LocationRackGetProps) => Promise<any>;
|
|
77
|
+
listLocationRacks: ({ limit, offset, filters, sortfield, sortorder, datatypes }: LocationRackListProps) => Promise<{
|
|
78
|
+
data: any[];
|
|
79
|
+
total: number;
|
|
80
|
+
}>;
|
|
81
|
+
removeLocationRacks: ({ locationRackIds }: LocationRackRemoveProps) => Promise<{
|
|
82
|
+
status: number;
|
|
83
|
+
createdatetime: Date | null;
|
|
84
|
+
createuserid: bigint;
|
|
85
|
+
updatedatetime: Date | null;
|
|
86
|
+
updateuserid: bigint;
|
|
87
|
+
isdelete: boolean | null;
|
|
88
|
+
istrash: boolean | null;
|
|
89
|
+
accountid: bigint;
|
|
90
|
+
location_id: bigint;
|
|
91
|
+
is_default: number | null;
|
|
92
|
+
location_rack_id: bigint;
|
|
93
|
+
rack_name: string;
|
|
94
|
+
rack_sequence: bigint | null;
|
|
95
|
+
rack_type: string | null;
|
|
96
|
+
}[]>;
|
|
97
|
+
getDataTypes: () => unknown[];
|
|
98
|
+
};
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocationRackService = exports.locationRackDataTypes = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const models_1 = require("../../models");
|
|
6
|
+
const utils_2 = require("../../utils");
|
|
7
|
+
exports.locationRackDataTypes = {
|
|
8
|
+
// customerInjectionFields: "customer_injection_fields",
|
|
9
|
+
// branch: "branch",
|
|
10
|
+
// branchCount: "branch_count",
|
|
11
|
+
// shippingAddress: "shipping_address",
|
|
12
|
+
// shippingAddressCount: "shipping_address_count",
|
|
13
|
+
// branchUserCount: "branch_user_count",
|
|
14
|
+
};
|
|
15
|
+
const getCreatePayload = (data) => {
|
|
16
|
+
if ("rack" in data) {
|
|
17
|
+
return {
|
|
18
|
+
[`${models_1.ModelLocationRackFields.is_default}`]: data.rack.isDefault ? 1 : 0,
|
|
19
|
+
[`${models_1.ModelLocationRackFields.location_id}`]: data.rack.locationId,
|
|
20
|
+
[`${models_1.ModelLocationRackFields.rack_name}`]: data.rack.rackName,
|
|
21
|
+
[`${models_1.ModelLocationRackFields.rack_sequence}`]: data.rack.rackSequence,
|
|
22
|
+
[`${models_1.ModelLocationRackFields.rack_type}`]: data.rack.rackType,
|
|
23
|
+
[`${models_1.ModelLocationRackFields.status}`]: data.rack.status ? 1 : 0,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
};
|
|
28
|
+
const getUpdatePayload = (data) => {
|
|
29
|
+
if ("rack" in data) {
|
|
30
|
+
return {
|
|
31
|
+
// [`${ModelLocationRackFields.location_id}`]: data.rack.locationId,
|
|
32
|
+
[`${models_1.ModelLocationRackFields.is_default}`]: data.rack.isDefault ? 1 : 0,
|
|
33
|
+
[`${models_1.ModelLocationRackFields.rack_name}`]: data.rack.rackName,
|
|
34
|
+
[`${models_1.ModelLocationRackFields.rack_sequence}`]: data.rack.rackSequence,
|
|
35
|
+
[`${models_1.ModelLocationRackFields.rack_type}`]: data.rack.rackType,
|
|
36
|
+
[`${models_1.ModelLocationRackFields.status}`]: data.rack.status ? 1 : 0,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
};
|
|
41
|
+
let mainSqlSelect = {
|
|
42
|
+
[`locr.${models_1.ModelLocationRackFields.location_rack_id}`]: "location_rack_id",
|
|
43
|
+
[`locr.${models_1.ModelLocationRackFields.is_default}`]: "is_default",
|
|
44
|
+
[`locr.${models_1.ModelLocationRackFields.location_id}`]: "location_id",
|
|
45
|
+
[`locr.${models_1.ModelLocationRackFields.rack_name}`]: "rack_name",
|
|
46
|
+
[`locr.${models_1.ModelLocationRackFields.rack_sequence}`]: "rack_sequence",
|
|
47
|
+
[`locr.${models_1.ModelLocationRackFields.rack_type}`]: "rack_type",
|
|
48
|
+
[`locr.${models_1.ModelLocationRackFields.status}`]: "status"
|
|
49
|
+
};
|
|
50
|
+
let locationSqlSelect = {
|
|
51
|
+
[`locc.${models_1.ModelLocationFields.location_code}`]: "location_code",
|
|
52
|
+
[`locc.${models_1.ModelLocationFields.location_name}`]: "location_name",
|
|
53
|
+
[`locc.${models_1.ModelLocationFields.location_type}`]: "location_type",
|
|
54
|
+
};
|
|
55
|
+
let locationSlotSqlSelect = {
|
|
56
|
+
[`COALESCE(
|
|
57
|
+
STRING_AGG(locslot.${models_1.ModelLocationSlotFields.slot_name}::text, ', '),
|
|
58
|
+
''
|
|
59
|
+
)`]: "slots_lbl",
|
|
60
|
+
[`COALESCE(
|
|
61
|
+
STRING_AGG(locslot.${models_1.ModelLocationSlotFields.location_slot_id}::text, ', '),
|
|
62
|
+
''
|
|
63
|
+
)`]: "slots_ids",
|
|
64
|
+
[`COALESCE(
|
|
65
|
+
JSON_AGG(
|
|
66
|
+
DISTINCT JSONB_BUILD_OBJECT(
|
|
67
|
+
'${models_1.ModelLocationSlotFields.location_slot_id}', locslot.location_slot_id,
|
|
68
|
+
'${models_1.ModelLocationSlotFields.rack_id}', locslot.rack_id,
|
|
69
|
+
'${models_1.ModelLocationSlotFields.slot_name}', locslot.slot_name,
|
|
70
|
+
'${models_1.ModelLocationSlotFields.slot_sequence}', locslot.slot_sequence,
|
|
71
|
+
'${models_1.ModelLocationSlotFields.status}', locslot.status
|
|
72
|
+
)
|
|
73
|
+
) FILTER (WHERE locslot.rack_id IS NOT NULL AND locslot.isdelete = false AND locslot.istrash = false),
|
|
74
|
+
'[]'
|
|
75
|
+
)`]: "slots"
|
|
76
|
+
};
|
|
77
|
+
let defaultSqlSelect = {
|
|
78
|
+
[`locr.${models_1.ModelLocationRackFields.createdatetime}`]: "createdatetime",
|
|
79
|
+
[`creator.${models_1.ModelUserFields.login_username}`]: "createusername",
|
|
80
|
+
[`locr.${models_1.ModelLocationRackFields.updatedatetime}`]: "updatedatetime",
|
|
81
|
+
[`updater.${models_1.ModelUserFields.login_username}`]: "updateusername",
|
|
82
|
+
[`locr.${models_1.ModelLocationRackFields.isdelete}`]: "isdelete",
|
|
83
|
+
[`locr.${models_1.ModelLocationRackFields.istrash}`]: "istrash",
|
|
84
|
+
[`locr.${models_1.ModelLocationRackFields.accountid}`]: "accountid",
|
|
85
|
+
};
|
|
86
|
+
const LocationRackService = (props) => {
|
|
87
|
+
const { prisma, accountId = 0, actionUserId = 0 } = props;
|
|
88
|
+
const locationRackModel = (0, models_1.LocationRackModel)({ prisma, accountId, actionUserId });
|
|
89
|
+
const createLocationRack = async ({ data }) => {
|
|
90
|
+
const _data = getCreatePayload(data);
|
|
91
|
+
if (!_data) {
|
|
92
|
+
throw new Error(`Invalid create location rack payload: ${JSON.stringify(_data)}`);
|
|
93
|
+
}
|
|
94
|
+
let response = await locationRackModel.create({ data: _data });
|
|
95
|
+
return response;
|
|
96
|
+
};
|
|
97
|
+
const updateLocationRack = async ({ locationRackId, data }) => {
|
|
98
|
+
const _data = getUpdatePayload(data);
|
|
99
|
+
if (!_data) {
|
|
100
|
+
throw new Error(`Invalid update location rack payload: ${JSON.stringify(_data)}`);
|
|
101
|
+
}
|
|
102
|
+
let response = await locationRackModel.update({ where: { [`${models_1.ModelLocationRackFields.location_rack_id}`]: locationRackId }, data: _data });
|
|
103
|
+
return response;
|
|
104
|
+
};
|
|
105
|
+
const getLocationRack = async ({ id, datatypes = [] }) => {
|
|
106
|
+
let { data } = await listLocationRacks({
|
|
107
|
+
limit: 1,
|
|
108
|
+
offset: 0,
|
|
109
|
+
filters: [{ field: "location_rack_id", operator: "=", value: id }],
|
|
110
|
+
sortfield: "location_rack_id",
|
|
111
|
+
sortorder: "ASC",
|
|
112
|
+
datatypes
|
|
113
|
+
});
|
|
114
|
+
return data[0] ?? null;
|
|
115
|
+
};
|
|
116
|
+
const listLocationRacks = async ({ limit, offset, filters, sortfield, sortorder, datatypes = [] }) => {
|
|
117
|
+
let data = [];
|
|
118
|
+
let sqlSelect = [
|
|
119
|
+
`COUNT(locr.*) OVER() as filtered_count`,
|
|
120
|
+
(0, utils_2.buildSqlSelect)(``, mainSqlSelect),
|
|
121
|
+
(0, utils_2.buildSqlSelect)(``, locationSqlSelect),
|
|
122
|
+
(0, utils_2.buildSqlSelect)(``, locationSlotSqlSelect),
|
|
123
|
+
(0, utils_2.buildSqlSelect)(``, defaultSqlSelect)
|
|
124
|
+
];
|
|
125
|
+
let sqlRelation = [
|
|
126
|
+
(0, utils_2.buildSqlRelation)("left", "locr", "locations", "locc", ["locr.location_id = locc.location_id", "locc.isdelete = false", "locc.istrash = false"]),
|
|
127
|
+
(0, utils_2.buildSqlRelation)("left", "locr", "location_slots", "locslot", ["locr.location_rack_id = locslot.rack_id", "locslot.isdelete = false", "locslot.istrash = false"]),
|
|
128
|
+
(0, utils_2.buildSqlRelation)("left", "locr", "users", "creator", ["locr.createuserid = creator.user_id", "creator.isdelete = false", "creator.istrash = false"]),
|
|
129
|
+
(0, utils_2.buildSqlRelation)("left", "locr", "users", "updater", ["locr.updateuserid = updater.user_id", "updater.isdelete = false", "updater.istrash = false"])
|
|
130
|
+
];
|
|
131
|
+
let sqlGroupBy = [...Object.keys(mainSqlSelect), ...Object.keys(locationSqlSelect), ...Object.keys(defaultSqlSelect)];
|
|
132
|
+
let filterColumns = { ...mainSqlSelect, ...locationSqlSelect, ...defaultSqlSelect };
|
|
133
|
+
// if (datatypes.includes(locationRackDataTypes.customerInjectionFields)) {
|
|
134
|
+
// let injectionFieldSqlSelect = {
|
|
135
|
+
// [`uip.usr_cust_cust_qty`]: "inf_usr_cust_cust_qty",
|
|
136
|
+
// // [`uip.${ModelUserFields.login_username}`]: "login_username",
|
|
137
|
+
// // [`uip.${ModelUserFields.user_type}`]: "user_type",
|
|
138
|
+
// // [`uip.${ModelUserFields.firstname}`]: "firstname",
|
|
139
|
+
// // [`uip.${ModelUserFields.lastname}`]: "lastname",
|
|
140
|
+
// // [`uip.${ModelUserFields.contact}`]: "contact",
|
|
141
|
+
// // [`uip.${ModelUserFields.email}`]: "email",
|
|
142
|
+
// }
|
|
143
|
+
// filterColumns = { ...filterColumns, ...injectionFieldSqlSelect }
|
|
144
|
+
// sqlSelect = [...sqlSelect, buildSqlSelect(``, injectionFieldSqlSelect)]
|
|
145
|
+
// sqlRelation = [...sqlRelation, buildSqlRelation("left", "locr", "user_injection_fields", "uip", ["locr.user_id = uip.user_id", "uip.field_ref = 'user'", "uip.isdelete = false", "uip.istrash = false"])]
|
|
146
|
+
// sqlGroupBy = [...sqlGroupBy, ...Object.keys(injectionFieldSqlSelect)]
|
|
147
|
+
// }
|
|
148
|
+
// if (datatypes.includes(locationRackDataTypes.branch)) {
|
|
149
|
+
// let branchSqlSelect = {
|
|
150
|
+
// [`COALESCE(
|
|
151
|
+
// JSON_AGG(
|
|
152
|
+
// DISTINCT JSONB_BUILD_OBJECT(
|
|
153
|
+
// '${ModelBranchFields.type}', brn.type,
|
|
154
|
+
// '${ModelBranchFields.branch_id}', brn.branch_id,
|
|
155
|
+
// '${ModelBranchFields.branch_code}', brn.branch_code,
|
|
156
|
+
// '${ModelBranchFields.branch_name}', brn.branch_name,
|
|
157
|
+
// '${ModelBranchFields.address_1}', brn.address_1,
|
|
158
|
+
// '${ModelBranchFields.address_2}', brn.address_2,
|
|
159
|
+
// '${ModelBranchFields.area}', brn.area,
|
|
160
|
+
// '${ModelBranchFields.area_id}', brn.area_id,
|
|
161
|
+
// '${ModelBranchFields.branch_contact}', brn.branch_contact,
|
|
162
|
+
// '${ModelBranchFields.branch_email}', brn.branch_email,
|
|
163
|
+
// '${ModelBranchFields.country_id}', brn.country_id,
|
|
164
|
+
// '${ModelBranchFields.is_hq}', brn.is_hq,
|
|
165
|
+
// '${ModelBranchFields.remark}', brn.remark,
|
|
166
|
+
// '${ModelBranchFields.pic_contact}', brn.pic_contact,
|
|
167
|
+
// '${ModelBranchFields.pic_email}', brn.pic_email,
|
|
168
|
+
// '${ModelBranchFields.pic_contact}', brn.pic_contact,
|
|
169
|
+
// '${ModelBranchFields.postcode}', brn.postcode,
|
|
170
|
+
// '${ModelBranchFields.state_id}', brn.state_id,
|
|
171
|
+
// '${ModelBranchFields.status}', brn.status,
|
|
172
|
+
// '${ModelBranchFields.user_id}', brn.user_id
|
|
173
|
+
// )
|
|
174
|
+
// ) FILTER (WHERE brn.branch_id IS NOT NULL AND brn.isdelete = false AND brn.istrash = false),
|
|
175
|
+
// '[]'
|
|
176
|
+
// )`]: "branches"
|
|
177
|
+
// }
|
|
178
|
+
// filterColumns = { ...filterColumns, ...branchSqlSelect }
|
|
179
|
+
// sqlSelect = [...sqlSelect, buildSqlSelect(``, branchSqlSelect)]
|
|
180
|
+
// sqlRelation = [...sqlRelation, buildSqlRelation("left", "locr", "branches", "brn", ["locr.user_id = brn.user_id", "brn.isdelete = false", "brn.istrash = false"])]
|
|
181
|
+
// }
|
|
182
|
+
// if (datatypes.includes(locationRackDataTypes.shippingAddress)) {
|
|
183
|
+
// let branchShippingAddressSqlSelect = {
|
|
184
|
+
// [`COALESCE(
|
|
185
|
+
// JSON_AGG(
|
|
186
|
+
// DISTINCT JSONB_BUILD_OBJECT(
|
|
187
|
+
// '${ModelBranchFields.type}', brnship.type,
|
|
188
|
+
// '${ModelBranchFields.branch_id}', brnship.branch_id,
|
|
189
|
+
// '${ModelBranchFields.branch_code}', brnship.branch_code,
|
|
190
|
+
// '${ModelBranchFields.branch_name}', brnship.branch_name,
|
|
191
|
+
// '${ModelBranchFields.address_1}', brnship.address_1,
|
|
192
|
+
// '${ModelBranchFields.address_2}', brnship.address_2,
|
|
193
|
+
// '${ModelBranchFields.area}', brnship.area,
|
|
194
|
+
// '${ModelBranchFields.area_id}', brnship.area_id,
|
|
195
|
+
// '${ModelBranchFields.branch_contact}', brnship.branch_contact,
|
|
196
|
+
// '${ModelBranchFields.branch_email}', brnship.branch_email,
|
|
197
|
+
// '${ModelBranchFields.country_id}', brnship.country_id,
|
|
198
|
+
// '${ModelBranchFields.is_hq}', brnship.is_hq,
|
|
199
|
+
// '${ModelBranchFields.remark}', brnship.remark,
|
|
200
|
+
// '${ModelBranchFields.pic_contact}', brnship.pic_contact,
|
|
201
|
+
// '${ModelBranchFields.pic_email}', brnship.pic_email,
|
|
202
|
+
// '${ModelBranchFields.pic_contact}', brnship.pic_contact,
|
|
203
|
+
// '${ModelBranchFields.postcode}', brnship.postcode,
|
|
204
|
+
// '${ModelBranchFields.state_id}', brnship.state_id,
|
|
205
|
+
// '${ModelBranchFields.status}', brnship.status,
|
|
206
|
+
// '${ModelBranchFields.user_id}', brnship.user_id
|
|
207
|
+
// )
|
|
208
|
+
// ) FILTER (WHERE brnship.branch_id IS NOT NULL AND brnship.isdelete = false AND brnship.istrash = false AND brnship.type = 'shipping_address'),
|
|
209
|
+
// '[]'
|
|
210
|
+
// )`]: "shipping_address"
|
|
211
|
+
// }
|
|
212
|
+
// filterColumns = { ...filterColumns, ...branchShippingAddressSqlSelect }
|
|
213
|
+
// sqlSelect = [...sqlSelect, buildSqlSelect(``, branchShippingAddressSqlSelect)]
|
|
214
|
+
// sqlRelation = [...sqlRelation, buildSqlRelation("left", "locr", "branches", "brnship", ["locr.user_id = brnship.user_id", "brnship.isdelete = false", "brnship.istrash = false"])]
|
|
215
|
+
// }
|
|
216
|
+
// if (datatypes.includes(locationRackDataTypes.branchCount)) {
|
|
217
|
+
// let branchCountSqlSelect = {
|
|
218
|
+
// [`COUNT(DISTINCT brncount.${ModelBranchFields.branch_id})::INT`]: "branch_count"
|
|
219
|
+
// }
|
|
220
|
+
// filterColumns = { ...filterColumns, ...branchCountSqlSelect }
|
|
221
|
+
// sqlSelect = [...sqlSelect, buildSqlSelect(``, branchCountSqlSelect)]
|
|
222
|
+
// sqlRelation = [...sqlRelation, buildSqlRelation("left", "locr", "branches", "brncount", ["locr.user_id = brncount.user_id", "brncount.isdelete = false", "brncount.istrash = false"])]
|
|
223
|
+
// }
|
|
224
|
+
// if (datatypes.includes(locationRackDataTypes.branchUserCount)) {
|
|
225
|
+
// let branchUserCountSqlSelect = {
|
|
226
|
+
// [`COUNT(DISTINCT brnusrcount.${ModelBranchUserFields.branch_user_id})::INT`]: "branch_user_count"
|
|
227
|
+
// }
|
|
228
|
+
// filterColumns = { ...filterColumns, ...branchUserCountSqlSelect }
|
|
229
|
+
// sqlSelect = [...sqlSelect, buildSqlSelect(``, branchUserCountSqlSelect)]
|
|
230
|
+
// sqlRelation = [...sqlRelation, buildSqlRelation("left", "locr", "branch_users", "brnusrcount", ["locr.user_id = brnusrcount.user_id", "brnusrcount.isdelete = false", "brnusrcount.istrash = false"])]
|
|
231
|
+
// }
|
|
232
|
+
let sqlWhere = [
|
|
233
|
+
`locr.isdelete = false`,
|
|
234
|
+
`locr.istrash = false`,
|
|
235
|
+
...(filters.length ? [(0, utils_2.buildSqlWhere)(filters, filterColumns)] : []),
|
|
236
|
+
];
|
|
237
|
+
let sqlOrderby = (0, utils_2.buildSqlOrderBy)(sortfield, sortorder);
|
|
238
|
+
let sqlLimitOffset = (0, utils_2.buildSqlLimitOffset)(limit, offset);
|
|
239
|
+
const sqlRaw = (0, utils_2.buildSqlRawSelect)({
|
|
240
|
+
tableName: "location_racks",
|
|
241
|
+
mainAlias: "locr",
|
|
242
|
+
accountId,
|
|
243
|
+
sqlSelect,
|
|
244
|
+
sqlRelation,
|
|
245
|
+
sqlWhere,
|
|
246
|
+
sqlGroupBy,
|
|
247
|
+
sqlOrderby,
|
|
248
|
+
sqlLimitOffset
|
|
249
|
+
});
|
|
250
|
+
data = await locationRackModel.raw(sqlRaw);
|
|
251
|
+
const response = {
|
|
252
|
+
data: data.map(({ filtered_count, ...rest }) => rest),
|
|
253
|
+
total: data.length ? Number(data[0].filtered_count) : 0
|
|
254
|
+
};
|
|
255
|
+
return response;
|
|
256
|
+
};
|
|
257
|
+
const removeLocationRacks = async ({ locationRackIds }) => {
|
|
258
|
+
if (!locationRackIds.length)
|
|
259
|
+
(0, utils_1.throwError)('locationRackIds is required');
|
|
260
|
+
const response = await locationRackModel.remove({ where: { [`${models_1.ModelLocationRackFields.location_rack_id}`]: { in: locationRackIds } } });
|
|
261
|
+
return response;
|
|
262
|
+
};
|
|
263
|
+
const getDataTypes = () => {
|
|
264
|
+
return Object.values(exports.locationRackDataTypes);
|
|
265
|
+
};
|
|
266
|
+
return {
|
|
267
|
+
createLocationRack,
|
|
268
|
+
updateLocationRack,
|
|
269
|
+
getLocationRack,
|
|
270
|
+
listLocationRacks,
|
|
271
|
+
removeLocationRacks,
|
|
272
|
+
getDataTypes
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
exports.LocationRackService = LocationRackService;
|