@spytecgps/nova-orm 0.0.224 → 0.0.226
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/entities/acumaticaAmazonProduct.js +46 -0
- package/dist/entities/acumaticaImeiIccidData.js +91 -0
- package/dist/entities/acumaticaOrderShipmentDetails.js +61 -0
- package/dist/entities/acumaticaShipment.js +31 -0
- package/dist/entities/acumaticaShipmentAmazon.js +26 -0
- package/dist/entities/aempToken.js +47 -0
- package/dist/entities/alert.js +129 -0
- package/dist/entities/alertMigration.js +115 -0
- package/dist/entities/alertMigrationBatch.js +21 -0
- package/dist/entities/alertTimeWindowConfiguration.js +61 -0
- package/dist/entities/alertType.js +83 -0
- package/dist/entities/appFeatureType.js +36 -0
- package/dist/entities/assetCategory.js +32 -0
- package/dist/entities/billing.js +108 -0
- package/dist/entities/billingCustomerBraintree.js +62 -0
- package/dist/entities/billingDeviceHistory.js +61 -0
- package/dist/entities/billingHubspotPaymentLog.js +256 -0
- package/dist/entities/billingKlarnaCustomer.js +76 -0
- package/dist/entities/billingKlarnaOrder.js +114 -0
- package/dist/entities/billingStatusHistoryBraintree.js +63 -0
- package/dist/entities/billingSubscriptionBraintree.js +229 -0
- package/dist/entities/blacklist.js +51 -0
- package/dist/entities/blacklistType.js +31 -0
- package/dist/entities/boundary.js +119 -0
- package/dist/entities/boundaryEvent.js +105 -0
- package/dist/entities/cellTower.js +66 -0
- package/dist/entities/client.js +153 -0
- package/dist/entities/clientAppFeature.js +47 -0
- package/dist/entities/clientConfiguration.js +47 -0
- package/dist/entities/clientDeviceSetting.js +90 -0
- package/dist/entities/clientType.js +36 -0
- package/dist/entities/country.js +90 -0
- package/dist/entities/customerAttribute.js +52 -0
- package/dist/entities/dataSourceType.js +31 -0
- package/dist/entities/deactivation.js +83 -0
- package/dist/entities/deactivationReason.js +40 -0
- package/dist/entities/device.js +160 -0
- package/dist/entities/deviceAlertConfiguration.js +71 -0
- package/dist/entities/deviceBehavior.js +147 -0
- package/dist/entities/deviceCustomConfiguration.js +67 -0
- package/dist/entities/deviceHistory.js +46 -0
- package/dist/entities/deviceModelListener.js +46 -0
- package/dist/entities/devicePairing.js +67 -0
- package/dist/entities/devicePromotion.js +104 -0
- package/dist/entities/deviceReplacement.js +57 -0
- package/dist/entities/deviceTask.js +44 -0
- package/dist/entities/deviceType.js +149 -0
- package/dist/entities/deviceTypeEvent.js +32 -0
- package/dist/entities/deviceTypeFeature.js +32 -0
- package/dist/entities/deviceTypeFirmware.js +117 -0
- package/dist/entities/entityTag.js +48 -0
- package/dist/entities/entityType.js +31 -0
- package/dist/entities/event.js +36 -0
- package/dist/entities/feature.js +36 -0
- package/dist/entities/firmwareAutoUpgradeBlacklist.js +35 -0
- package/dist/entities/firmwareUpgradeTask.js +105 -0
- package/dist/entities/iccidStatus.js +49 -0
- package/dist/entities/imeiIccidCarrier.js +125 -0
- package/dist/entities/imeiIccidHistory.js +43 -0
- package/dist/entities/index.js +99 -0
- package/dist/entities/industry.js +46 -0
- package/dist/entities/latestPosition.js +100 -0
- package/dist/entities/latestPositionMigration.js +96 -0
- package/dist/entities/latestPositionMigrationBatch.js +21 -0
- package/dist/entities/magento2Gps.js +256 -0
- package/dist/entities/magento2Plan.js +41 -0
- package/dist/entities/mobileNetwork.js +51 -0
- package/dist/entities/notificationRecipient.js +100 -0
- package/dist/entities/organization.js +46 -0
- package/dist/entities/plan.js +86 -0
- package/dist/entities/position.js +102 -0
- package/dist/entities/positionMigration.js +96 -0
- package/dist/entities/positionMigrationBatch.js +21 -0
- package/dist/entities/promotion.js +134 -0
- package/dist/entities/securityRole.js +41 -0
- package/dist/entities/serviceProvider.js +41 -0
- package/dist/entities/serviceProviderProduct.js +61 -0
- package/dist/entities/serviceProviderProductNetwork.js +31 -0
- package/dist/entities/serviceProviderProductType.js +31 -0
- package/dist/entities/sim.js +92 -0
- package/dist/entities/task.js +146 -0
- package/dist/entities/taskSchedule.js +141 -0
- package/dist/entities/trip.js +127 -0
- package/dist/entities/tripCompletionStatus.js +36 -0
- package/dist/entities/tripPosition.js +26 -0
- package/dist/entities/user.js +196 -0
- package/dist/entities/userActivation.js +52 -0
- package/dist/entities/userActivationDevice.js +164 -0
- package/dist/entities/userActivationEvent.js +61 -0
- package/dist/entities/userActivationMetric.js +208 -0
- package/dist/entities/userAlertComplain.js +78 -0
- package/dist/entities/userAlertConfiguration.js +109 -0
- package/dist/entities/userAppFeedback.js +52 -0
- package/dist/entities/userAppIncident.js +176 -0
- package/dist/entities/userConfiguration.js +109 -0
- package/dist/entities/userDataDeletionRequest.js +56 -0
- package/dist/entities/userDeviceBehaviorTask.js +80 -0
- package/dist/entities/userInvitation.js +89 -0
- package/dist/entities/userRatingRequest.js +75 -0
- package/dist/entities/userRegistrationAttempt.js +177 -0
- package/dist/entities/userSecurityRole.js +33 -0
- package/dist/index.js +1 -2
- package/dist/migration/1684483704434-addLowerCaseIndex.js +16 -0
- package/dist/novaDataSource.js +111 -0
- package/dist/repositories/acumatica/getAcumaticaImeiIccidData.js +35 -0
- package/dist/repositories/acumatica/getAcumaticaShipmentDetails.js +50 -0
- package/dist/repositories/acumatica/getLastAcumaticaShipmentDetails.js +27 -0
- package/dist/repositories/acumatica/index.js +52 -0
- package/dist/repositories/aempToken/createAempToken.js +26 -0
- package/dist/repositories/aempToken/deleteAempTokens.js +30 -0
- package/dist/repositories/aempToken/getAempTokens.js +27 -0
- package/dist/repositories/aempToken/index.js +53 -0
- package/dist/repositories/alertTypes/getAlertTypes.js +13 -0
- package/dist/repositories/alertTypes/index.js +18 -0
- package/dist/repositories/alerts/createAlert.js +94 -0
- package/dist/repositories/alerts/createUserAlertComplain.js +26 -0
- package/dist/repositories/alerts/getAlertsReportByClient.js +65 -0
- package/dist/repositories/alerts/getAlertsReportByUser.js +127 -0
- package/dist/repositories/alerts/index.js +104 -0
- package/dist/repositories/appFeatures/createAppFeatureType.js +15 -0
- package/dist/repositories/appFeatures/createClientAppFeature.js +15 -0
- package/dist/repositories/appFeatures/getClientAppFeatures.js +39 -0
- package/dist/repositories/appFeatures/index.js +57 -0
- package/dist/repositories/assetCategories/getAssetCategories.js +8 -0
- package/dist/repositories/assetCategories/index.js +16 -0
- package/dist/repositories/baseRepository.js +9 -0
- package/dist/repositories/billing/createBilling.js +37 -0
- package/dist/repositories/billing/createBillingDeviceHistory.js +30 -0
- package/dist/repositories/billing/createBillingHubspotPaymentLog.js +61 -0
- package/dist/repositories/billing/createBillingStatusHistoryBraintree.js +32 -0
- package/dist/repositories/billing/getBillingCustomerBraintreeById.js +18 -0
- package/dist/repositories/billing/getBillingKlarnaOrderByImei.js +18 -0
- package/dist/repositories/billing/getBillingSubscriptionBraintreeByImei.js +18 -0
- package/dist/repositories/billing/getBillingSubscriptionsBraintree.js +25 -0
- package/dist/repositories/billing/getBillings.js +42 -0
- package/dist/repositories/billing/getCanceledImeis.js +84 -0
- package/dist/repositories/billing/getCanceledImeisMatchingMagentoData.js +100 -0
- package/dist/repositories/billing/getChurnStatusByClientId.js +27 -0
- package/dist/repositories/billing/getClientIdFromBraintreeCustomer.js +20 -0
- package/dist/repositories/billing/getMagentoPlan.js +21 -0
- package/dist/repositories/billing/getUserByBraintreeCustomerId.js +22 -0
- package/dist/repositories/billing/index.js +353 -0
- package/dist/repositories/billing/updateBilling.js +43 -0
- package/dist/repositories/billing/updateBillingCustomerBraintree.js +37 -0
- package/dist/repositories/billing/upsertBillingCustomerBraintree.js +39 -0
- package/dist/repositories/billing/upsertBillingKlarnaCustomer.js +52 -0
- package/dist/repositories/billing/upsertBillingKlarnaOrder.js +58 -0
- package/dist/repositories/billing/upsertBillingSubscriptionBraintree.js +20 -0
- package/dist/repositories/blacklist/getBlacklists.js +19 -0
- package/dist/repositories/blacklist/index.js +19 -0
- package/dist/repositories/boundaries/createBoundary.js +52 -0
- package/dist/repositories/boundaries/deleteBoundary.js +23 -0
- package/dist/repositories/boundaries/getBoundariesByClientId.js +17 -0
- package/dist/repositories/boundaries/getBoundariesIdsByClientId.js +19 -0
- package/dist/repositories/boundaries/getBoundariesReport.js +141 -0
- package/dist/repositories/boundaries/getBoundaryById.js +14 -0
- package/dist/repositories/boundaries/index.js +178 -0
- package/dist/repositories/boundaries/processBoundaryEvent.js +211 -0
- package/dist/repositories/boundaries/updateBoundary.js +53 -0
- package/dist/repositories/boundaries/upsertBoundaryEvent.js +23 -0
- package/dist/repositories/clients/createClient.js +35 -0
- package/dist/repositories/clients/createClientConfiguration.js +18 -0
- package/dist/repositories/clients/createCustomerAttribute.js +16 -0
- package/dist/repositories/clients/deleteClientAndConfiguration.js +25 -0
- package/dist/repositories/clients/getClient.js +32 -0
- package/dist/repositories/clients/getClientConfiguration.js +14 -0
- package/dist/repositories/clients/getClients.js +26 -0
- package/dist/repositories/clients/getCustomerAttribute.js +14 -0
- package/dist/repositories/clients/index.js +192 -0
- package/dist/repositories/clients/updateClient.js +52 -0
- package/dist/repositories/clients/updateClientConfiguration.js +31 -0
- package/dist/repositories/clients/updateCustomerAttribute.js +27 -0
- package/dist/repositories/countries/getCountries.js +14 -0
- package/dist/repositories/countries/getCountry.js +23 -0
- package/dist/repositories/countries/index.js +33 -0
- package/dist/repositories/deactivations/createDeactivation.js +16 -0
- package/dist/repositories/deactivations/getDeactivationReasons.js +24 -0
- package/dist/repositories/deactivations/getLatestDeactivationByImei.js +19 -0
- package/dist/repositories/deactivations/index.js +58 -0
- package/dist/repositories/deviceBehaviors/createDeviceBehaviorTask.js +48 -0
- package/dist/repositories/deviceBehaviors/getDeviceBehaviorTasks.js +40 -0
- package/dist/repositories/deviceBehaviors/getDeviceBehaviors.js +41 -0
- package/dist/repositories/deviceBehaviors/getDeviceBehaviorsByIds.js +16 -0
- package/dist/repositories/deviceBehaviors/getDevicesLastBehaviorTask.js +42 -0
- package/dist/repositories/deviceBehaviors/getLatestDeviceBehaviorTasks.js +40 -0
- package/dist/repositories/deviceBehaviors/index.js +147 -0
- package/dist/repositories/deviceBehaviors/updateDeviceBehaviorTask.js +27 -0
- package/dist/repositories/deviceBehaviors/upsertDeviceBehavior.js +20 -0
- package/dist/repositories/devicePairings/createDevicePairing.js +21 -0
- package/dist/repositories/devicePairings/deleteDevicePairing.js +16 -0
- package/dist/repositories/devicePairings/getDevicePairings.js +36 -0
- package/dist/repositories/devicePairings/getDevicePairingsByImei.js +20 -0
- package/dist/repositories/devicePairings/index.js +90 -0
- package/dist/repositories/devicePairings/updateDevicePairing.js +32 -0
- package/dist/repositories/devices/createClientDeviceSetting.js +25 -0
- package/dist/repositories/devices/createDevice.js +30 -0
- package/dist/repositories/devices/createDeviceReplacement.js +34 -0
- package/dist/repositories/devices/createDeviceType.js +15 -0
- package/dist/repositories/devices/deleteDevice.js +16 -0
- package/dist/repositories/devices/generateDeviceIdentifierKey.js +18 -0
- package/dist/repositories/devices/getCanceledDevicesWithActiveSimCards.js +40 -0
- package/dist/repositories/devices/getCarrierStatusUpdatedBefore.js +40 -0
- package/dist/repositories/devices/getClientDeviceSetting.js +20 -0
- package/dist/repositories/devices/getClientDeviceSettings.js +17 -0
- package/dist/repositories/devices/getDevice.js +33 -0
- package/dist/repositories/devices/getDeviceCustomConfig.js +37 -0
- package/dist/repositories/devices/getDeviceTypeByImei.js +18 -0
- package/dist/repositories/devices/getDeviceTypes.js +30 -0
- package/dist/repositories/devices/getDeviceTypesModelsOrderedByDeviceCount.js +27 -0
- package/dist/repositories/devices/getDeviceWithUsersInfo.js +59 -0
- package/dist/repositories/devices/getDevices.js +46 -0
- package/dist/repositories/devices/getFilteredImeisWithStatus.js +20 -0
- package/dist/repositories/devices/getIccidStatus.js +17 -0
- package/dist/repositories/devices/getImeiIccidCarrier.js +23 -0
- package/dist/repositories/devices/getImeiIccidCarriers.js +17 -0
- package/dist/repositories/devices/index.js +464 -0
- package/dist/repositories/devices/updateClientDeviceSetting.js +38 -0
- package/dist/repositories/devices/updateDevice.js +56 -0
- package/dist/repositories/devices/updateDeviceType.js +43 -0
- package/dist/repositories/devices/updateIccidStatus.js +28 -0
- package/dist/repositories/devices/updateImeiIccidCarrier.js +43 -0
- package/dist/repositories/devices/upsertIccidStatus.js +36 -0
- package/dist/repositories/firmwares/createDeviceFirmware.js +37 -0
- package/dist/repositories/firmwares/createFirmwareAutoUpgradeBlacklist.js +16 -0
- package/dist/repositories/firmwares/createFirmwareUpgradeTask.js +36 -0
- package/dist/repositories/firmwares/getDeviceFirmwares.js +21 -0
- package/dist/repositories/firmwares/getFirmwareAutoUpgradeBlacklist.js +23 -0
- package/dist/repositories/firmwares/getFirmwareUpgradeTasks.js +105 -0
- package/dist/repositories/firmwares/getFirmwareUpgradeTasksCount.js +56 -0
- package/dist/repositories/firmwares/index.js +194 -0
- package/dist/repositories/firmwares/updateDeviceFirmware.js +41 -0
- package/dist/repositories/firmwares/updateFirmwareUpgradeTasks.js +37 -0
- package/dist/repositories/index.js +31 -0
- package/dist/repositories/notificationRecipients/createNotificationRecipient.js +37 -0
- package/dist/repositories/notificationRecipients/deleteNotificationRecipients.js +26 -0
- package/dist/repositories/notificationRecipients/deleteNotificationRecipientsByEmailOrPhone.js +28 -0
- package/dist/repositories/notificationRecipients/getNotificationRecipients.js +16 -0
- package/dist/repositories/notificationRecipients/index.js +131 -0
- package/dist/repositories/notificationRecipients/updateNotificationRecipient.js +37 -0
- package/dist/repositories/notificationRecipients/updateUsersNotificationsUnsubscribedInfoStatus.js +98 -0
- package/dist/repositories/notificationRecipients/updateUsersNotificationsUnsuscribedStatus.js +35 -0
- package/dist/repositories/positions/createPosition.js +100 -0
- package/dist/repositories/positions/getLatestPositionByImei.js +26 -0
- package/dist/repositories/positions/getPositionsByImei.js +23 -0
- package/dist/repositories/positions/getPositionsReportByClient.js +87 -0
- package/dist/repositories/positions/index.js +101 -0
- package/dist/repositories/positions/upsertLatestPosition.js +41 -0
- package/dist/repositories/security/createUserRole.js +30 -0
- package/dist/repositories/security/getAllRoles.js +8 -0
- package/dist/repositories/security/getUserRoles.js +15 -0
- package/dist/repositories/security/getUserRolesByClientId.js +17 -0
- package/dist/repositories/security/index.js +111 -0
- package/dist/repositories/security/removeUserRoles.js +21 -0
- package/dist/repositories/security/updateUserRole.js +27 -0
- package/dist/repositories/security/userIsAdminOrOwner.js +20 -0
- package/dist/repositories/security/userIsInRole.js +18 -0
- package/dist/repositories/tasks/addTaskScheduleDevices.js +37 -0
- package/dist/repositories/tasks/completeTask.js +25 -0
- package/dist/repositories/tasks/createTask.js +22 -0
- package/dist/repositories/tasks/createTaskSchedule.js +33 -0
- package/dist/repositories/tasks/deleteTask.js +22 -0
- package/dist/repositories/tasks/deleteTaskSchedule.js +22 -0
- package/dist/repositories/tasks/deleteTaskScheduleDevices.js +17 -0
- package/dist/repositories/tasks/getDeviceTasks.js +28 -0
- package/dist/repositories/tasks/getTaskSchedule.js +31 -0
- package/dist/repositories/tasks/getTaskSchedules.js +75 -0
- package/dist/repositories/tasks/getTaskSchedulesCount.js +23 -0
- package/dist/repositories/tasks/getTasks.js +29 -0
- package/dist/repositories/tasks/getTasksCount.js +20 -0
- package/dist/repositories/tasks/index.js +441 -0
- package/dist/repositories/tasks/setTaskAsPastDue.js +23 -0
- package/dist/repositories/tasks/setTaskScheduleDevices.js +43 -0
- package/dist/repositories/tasks/updateTask.js +21 -0
- package/dist/repositories/tasks/updateTaskSchedule.js +35 -0
- package/dist/repositories/trips/createTrip.js +29 -0
- package/dist/repositories/trips/getTripById.js +15 -0
- package/dist/repositories/trips/getTrips.js +65 -0
- package/dist/repositories/trips/index.js +69 -0
- package/dist/repositories/trips/updateTripEndValues.js +36 -0
- package/dist/repositories/trips/upsertTrip.js +31 -0
- package/dist/repositories/userActivations/createUserActivation.js +26 -0
- package/dist/repositories/userActivations/createUserActivationDevice.js +35 -0
- package/dist/repositories/userActivations/createUserActivationEvent.js +34 -0
- package/dist/repositories/userActivations/createUserActivationMetric.js +28 -0
- package/dist/repositories/userActivations/deleteUserActivation.js +22 -0
- package/dist/repositories/userActivations/getLastActivationDevice.js +26 -0
- package/dist/repositories/userActivations/getUserActivationDevices.js +24 -0
- package/dist/repositories/userActivations/getUserActivationDevicesByClientId.js +26 -0
- package/dist/repositories/userActivations/getUserActivationMetrics.js +24 -0
- package/dist/repositories/userActivations/getUserActivations.js +29 -0
- package/dist/repositories/userActivations/index.js +229 -0
- package/dist/repositories/userActivations/updateUserActivationDevice.js +39 -0
- package/dist/repositories/userActivations/updateUserActivationMetrics.js +61 -0
- package/dist/repositories/userAppFeedback/createUserAppFeedback.js +26 -0
- package/dist/repositories/userAppFeedback/index.js +23 -0
- package/dist/repositories/userAppIncidents/getUserAppIncidents.js +28 -0
- package/dist/repositories/userAppIncidents/index.js +63 -0
- package/dist/repositories/userAppIncidents/upsertUserAppIncident.js +53 -0
- package/dist/repositories/userConfigurations/bulkCreateUserAlertConfigurations.js +46 -0
- package/dist/repositories/userConfigurations/createDeviceAlertTimeWindows.js +36 -0
- package/dist/repositories/userConfigurations/createUserAlertTimeWindows.js +33 -0
- package/dist/repositories/userConfigurations/createUserConfiguration.js +34 -0
- package/dist/repositories/userConfigurations/deleteDeviceAlertTimeWindows.js +17 -0
- package/dist/repositories/userConfigurations/deleteUserAlertConfigurations.js +24 -0
- package/dist/repositories/userConfigurations/deleteUserAlertTimeWindows.js +17 -0
- package/dist/repositories/userConfigurations/deleteUserConfiguration.js +23 -0
- package/dist/repositories/userConfigurations/getDeviceAlertTimeWindows.js +43 -0
- package/dist/repositories/userConfigurations/getUserAlertConfigurations.js +25 -0
- package/dist/repositories/userConfigurations/getUserAlertTimeWindows.js +35 -0
- package/dist/repositories/userConfigurations/getUserConfigurations.js +31 -0
- package/dist/repositories/userConfigurations/index.js +298 -0
- package/dist/repositories/userConfigurations/updateDeviceAlertTimeWindows.js +29 -0
- package/dist/repositories/userConfigurations/updateUserAlertConfigurations.js +46 -0
- package/dist/repositories/userConfigurations/updateUserAlertTimeWindows.js +28 -0
- package/dist/repositories/userConfigurations/updateUserConfiguration.js +49 -0
- package/dist/repositories/userDataDeletionRequests/createUserDataDeletionRequest.js +28 -0
- package/dist/repositories/userDataDeletionRequests/getUserDataDeletionRequest.js +29 -0
- package/dist/repositories/userDataDeletionRequests/index.js +66 -0
- package/dist/repositories/userDataDeletionRequests/removeUserDataDeletionRequest.js +17 -0
- package/dist/repositories/userDataDeletionRequests/updateUserDataDeletionRequest.js +38 -0
- package/dist/repositories/userInvitations/createUserInvitation.js +43 -0
- package/dist/repositories/userInvitations/getUserInvitationById.js +22 -0
- package/dist/repositories/userInvitations/getUserInvitations.js +31 -0
- package/dist/repositories/userInvitations/index.js +82 -0
- package/dist/repositories/userInvitations/updateUserInvitation.js +50 -0
- package/dist/repositories/userRatingRequests/createUserRatingRequest.js +34 -0
- package/dist/repositories/userRatingRequests/getUserRatingRequests.js +23 -0
- package/dist/repositories/userRatingRequests/index.js +41 -0
- package/dist/repositories/userRegistrationAttempts/createUserRegistrationAttempt.js +40 -0
- package/dist/repositories/userRegistrationAttempts/getUserRegistrationAttempts.js +29 -0
- package/dist/repositories/userRegistrationAttempts/index.js +70 -0
- package/dist/repositories/userRegistrationAttempts/updateUserRegistrationAttempt.js +40 -0
- package/dist/repositories/users/createUser.js +47 -0
- package/dist/repositories/users/deleteAccount.js +98 -0
- package/dist/repositories/users/deleteUser.js +22 -0
- package/dist/repositories/users/getUserById.js +22 -0
- package/dist/repositories/users/getUserData.js +66 -0
- package/dist/repositories/users/getUsers.js +49 -0
- package/dist/repositories/users/getUsersConfigurationByImei.js +29 -0
- package/dist/repositories/users/getUsersIdByPhoneAndCountryCode.js +21 -0
- package/dist/repositories/users/getUsersWithRoles.js +32 -0
- package/dist/repositories/users/index.js +195 -0
- package/dist/repositories/users/updateUser.js +109 -0
- package/dist/subscribers/allEntitiesSubscriber.js +52 -0
- package/dist/subscribers/index.js +2 -0
- package/dist/types/acumatica.js +1 -0
- package/dist/types/aempToken.js +1 -0
- package/dist/types/alert.js +1 -0
- package/dist/types/alertTypes.js +1 -0
- package/dist/types/appFeatures.js +1 -0
- package/dist/types/billing.js +1 -0
- package/dist/types/blacklist.js +1 -0
- package/dist/types/boundaries.js +1 -0
- package/dist/types/clients.js +1 -0
- package/dist/types/common.js +1 -0
- package/dist/types/countries.js +1 -0
- package/dist/types/deactivations.js +1 -0
- package/dist/types/deviceBehaviors.js +1 -0
- package/dist/types/devicePairings.js +1 -0
- package/dist/types/devices.js +1 -0
- package/dist/types/enums.js +74 -0
- package/dist/types/firmwares.js +17 -0
- package/dist/types/index.js +30 -0
- package/dist/types/logger.js +9 -0
- package/dist/types/notificationRecipients.js +1 -0
- package/dist/types/position.js +1 -0
- package/dist/types/security.js +1 -0
- package/dist/types/tasks.js +1 -0
- package/dist/types/trip.js +29 -0
- package/dist/types/user.js +1 -0
- package/dist/types/userActivations.js +1 -0
- package/dist/types/userAppFeedback.js +1 -0
- package/dist/types/userAppIncidents.js +1 -0
- package/dist/types/userConfigurations.js +1 -0
- package/dist/types/userDataDeletionRequests.js +1 -0
- package/dist/types/userInvitations.js +1 -0
- package/dist/types/userRatingRequests.js +1 -0
- package/dist/types/userRegistrationAttempts.js +1 -0
- package/dist/utils/anyAttributeHasValue.js +20 -0
- package/dist/utils/anyAttributeIsNull.js +12 -0
- package/dist/utils/boolToNumberTransformer.js +23 -0
- package/dist/utils/consoleLogger.js +42 -0
- package/dist/utils/filterTools.js +299 -0
- package/dist/utils/mapRawEntityToEntity.js +12 -0
- package/dist/utils/queryLogger.js +48 -0
- package/dist/utils/randomizer.js +39 -0
- package/dist/utils/stringToDateTransformer.js +16 -0
- package/dist/utils/uuidHelpers.js +30 -0
- package/package.json +10 -8
- package/dist/index.js.LICENSE.txt +0 -41
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Boundary } from '../../entities';
|
|
2
|
+
import { BoundaryStatus } from '../../types/enums';
|
|
3
|
+
const MIN_BOUNDARY_RADIUS_IN_M = 50; // in meters
|
|
4
|
+
const DEFAULT_BOUNDARY_COLOR = '#e74c3c';
|
|
5
|
+
const DEFAULT_BOUNDARY_DISPLAY_UNIT = 'm';
|
|
6
|
+
export const createBoundary = async (novaDataSource, params, logger) => {
|
|
7
|
+
if (!params?.clientId ||
|
|
8
|
+
params.clientId === 0 ||
|
|
9
|
+
!params?.name ||
|
|
10
|
+
!params?.type ||
|
|
11
|
+
!params?.location ||
|
|
12
|
+
!params?.geometry) {
|
|
13
|
+
logger.warn({ params }, 'BoundariesRepository::createBoundary - missing required parameters');
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return novaDataSource.safeQuery(async (dataSource) => {
|
|
17
|
+
const boundariesRepository = dataSource.getRepository(Boundary);
|
|
18
|
+
const now = new Date();
|
|
19
|
+
// radius
|
|
20
|
+
let buffer = parseFloat(params.buffer);
|
|
21
|
+
if (Number.isNaN(buffer)) {
|
|
22
|
+
buffer = 0;
|
|
23
|
+
}
|
|
24
|
+
const normalizedRadius = Math.max(buffer, MIN_BOUNDARY_RADIUS_IN_M);
|
|
25
|
+
// display unit
|
|
26
|
+
const radiusDisplayUnit = params.radiusDisplayUnit || DEFAULT_BOUNDARY_DISPLAY_UNIT;
|
|
27
|
+
// if not color default
|
|
28
|
+
const color = params.color || DEFAULT_BOUNDARY_COLOR;
|
|
29
|
+
// status
|
|
30
|
+
const status = params.status > 0 && params.status < 4 ? params.status : BoundaryStatus.Active;
|
|
31
|
+
const newBoundary = {
|
|
32
|
+
id: params.boundaryId,
|
|
33
|
+
name: params.name,
|
|
34
|
+
type: params.type,
|
|
35
|
+
buffer: `${normalizedRadius}`,
|
|
36
|
+
radiusDisplayUnit,
|
|
37
|
+
clientId: params.clientId,
|
|
38
|
+
createdAt: now,
|
|
39
|
+
modifiedAt: now,
|
|
40
|
+
createdBy: params.createdBy,
|
|
41
|
+
modifiedBy: params.createdBy,
|
|
42
|
+
location: params.location,
|
|
43
|
+
color,
|
|
44
|
+
geometry: params.geometry,
|
|
45
|
+
isUserCreated: params.isUserCreated ?? true,
|
|
46
|
+
status,
|
|
47
|
+
area: params.area,
|
|
48
|
+
dataSourceTypeId: params.dataSourceTypeId,
|
|
49
|
+
};
|
|
50
|
+
return await boundariesRepository.save(newBoundary);
|
|
51
|
+
}, 'BoundariesRepository::createBoundary');
|
|
52
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Boundary } from '../../entities';
|
|
2
|
+
import { BoundaryStatus } from '../../types/enums';
|
|
3
|
+
export const deleteBoundary = async (novaDataSource, params, logger) => {
|
|
4
|
+
if (!params?.filters?.boundaryId) {
|
|
5
|
+
logger.warn({ params }, 'BoundariesRepository::deleteBoundary - missing required parameters');
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return novaDataSource.safeQuery(async (dataSource) => {
|
|
9
|
+
const boundariesRepository = dataSource.getRepository(Boundary);
|
|
10
|
+
const now = new Date();
|
|
11
|
+
const result = await boundariesRepository
|
|
12
|
+
.createQueryBuilder()
|
|
13
|
+
.update(Boundary)
|
|
14
|
+
.set({
|
|
15
|
+
status: BoundaryStatus.Deleted,
|
|
16
|
+
modifiedBy: params.values.modifiedBy,
|
|
17
|
+
modifiedAt: now,
|
|
18
|
+
})
|
|
19
|
+
.where('id = :id', { id: params.filters.boundaryId })
|
|
20
|
+
.execute();
|
|
21
|
+
return result.affected > 0;
|
|
22
|
+
}, 'BoundariesRepository::deleteBoundary');
|
|
23
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Boundary } from '../../entities';
|
|
2
|
+
export const getBoundariesByClientId = async (novaDataSource, params, logger) => {
|
|
3
|
+
if (!params.filters.clientId) {
|
|
4
|
+
logger.warn({ params }, 'BoundariesRepository::getBoundariesByClientId - missing required parameters');
|
|
5
|
+
return [];
|
|
6
|
+
}
|
|
7
|
+
return novaDataSource.safeQuery(async (dataSource) => {
|
|
8
|
+
const boundariesRepository = dataSource.getRepository(Boundary);
|
|
9
|
+
const filterCondition = params.filters.status
|
|
10
|
+
? { where: { clientId: params.filters.clientId, status: params.filters.status } }
|
|
11
|
+
: {
|
|
12
|
+
where: { clientId: params.filters.clientId },
|
|
13
|
+
};
|
|
14
|
+
const boundaries = await boundariesRepository.find(filterCondition);
|
|
15
|
+
return boundaries;
|
|
16
|
+
}, 'BoundariesRepository::getBoundariesByClientId');
|
|
17
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Boundary } from '../../entities';
|
|
2
|
+
export const getBoundariesIdsByClientId = async (novaDataSource, params, logger) => {
|
|
3
|
+
if (!params.filters.clientId) {
|
|
4
|
+
logger.warn({ params }, 'BoundariesRepository::getBoundariesIdsByClientId - missing required parameters');
|
|
5
|
+
return [];
|
|
6
|
+
}
|
|
7
|
+
return novaDataSource.safeQuery(async (dataSource) => {
|
|
8
|
+
const boundariesRepository = dataSource.getRepository(Boundary);
|
|
9
|
+
const filterCondition = params.filters.status
|
|
10
|
+
? { clientId: params.filters.clientId, status: params.filters.status }
|
|
11
|
+
: { clientId: params.filters.clientId };
|
|
12
|
+
const boundariesIds = await boundariesRepository
|
|
13
|
+
.createQueryBuilder()
|
|
14
|
+
.where(filterCondition)
|
|
15
|
+
.select('id')
|
|
16
|
+
.getRawMany();
|
|
17
|
+
return boundariesIds.map(x => x.id);
|
|
18
|
+
}, 'BoundariesRepository::getBoundariesIdsByClientId');
|
|
19
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Enums } from '../..';
|
|
2
|
+
import { Boundary, BoundaryEvent, Device } from '../../entities';
|
|
3
|
+
import { uuidStringToBinaryBuffer } from '../../utils/uuidHelpers';
|
|
4
|
+
export const getBoundariesReport = async (novaDataSource, params, logger) => {
|
|
5
|
+
if (!params?.filters?.userId) {
|
|
6
|
+
logger.warn({ params }, 'BoundariesRepository::getBoundariesReport - missing required parameters');
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
const userIdBinaryBuffer = uuidStringToBinaryBuffer(params?.filters?.userId);
|
|
10
|
+
if (!userIdBinaryBuffer?.length) {
|
|
11
|
+
logger.warn({ params }, 'BoundariesRepository::getBoundariesReport - user id should be a valid UUID');
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return novaDataSource.safeQuery(async (dataSource) => {
|
|
15
|
+
const boundariesRepository = dataSource.getRepository(BoundaryEvent);
|
|
16
|
+
const queryBuilder = boundariesRepository
|
|
17
|
+
.createQueryBuilder('boundaryEvent')
|
|
18
|
+
.innerJoin(Device, 'device', 'device.id = boundaryEvent.deviceId')
|
|
19
|
+
.innerJoin(Boundary, 'boundary', 'boundary.id = boundaryEvent.boundaryId')
|
|
20
|
+
.where('boundaryEvent.userId = :userId', { userId: userIdBinaryBuffer })
|
|
21
|
+
.andWhere('device.status = :deviceStatus', { deviceStatus: Enums.DeviceStatus.Active });
|
|
22
|
+
if (params.filters.boundaryId) {
|
|
23
|
+
queryBuilder.andWhere('boundaryEvent.boundaryId = :boundaryId', {
|
|
24
|
+
boundaryId: params.filters.boundaryId,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (params.filters.boundaryName) {
|
|
28
|
+
queryBuilder.andWhere('boundary.name LIKE :boundaryName', {
|
|
29
|
+
boundaryName: `%${params.filters.boundaryName}%`,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (params.filters.imeis?.length) {
|
|
33
|
+
queryBuilder.andWhere('device.imei IN (:...imeis)', { imeis: params.filters.imeis });
|
|
34
|
+
}
|
|
35
|
+
if (params.filters.boundaryInStartDate) {
|
|
36
|
+
queryBuilder.andWhere('boundaryEvent.inDate >= :boundaryInStartDate', {
|
|
37
|
+
boundaryInStartDate: params.filters.boundaryInStartDate,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (params.filters.boundaryInEndDate) {
|
|
41
|
+
queryBuilder.andWhere('boundaryEvent.inDate <= :boundaryInEndDate', {
|
|
42
|
+
boundaryInEndDate: params.filters.boundaryInEndDate,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (params.filters.boundaryOutStartDate) {
|
|
46
|
+
queryBuilder.andWhere('boundaryEvent.outDate >= :boundaryOutStartDate', {
|
|
47
|
+
boundaryOutStartDate: params.filters.boundaryOutStartDate,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (params.filters.boundaryOutEndDate) {
|
|
51
|
+
queryBuilder.andWhere('boundaryEvent.outDate <= :boundaryOutEndDate', {
|
|
52
|
+
boundaryOutEndDate: params.filters.boundaryOutEndDate,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (params.filters.minDuration) {
|
|
56
|
+
queryBuilder.andWhere(`((boundaryEvent.inOutDuration IS NOT NULL AND boundaryEvent.inOutDuration >= :minDuration) OR
|
|
57
|
+
(boundaryEvent.inOutDuration IS NULL AND boundaryEvent.inDate IS NOT NULL AND boundaryEvent.outDate IS NULL AND
|
|
58
|
+
UNIX_TIMESTAMP(CONVERT_TZ(NOW(), @@session.time_zone, '+00:00')) - UNIX_TIMESTAMP(boundaryEvent.inDate) >= :minDuration
|
|
59
|
+
))`, {
|
|
60
|
+
minDuration: params.filters.minDuration,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (params.filters.maxDuration) {
|
|
64
|
+
queryBuilder.andWhere(`((boundaryEvent.inOutDuration IS NOT NULL AND boundaryEvent.inOutDuration <= :maxDuration) OR
|
|
65
|
+
(boundaryEvent.inOutDuration IS NULL AND boundaryEvent.inDate IS NOT NULL AND boundaryEvent.outDate IS NULL AND
|
|
66
|
+
UNIX_TIMESTAMP(CONVERT_TZ(NOW(), @@session.time_zone, '+00:00')) - UNIX_TIMESTAMP(boundaryEvent.inDate) <= :maxDuration
|
|
67
|
+
))`, {
|
|
68
|
+
maxDuration: params.filters.maxDuration,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const subQuery = queryBuilder.clone().select('COUNT(boundaryEvent.id)', 'totalCount');
|
|
72
|
+
queryBuilder.innerJoin(`(${subQuery.getQuery()})`, 'sub');
|
|
73
|
+
if (params.sortOptions?.sortField) {
|
|
74
|
+
let sortField = null;
|
|
75
|
+
switch (params.sortOptions.sortField) {
|
|
76
|
+
case 'inDateTime':
|
|
77
|
+
sortField = 'boundaryEvent.inDate';
|
|
78
|
+
break;
|
|
79
|
+
case 'outDateTime':
|
|
80
|
+
sortField = 'boundaryEvent.outDate';
|
|
81
|
+
break;
|
|
82
|
+
case 'inOutDuration':
|
|
83
|
+
sortField = `CASE WHEN boundaryEvent.inOutDuration IS NOT NULL
|
|
84
|
+
THEN boundaryEvent.inOutDuration
|
|
85
|
+
WHEN boundaryEvent.inOutDuration IS NULL AND boundaryEvent.inDate IS NOT NULL AND boundaryEvent.outDate IS NULL
|
|
86
|
+
THEN UNIX_TIMESTAMP(CONVERT_TZ(NOW(), @@session.time_zone, "+00:00")) - UNIX_TIMESTAMP(boundaryEvent.inDate)
|
|
87
|
+
ELSE NULL
|
|
88
|
+
END`;
|
|
89
|
+
break;
|
|
90
|
+
case 'name':
|
|
91
|
+
sortField = 'boundary.name';
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
queryBuilder.orderBy(sortField || 'boundaryEvent.inDate', params.sortOptions.sortOrder || 'DESC');
|
|
95
|
+
}
|
|
96
|
+
const result = await queryBuilder
|
|
97
|
+
.select([
|
|
98
|
+
'device.id AS deviceId',
|
|
99
|
+
'device.imei AS imei',
|
|
100
|
+
'device.name AS deviceName',
|
|
101
|
+
'boundary.id AS boundaryId',
|
|
102
|
+
'boundary.name AS boundaryName',
|
|
103
|
+
'boundaryEvent.inDate AS inDate',
|
|
104
|
+
'boundaryEvent.inLat AS inLat',
|
|
105
|
+
'boundaryEvent.inLon AS inLon',
|
|
106
|
+
'boundaryEvent.inAddress AS inAddress',
|
|
107
|
+
'boundaryEvent.outDate AS outDate',
|
|
108
|
+
'boundaryEvent.outLat AS outLat',
|
|
109
|
+
'boundaryEvent.outLon AS outLon',
|
|
110
|
+
'boundaryEvent.outAddress AS outAddress',
|
|
111
|
+
`CASE
|
|
112
|
+
WHEN boundaryEvent.inOutDuration IS NOT NULL
|
|
113
|
+
THEN boundaryEvent.inOutDuration
|
|
114
|
+
WHEN boundaryEvent.inOutDuration IS NULL AND boundaryEvent.inDate IS NOT NULL AND boundaryEvent.outDate IS NULL
|
|
115
|
+
THEN UNIX_TIMESTAMP(CONVERT_TZ(NOW(), @@session.time_zone, '+00:00')) - UNIX_TIMESTAMP(boundaryEvent.inDate)
|
|
116
|
+
ELSE NULL
|
|
117
|
+
END AS duration`,
|
|
118
|
+
`sub.totalCount AS totalCount`,
|
|
119
|
+
])
|
|
120
|
+
.limit(params.pagingOptions.pageSize)
|
|
121
|
+
.offset(params.pagingOptions.pageSize * params.pagingOptions.pageIndex)
|
|
122
|
+
.getRawMany();
|
|
123
|
+
return result.map(row => ({
|
|
124
|
+
deviceId: row.deviceId,
|
|
125
|
+
imei: row.imei,
|
|
126
|
+
deviceName: row.deviceName,
|
|
127
|
+
boundaryId: row.boundaryId,
|
|
128
|
+
boundaryName: row.boundaryName,
|
|
129
|
+
inDate: row.inDate,
|
|
130
|
+
inLat: row.inLat,
|
|
131
|
+
inLon: row.inLon,
|
|
132
|
+
inAddress: row.inAddress,
|
|
133
|
+
outDate: row.outDate,
|
|
134
|
+
outLat: row.outLat,
|
|
135
|
+
outLon: row.outLon,
|
|
136
|
+
outAddress: row.outAddress,
|
|
137
|
+
inOutDuration: row.duration,
|
|
138
|
+
totalCount: row.totalCount,
|
|
139
|
+
}));
|
|
140
|
+
}, 'BoundariesRepository::getBoundariesReport');
|
|
141
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Boundary } from '../../entities';
|
|
2
|
+
export const getBoundaryById = async (novaDataSource, params, logger) => {
|
|
3
|
+
if (!params.filters.boundaryId) {
|
|
4
|
+
logger.warn({ params }, 'BoundariesRepository::getBoundaryById - missing required parameters');
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
return novaDataSource.safeQuery(async (dataSource) => {
|
|
8
|
+
const boundariesRepository = dataSource.getRepository(Boundary);
|
|
9
|
+
const boundary = await boundariesRepository.findOne({
|
|
10
|
+
where: { id: params.filters.boundaryId },
|
|
11
|
+
});
|
|
12
|
+
return boundary;
|
|
13
|
+
}, 'BoundariesRepository::getBoundaryById');
|
|
14
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { NovaDataSource } from '../../novaDataSource';
|
|
2
|
+
import { BaseRepository } from '../baseRepository';
|
|
3
|
+
import { createBoundary } from './createBoundary';
|
|
4
|
+
import { deleteBoundary } from './deleteBoundary';
|
|
5
|
+
import { getBoundariesByClientId } from './getBoundariesByClientId';
|
|
6
|
+
import { getBoundariesIdsByClientId } from './getBoundariesIdsByClientId';
|
|
7
|
+
import { getBoundariesReport } from './getBoundariesReport';
|
|
8
|
+
import { getBoundaryById } from './getBoundaryById';
|
|
9
|
+
import { processBoundaryEvent } from './processBoundaryEvent';
|
|
10
|
+
import { updateBoundary } from './updateBoundary';
|
|
11
|
+
import { upsertBoundaryEvent } from './upsertBoundaryEvent';
|
|
12
|
+
export class BoundariesRepository extends BaseRepository {
|
|
13
|
+
/**
|
|
14
|
+
* Get all boundaries by client id
|
|
15
|
+
* @param {GetBoundariesByClientIdParams} params containing information to get boundaries by clientId
|
|
16
|
+
* - filters.clientId: The client id
|
|
17
|
+
* - filters.status: The status to only obtain boundaries with that status, optional
|
|
18
|
+
*/
|
|
19
|
+
async getBoundariesByClientId(params) {
|
|
20
|
+
this.logger.trace(params, 'BoundariesRepository::getBoundariesByClientId started with params');
|
|
21
|
+
const novaDataSource = new NovaDataSource(this.novaDataSourceConfig, this.logger);
|
|
22
|
+
const result = await getBoundariesByClientId(novaDataSource, params, this.logger);
|
|
23
|
+
this.logger.trace({ result: result.map(x => x.id) }, 'BoundariesRepository::getBoundariesByClientId result');
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get all boundaries ids by client id
|
|
28
|
+
* @param {GetBoundariesByClientIdParams} params containing information to get boundaries ids by clientId
|
|
29
|
+
* - filters.clientId: The client id
|
|
30
|
+
* - filters.status: The status to only obtain boundaries with that status, optional
|
|
31
|
+
*/
|
|
32
|
+
async getBoundariesIdsByClientId(params) {
|
|
33
|
+
this.logger.trace(params, 'BoundariesRepository::getBoundariesIdsByClientId started with params');
|
|
34
|
+
const novaDataSource = new NovaDataSource(this.novaDataSourceConfig, this.logger);
|
|
35
|
+
const result = await getBoundariesIdsByClientId(novaDataSource, params, this.logger);
|
|
36
|
+
this.logger.trace(result, 'BoundariesRepository::getBoundariesIdsByClientId result');
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get a boundary by id
|
|
41
|
+
* @param {GetBoundaryByIdParams} params containing information to get a boundary by id
|
|
42
|
+
* - filters.boundaryId: The boundary id
|
|
43
|
+
*/
|
|
44
|
+
async getBoundaryById(params) {
|
|
45
|
+
this.logger.trace(params, 'BoundariesRepository::getBoundaryById started with params');
|
|
46
|
+
const novaDataSource = new NovaDataSource(this.novaDataSourceConfig, this.logger);
|
|
47
|
+
const result = await getBoundaryById(novaDataSource, params, this.logger);
|
|
48
|
+
this.logger.trace({
|
|
49
|
+
result: {
|
|
50
|
+
...result,
|
|
51
|
+
geometry: undefined,
|
|
52
|
+
},
|
|
53
|
+
}, 'BoundariesRepository::getBoundaryById result');
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create a boundary
|
|
58
|
+
* @param {CreateBoundaryParams} params containing information to create a boundary
|
|
59
|
+
* - name: boundary name
|
|
60
|
+
* - type: boundary type
|
|
61
|
+
* - clientId: id of the client that owns the boundary
|
|
62
|
+
* - createdBy: id of the user that created the boundary
|
|
63
|
+
* - location: location of the boundary
|
|
64
|
+
* - buffer: buffer of the boundary
|
|
65
|
+
* - radiusDisplayUnit: radius display unit of the boundary
|
|
66
|
+
* - color: color of the boundary
|
|
67
|
+
* - geometry: geometry of the boundary
|
|
68
|
+
* - status: status of the boundary
|
|
69
|
+
* - dataSourceTypeId: data source type id of the boundary, optional
|
|
70
|
+
* - isUserCreated: if the boundary was created by a user, optional
|
|
71
|
+
* - area: area of the boundary, optional
|
|
72
|
+
*/
|
|
73
|
+
async createBoundary(params) {
|
|
74
|
+
this.logger.trace(params, 'BoundariesRepository::createBoundary started with params');
|
|
75
|
+
const novaDataSource = new NovaDataSource(this.novaDataSourceConfig, this.logger);
|
|
76
|
+
const result = await createBoundary(novaDataSource, params, this.logger);
|
|
77
|
+
this.logger.trace({
|
|
78
|
+
result: {
|
|
79
|
+
...result,
|
|
80
|
+
geometry: undefined,
|
|
81
|
+
},
|
|
82
|
+
}, 'BoundariesRepository::createBoundary result');
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Update a boundary
|
|
87
|
+
* @param {UpdateBoundaryParams} params containing information to update a boundary
|
|
88
|
+
* - filters.boundaryId: The id of the boundary to update
|
|
89
|
+
* - values.name: The name of the boundary. Optional, if undefined, the name will not be updated.
|
|
90
|
+
* - values.type: The type of the boundary. Optional, if undefined, the type will not be updated.
|
|
91
|
+
* - values.modifiedBy: The user id of the user that modified the boundary. Optional, if undefined, the modifiedBy will not be updated.
|
|
92
|
+
* - values.location: The location of the boundary. Optional, if undefined, the location will not be updated.
|
|
93
|
+
* - values.geometry: The geometry of the boundary. Optional, if undefined, the geometry will not be updated.
|
|
94
|
+
* - values.status: The status of the boundary. Optional, if undefined, the status will not be updated.
|
|
95
|
+
* - values.buffer: The buffer of the boundary. Optional, if undefined, the buffer will not be updated.
|
|
96
|
+
* - values.radiusDisplayUnit: The radius display unit of the boundary. Optional, if undefined, the radius display unit will not be updated.
|
|
97
|
+
* - values.color: The color of the boundary. Optional, if undefined, the color will not be updated.
|
|
98
|
+
* - values.area: The area of the boundary. Optional, if undefined, the area will not be updated.
|
|
99
|
+
*/
|
|
100
|
+
async updateBoundary(params) {
|
|
101
|
+
this.logger.trace(params, 'BoundariesRepository::updateBoundary started with params');
|
|
102
|
+
const novaDataSource = new NovaDataSource(this.novaDataSourceConfig, this.logger);
|
|
103
|
+
const result = await updateBoundary(novaDataSource, params, this.logger);
|
|
104
|
+
this.logger.trace({ result }, 'BoundariesRepository::updateBoundary result');
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Delete a boundary
|
|
109
|
+
* @param {DeleteBoundaryParams} params containing information to delete a boundary
|
|
110
|
+
* The boundary will not be removed from the database, it will only be marked as deleted
|
|
111
|
+
* - filters.boundaryId: The id of the boundary to delete
|
|
112
|
+
* - values.modifiedBy: The user id of the user that deleted the boundary
|
|
113
|
+
*/
|
|
114
|
+
async deleteBoundary(params) {
|
|
115
|
+
this.logger.trace(params, 'BoundariesRepository::deleteBoundary started with params');
|
|
116
|
+
const novaDataSource = new NovaDataSource(this.novaDataSourceConfig, this.logger);
|
|
117
|
+
const result = await deleteBoundary(novaDataSource, params, this.logger);
|
|
118
|
+
this.logger.trace({ result }, 'BoundariesRepository::deleteBoundary result');
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get boundaries report
|
|
123
|
+
* @param {GetBoundariesReportParams} params containing information to get boundaries report
|
|
124
|
+
* - filters.userId: The user id
|
|
125
|
+
* - filters.boundaryId: The boundary id, optional
|
|
126
|
+
* - filters.boundaryName: The boundary name, optional
|
|
127
|
+
* - filters.imeis: The imeis, optional
|
|
128
|
+
* - filters.boundaryInStartDate: The boundary in start date, optional
|
|
129
|
+
* - filters.boundaryInEndDate: The boundary in end date, optional
|
|
130
|
+
* - filters.boundaryOutStartDate: The boundary out start date, optional
|
|
131
|
+
* - filters.boundaryOutEndDate: The boundary out end date, optional
|
|
132
|
+
* - pagingOptions.pageSize: The page size of the pagination, required
|
|
133
|
+
* - pagingOptions.pageIndex: The page index of the pagination, required
|
|
134
|
+
* - sortOptions.sortField: The field to sort the pagination, optional
|
|
135
|
+
* - sortOptions.sortOrder: The order to sort the pagination, optional
|
|
136
|
+
* @returns The boundaries report
|
|
137
|
+
*/
|
|
138
|
+
async getBoundariesReport(params) {
|
|
139
|
+
this.logger.trace(params, 'BoundariesRepository::getBoundariesReport started with params');
|
|
140
|
+
const novaDataSource = new NovaDataSource(this.novaDataSourceConfig, this.logger);
|
|
141
|
+
const result = await getBoundariesReport(novaDataSource, params, this.logger);
|
|
142
|
+
this.logger.trace(result, 'BoundariesRepository::getBoundariesReport result');
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Process boundary event
|
|
147
|
+
* @param {ProcessBoundaryEventParams} params containing information to process boundary event
|
|
148
|
+
* - boundaryId: The boundary id
|
|
149
|
+
* - imei: The imei of the device
|
|
150
|
+
* - userId: The user id
|
|
151
|
+
* - sendTime: The event date
|
|
152
|
+
* - eventType: The event type (enter or exit)
|
|
153
|
+
* - lat: The latitude of the event
|
|
154
|
+
* - lon: The longitude of the event
|
|
155
|
+
* - address: The address of the event
|
|
156
|
+
* @returns true if the event was processed, false otherwise
|
|
157
|
+
*/
|
|
158
|
+
async processBoundaryEvent(params) {
|
|
159
|
+
this.logger.trace(params, 'BoundariesRepository::processBoundaryEvent started with params');
|
|
160
|
+
const novaDataSource = new NovaDataSource(this.novaDataSourceConfig, this.logger);
|
|
161
|
+
const result = await processBoundaryEvent(novaDataSource, params, this.logger);
|
|
162
|
+
this.logger.trace({ result }, 'BoundariesRepository::processBoundaryEvent result');
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Upsert boundary event
|
|
167
|
+
* @param {UpsertBoundaryEventParams} params containing information to upsert boundary event
|
|
168
|
+
* - id: The id of the boundary event
|
|
169
|
+
* @returns true if the event was upserted, false otherwise
|
|
170
|
+
*/
|
|
171
|
+
async upsertBoundaryEvent(params) {
|
|
172
|
+
this.logger.trace(params, 'BoundariesRepository::upsertBoundaryEvent started with params');
|
|
173
|
+
const novaDataSource = new NovaDataSource(this.novaDataSourceConfig, this.logger);
|
|
174
|
+
const result = await upsertBoundaryEvent(novaDataSource, params, this.logger);
|
|
175
|
+
this.logger.trace({ result }, 'BoundariesRepository::upsertBoundaryEvent result');
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { BoundaryEvent, Device } from '../../entities';
|
|
2
|
+
import { BoundaryEventType } from '../../types/enums';
|
|
3
|
+
import { uuidStringToBinaryBuffer } from '../../utils/uuidHelpers';
|
|
4
|
+
const createBoundaryEvent = async (novaDataSource, params, deviceId) => {
|
|
5
|
+
const boundaryEventsRepository = novaDataSource.getRepository(BoundaryEvent);
|
|
6
|
+
const newBoundaryEvent = {
|
|
7
|
+
deviceId,
|
|
8
|
+
boundaryId: params.boundaryId,
|
|
9
|
+
userId: uuidStringToBinaryBuffer(params.userId),
|
|
10
|
+
inDate: params.eventType === BoundaryEventType.Enter ? params.sendTime : null,
|
|
11
|
+
inLat: params.eventType === BoundaryEventType.Enter ? params.lat : null,
|
|
12
|
+
inLon: params.eventType === BoundaryEventType.Enter ? params.lon : null,
|
|
13
|
+
inAddress: params.eventType === BoundaryEventType.Enter ? params.address : null,
|
|
14
|
+
outDate: params.eventType === BoundaryEventType.Exit ? params.sendTime : null,
|
|
15
|
+
outLat: params.eventType === BoundaryEventType.Exit ? params.lat : null,
|
|
16
|
+
outLon: params.eventType === BoundaryEventType.Exit ? params.lon : null,
|
|
17
|
+
outAddress: params.eventType === BoundaryEventType.Exit ? params.address : null,
|
|
18
|
+
};
|
|
19
|
+
const result = await boundaryEventsRepository.insert(newBoundaryEvent);
|
|
20
|
+
return result?.raw.affectedRows > 0;
|
|
21
|
+
};
|
|
22
|
+
const getPreviousEventDate = async (novaDataSource, params, deviceId) => {
|
|
23
|
+
let result = null;
|
|
24
|
+
const boundaryEventsRepository = novaDataSource.getRepository(BoundaryEvent);
|
|
25
|
+
// boundary events for this device, boundary and userId
|
|
26
|
+
const queryBuilder = boundaryEventsRepository
|
|
27
|
+
.createQueryBuilder('boundaryEvent')
|
|
28
|
+
.where('boundaryEvent.deviceId = :deviceId', { deviceId })
|
|
29
|
+
.andWhere('boundaryEvent.boundaryId = :boundaryId', { boundaryId: params.boundaryId })
|
|
30
|
+
.andWhere('boundaryEvent.userId = :userId', {
|
|
31
|
+
userId: uuidStringToBinaryBuffer(params.userId),
|
|
32
|
+
});
|
|
33
|
+
if (params.eventType === BoundaryEventType.Enter) {
|
|
34
|
+
// if eventType is enter, let's find the previous entry event
|
|
35
|
+
result = (await queryBuilder
|
|
36
|
+
.andWhere('boundaryEvent.inDate < :sendTime', { sendTime: params.sendTime })
|
|
37
|
+
.orderBy('boundaryEvent.inDate', 'DESC')
|
|
38
|
+
.select('boundaryEvent.inDate')
|
|
39
|
+
.limit(1)
|
|
40
|
+
.getOne())?.inDate;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// if eventType is exit, let's find the previous exit event
|
|
44
|
+
result = (await queryBuilder
|
|
45
|
+
.andWhere('boundaryEvent.outDate < :sendTime', { sendTime: params.sendTime })
|
|
46
|
+
.orderBy('boundaryEvent.outDate', 'DESC')
|
|
47
|
+
.select('boundaryEvent.outDate')
|
|
48
|
+
.limit(1)
|
|
49
|
+
.getOne())?.outDate;
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
53
|
+
const getNextEventDate = async (novaDataSource, params, deviceId) => {
|
|
54
|
+
let result = null;
|
|
55
|
+
const boundaryEventsRepository = novaDataSource.getRepository(BoundaryEvent);
|
|
56
|
+
// boundary events for this device, boundary and userId
|
|
57
|
+
const queryBuilder = boundaryEventsRepository
|
|
58
|
+
.createQueryBuilder('boundaryEvent')
|
|
59
|
+
.where('boundaryEvent.deviceId = :deviceId', { deviceId })
|
|
60
|
+
.andWhere('boundaryEvent.boundaryId = :boundaryId', { boundaryId: params.boundaryId })
|
|
61
|
+
.andWhere('boundaryEvent.userId = :userId', {
|
|
62
|
+
userId: uuidStringToBinaryBuffer(params.userId),
|
|
63
|
+
});
|
|
64
|
+
if (params.eventType === BoundaryEventType.Enter) {
|
|
65
|
+
// if eventType is enter, let's find the next entry event
|
|
66
|
+
result = (await queryBuilder
|
|
67
|
+
.andWhere('boundaryEvent.inDate > :sendTime', { sendTime: params.sendTime })
|
|
68
|
+
.orderBy('boundaryEvent.inDate', 'ASC')
|
|
69
|
+
.select('boundaryEvent.inDate')
|
|
70
|
+
.limit(1)
|
|
71
|
+
.getOne())?.inDate;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
// if eventType is exit, let's find the next exit event
|
|
75
|
+
result = (await queryBuilder
|
|
76
|
+
.andWhere('boundaryEvent.outDate > :sendTime', { sendTime: params.sendTime })
|
|
77
|
+
.orderBy('boundaryEvent.outDate', 'ASC')
|
|
78
|
+
.select('boundaryEvent.outDate')
|
|
79
|
+
.limit(1)
|
|
80
|
+
.getOne())?.outDate;
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
};
|
|
84
|
+
const calculateSecondsBetween = (date1, date2) => {
|
|
85
|
+
// Convert dates to milliseconds since the Unix epoch
|
|
86
|
+
const time1 = date1.getTime();
|
|
87
|
+
const time2 = date2.getTime();
|
|
88
|
+
// Calculate the difference in milliseconds
|
|
89
|
+
const differenceInMilliseconds = Math.abs(time2 - time1);
|
|
90
|
+
// Convert milliseconds to seconds
|
|
91
|
+
const differenceInSeconds = differenceInMilliseconds / 1000;
|
|
92
|
+
return differenceInSeconds;
|
|
93
|
+
};
|
|
94
|
+
const getOrphanEventBetweenDates = async (novaDataSource, params, deviceId, previousEventDate, nextEventDate) => {
|
|
95
|
+
let result = null;
|
|
96
|
+
const boundaryEventsRepository = novaDataSource.getRepository(BoundaryEvent);
|
|
97
|
+
// events for this device, boundary and userId
|
|
98
|
+
const queryBuilder = boundaryEventsRepository
|
|
99
|
+
.createQueryBuilder('boundaryEvent')
|
|
100
|
+
.where('boundaryEvent.deviceId = :deviceId', { deviceId })
|
|
101
|
+
.andWhere('boundaryEvent.boundaryId = :boundaryId', { boundaryId: params.boundaryId })
|
|
102
|
+
.andWhere('boundaryEvent.userId = :userId', {
|
|
103
|
+
userId: uuidStringToBinaryBuffer(params.userId),
|
|
104
|
+
});
|
|
105
|
+
if (params.eventType === BoundaryEventType.Enter) {
|
|
106
|
+
// let's find newer orphan exits (with null inDate)
|
|
107
|
+
queryBuilder
|
|
108
|
+
.andWhere('boundaryEvent.inDate IS NULL')
|
|
109
|
+
.andWhere('boundaryEvent.outDate > :sendTime', { sendTime: params.sendTime });
|
|
110
|
+
// if nextEventDate is not null, we only use orphan exits that are older than nextEventDate
|
|
111
|
+
if (nextEventDate) {
|
|
112
|
+
queryBuilder.andWhere('boundaryEvent.outDate <= :nextEventDate', { nextEventDate });
|
|
113
|
+
}
|
|
114
|
+
// order by outDate ASC, so the first result is the closests newer orphan exit
|
|
115
|
+
queryBuilder.orderBy('boundaryEvent.outDate', 'ASC');
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// let's find older orphan entries (with null outDate)
|
|
119
|
+
queryBuilder
|
|
120
|
+
.andWhere('boundaryEvent.outDate IS NULL')
|
|
121
|
+
.andWhere('boundaryEvent.inDate < :sendTime', { sendTime: params.sendTime });
|
|
122
|
+
// if previousEventDate is available, we only use orphan entries that are newer than previousEventDate
|
|
123
|
+
if (previousEventDate) {
|
|
124
|
+
queryBuilder.andWhere('boundaryEvent.inDate >= :previousEventDate', { previousEventDate });
|
|
125
|
+
}
|
|
126
|
+
if (!previousEventDate && !nextEventDate) {
|
|
127
|
+
// if no other exit exist, we use the last orphan entry
|
|
128
|
+
queryBuilder.orderBy('boundaryEvent.inDate', 'DESC');
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
// if there are other exits (previous or next), we use the first orphan entry
|
|
132
|
+
queryBuilder.orderBy('boundaryEvent.inDate', 'ASC');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// select the closest orphan entry / exit
|
|
136
|
+
result = await queryBuilder.limit(1).getOne();
|
|
137
|
+
return result;
|
|
138
|
+
};
|
|
139
|
+
export const processBoundaryEvent = async (novaDataSource, params, logger) => {
|
|
140
|
+
if (!params?.imei ||
|
|
141
|
+
!params?.boundaryId ||
|
|
142
|
+
!params?.userId ||
|
|
143
|
+
!params?.sendTime ||
|
|
144
|
+
!params?.lat ||
|
|
145
|
+
!params?.lon ||
|
|
146
|
+
!params?.address ||
|
|
147
|
+
!params?.eventType) {
|
|
148
|
+
logger.warn({ params }, 'BoundariesRepository::processBoundaryEvent - missing required parameters');
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
const userIdBinaryBuffer = uuidStringToBinaryBuffer(params.userId);
|
|
152
|
+
if (!userIdBinaryBuffer) {
|
|
153
|
+
logger.warn({ params }, 'BoundariesRepository::processBoundaryEvent - userId should be a valid uuid');
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
return novaDataSource.safeQuery(async (dataSource) => {
|
|
157
|
+
const devicesRepository = dataSource.getRepository(Device);
|
|
158
|
+
const device = await devicesRepository.findOne({
|
|
159
|
+
where: {
|
|
160
|
+
imei: params.imei,
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
// if device is not found, we can't process the event
|
|
164
|
+
if (!device) {
|
|
165
|
+
logger.warn({ params }, 'BoundariesRepository::processBoundaryEvent - device not found');
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
const boundaryEventsRepository = dataSource.getRepository(BoundaryEvent);
|
|
169
|
+
// we check if there is at least one event for this device, boundary and userId
|
|
170
|
+
const boundaryEvent = await boundaryEventsRepository.findOne({
|
|
171
|
+
where: {
|
|
172
|
+
deviceId: device.id,
|
|
173
|
+
boundaryId: params.boundaryId,
|
|
174
|
+
userId: userIdBinaryBuffer,
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
if (!boundaryEvent) {
|
|
178
|
+
// if no event exist for this device, boundary and userId, we create a new one
|
|
179
|
+
return await createBoundaryEvent(dataSource, params, device.id);
|
|
180
|
+
}
|
|
181
|
+
// at least one event exist, we obtain dates for events sorrounding the sendTime
|
|
182
|
+
const previousEventDate = await getPreviousEventDate(dataSource, params, device.id);
|
|
183
|
+
const nextEventDate = await getNextEventDate(dataSource, params, device.id);
|
|
184
|
+
logger.trace({ previousEventDate, nextEventDate }, 'BoundariesRepository::processBoundaryEvent - previousEventDate, nextEventDate');
|
|
185
|
+
// we check if there is an orphan event (entry or exit) between the previous and next event dates
|
|
186
|
+
const existingOrphanEvent = await getOrphanEventBetweenDates(dataSource, params, device.id, previousEventDate, nextEventDate);
|
|
187
|
+
logger.trace({ existingOrphanEventId: existingOrphanEvent?.id }, 'BoundariesRepository::processBoundaryEvent - existingOrphanEventId');
|
|
188
|
+
if (existingOrphanEvent != null) {
|
|
189
|
+
// an orphan event is available, let's update the entry or the exit part
|
|
190
|
+
const result = await boundaryEventsRepository.update({ id: existingOrphanEvent.id }, {
|
|
191
|
+
inDate: params.eventType === BoundaryEventType.Enter ? params.sendTime : undefined,
|
|
192
|
+
inLat: params.eventType === BoundaryEventType.Enter ? params.lat : undefined,
|
|
193
|
+
inLon: params.eventType === BoundaryEventType.Enter ? params.lon : undefined,
|
|
194
|
+
inAddress: params.eventType === BoundaryEventType.Enter ? params.address : undefined,
|
|
195
|
+
outDate: params.eventType === BoundaryEventType.Exit ? params.sendTime : undefined,
|
|
196
|
+
outLat: params.eventType === BoundaryEventType.Exit ? params.lat : undefined,
|
|
197
|
+
outLon: params.eventType === BoundaryEventType.Exit ? params.lon : undefined,
|
|
198
|
+
outAddress: params.eventType === BoundaryEventType.Exit ? params.address : undefined,
|
|
199
|
+
modifiedAt: new Date(),
|
|
200
|
+
inOutDuration: params.eventType === BoundaryEventType.Enter
|
|
201
|
+
? calculateSecondsBetween(params.sendTime, existingOrphanEvent.outDate)
|
|
202
|
+
: calculateSecondsBetween(existingOrphanEvent.inDate, params.sendTime),
|
|
203
|
+
});
|
|
204
|
+
return result.affected > 0;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
// no orphan event is available, create a new one
|
|
208
|
+
return await createBoundaryEvent(dataSource, params, device.id);
|
|
209
|
+
}
|
|
210
|
+
}, 'BoundariesRepository::processBoundaryEvent');
|
|
211
|
+
};
|