@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.
Files changed (390) hide show
  1. package/dist/entities/acumaticaAmazonProduct.js +46 -0
  2. package/dist/entities/acumaticaImeiIccidData.js +91 -0
  3. package/dist/entities/acumaticaOrderShipmentDetails.js +61 -0
  4. package/dist/entities/acumaticaShipment.js +31 -0
  5. package/dist/entities/acumaticaShipmentAmazon.js +26 -0
  6. package/dist/entities/aempToken.js +47 -0
  7. package/dist/entities/alert.js +129 -0
  8. package/dist/entities/alertMigration.js +115 -0
  9. package/dist/entities/alertMigrationBatch.js +21 -0
  10. package/dist/entities/alertTimeWindowConfiguration.js +61 -0
  11. package/dist/entities/alertType.js +83 -0
  12. package/dist/entities/appFeatureType.js +36 -0
  13. package/dist/entities/assetCategory.js +32 -0
  14. package/dist/entities/billing.js +108 -0
  15. package/dist/entities/billingCustomerBraintree.js +62 -0
  16. package/dist/entities/billingDeviceHistory.js +61 -0
  17. package/dist/entities/billingHubspotPaymentLog.js +256 -0
  18. package/dist/entities/billingKlarnaCustomer.js +76 -0
  19. package/dist/entities/billingKlarnaOrder.js +114 -0
  20. package/dist/entities/billingStatusHistoryBraintree.js +63 -0
  21. package/dist/entities/billingSubscriptionBraintree.js +229 -0
  22. package/dist/entities/blacklist.js +51 -0
  23. package/dist/entities/blacklistType.js +31 -0
  24. package/dist/entities/boundary.js +119 -0
  25. package/dist/entities/boundaryEvent.js +105 -0
  26. package/dist/entities/cellTower.js +66 -0
  27. package/dist/entities/client.js +153 -0
  28. package/dist/entities/clientAppFeature.js +47 -0
  29. package/dist/entities/clientConfiguration.js +47 -0
  30. package/dist/entities/clientDeviceSetting.js +90 -0
  31. package/dist/entities/clientType.js +36 -0
  32. package/dist/entities/country.js +90 -0
  33. package/dist/entities/customerAttribute.js +52 -0
  34. package/dist/entities/dataSourceType.js +31 -0
  35. package/dist/entities/deactivation.js +83 -0
  36. package/dist/entities/deactivationReason.js +40 -0
  37. package/dist/entities/device.js +160 -0
  38. package/dist/entities/deviceAlertConfiguration.js +71 -0
  39. package/dist/entities/deviceBehavior.js +147 -0
  40. package/dist/entities/deviceCustomConfiguration.js +67 -0
  41. package/dist/entities/deviceHistory.js +46 -0
  42. package/dist/entities/deviceModelListener.js +46 -0
  43. package/dist/entities/devicePairing.js +67 -0
  44. package/dist/entities/devicePromotion.js +104 -0
  45. package/dist/entities/deviceReplacement.js +57 -0
  46. package/dist/entities/deviceTask.js +44 -0
  47. package/dist/entities/deviceType.js +149 -0
  48. package/dist/entities/deviceTypeEvent.js +32 -0
  49. package/dist/entities/deviceTypeFeature.js +32 -0
  50. package/dist/entities/deviceTypeFirmware.js +117 -0
  51. package/dist/entities/entityTag.js +48 -0
  52. package/dist/entities/entityType.js +31 -0
  53. package/dist/entities/event.js +36 -0
  54. package/dist/entities/feature.js +36 -0
  55. package/dist/entities/firmwareAutoUpgradeBlacklist.js +35 -0
  56. package/dist/entities/firmwareUpgradeTask.js +105 -0
  57. package/dist/entities/iccidStatus.js +49 -0
  58. package/dist/entities/imeiIccidCarrier.js +125 -0
  59. package/dist/entities/imeiIccidHistory.js +43 -0
  60. package/dist/entities/index.js +99 -0
  61. package/dist/entities/industry.js +46 -0
  62. package/dist/entities/latestPosition.js +100 -0
  63. package/dist/entities/latestPositionMigration.js +96 -0
  64. package/dist/entities/latestPositionMigrationBatch.js +21 -0
  65. package/dist/entities/magento2Gps.js +256 -0
  66. package/dist/entities/magento2Plan.js +41 -0
  67. package/dist/entities/mobileNetwork.js +51 -0
  68. package/dist/entities/notificationRecipient.js +100 -0
  69. package/dist/entities/organization.js +46 -0
  70. package/dist/entities/plan.js +86 -0
  71. package/dist/entities/position.js +102 -0
  72. package/dist/entities/positionMigration.js +96 -0
  73. package/dist/entities/positionMigrationBatch.js +21 -0
  74. package/dist/entities/promotion.js +134 -0
  75. package/dist/entities/securityRole.js +41 -0
  76. package/dist/entities/serviceProvider.js +41 -0
  77. package/dist/entities/serviceProviderProduct.js +61 -0
  78. package/dist/entities/serviceProviderProductNetwork.js +31 -0
  79. package/dist/entities/serviceProviderProductType.js +31 -0
  80. package/dist/entities/sim.js +92 -0
  81. package/dist/entities/task.js +146 -0
  82. package/dist/entities/taskSchedule.js +141 -0
  83. package/dist/entities/trip.js +127 -0
  84. package/dist/entities/tripCompletionStatus.js +36 -0
  85. package/dist/entities/tripPosition.js +26 -0
  86. package/dist/entities/user.js +196 -0
  87. package/dist/entities/userActivation.js +52 -0
  88. package/dist/entities/userActivationDevice.js +164 -0
  89. package/dist/entities/userActivationEvent.js +61 -0
  90. package/dist/entities/userActivationMetric.js +208 -0
  91. package/dist/entities/userAlertComplain.js +78 -0
  92. package/dist/entities/userAlertConfiguration.js +109 -0
  93. package/dist/entities/userAppFeedback.js +52 -0
  94. package/dist/entities/userAppIncident.js +176 -0
  95. package/dist/entities/userConfiguration.js +109 -0
  96. package/dist/entities/userDataDeletionRequest.js +56 -0
  97. package/dist/entities/userDeviceBehaviorTask.js +80 -0
  98. package/dist/entities/userInvitation.js +89 -0
  99. package/dist/entities/userRatingRequest.js +75 -0
  100. package/dist/entities/userRegistrationAttempt.js +177 -0
  101. package/dist/entities/userSecurityRole.js +33 -0
  102. package/dist/index.js +1 -2
  103. package/dist/migration/1684483704434-addLowerCaseIndex.js +16 -0
  104. package/dist/novaDataSource.js +111 -0
  105. package/dist/repositories/acumatica/getAcumaticaImeiIccidData.js +35 -0
  106. package/dist/repositories/acumatica/getAcumaticaShipmentDetails.js +50 -0
  107. package/dist/repositories/acumatica/getLastAcumaticaShipmentDetails.js +27 -0
  108. package/dist/repositories/acumatica/index.js +52 -0
  109. package/dist/repositories/aempToken/createAempToken.js +26 -0
  110. package/dist/repositories/aempToken/deleteAempTokens.js +30 -0
  111. package/dist/repositories/aempToken/getAempTokens.js +27 -0
  112. package/dist/repositories/aempToken/index.js +53 -0
  113. package/dist/repositories/alertTypes/getAlertTypes.js +13 -0
  114. package/dist/repositories/alertTypes/index.js +18 -0
  115. package/dist/repositories/alerts/createAlert.js +94 -0
  116. package/dist/repositories/alerts/createUserAlertComplain.js +26 -0
  117. package/dist/repositories/alerts/getAlertsReportByClient.js +65 -0
  118. package/dist/repositories/alerts/getAlertsReportByUser.js +127 -0
  119. package/dist/repositories/alerts/index.js +104 -0
  120. package/dist/repositories/appFeatures/createAppFeatureType.js +15 -0
  121. package/dist/repositories/appFeatures/createClientAppFeature.js +15 -0
  122. package/dist/repositories/appFeatures/getClientAppFeatures.js +39 -0
  123. package/dist/repositories/appFeatures/index.js +57 -0
  124. package/dist/repositories/assetCategories/getAssetCategories.js +8 -0
  125. package/dist/repositories/assetCategories/index.js +16 -0
  126. package/dist/repositories/baseRepository.js +9 -0
  127. package/dist/repositories/billing/createBilling.js +37 -0
  128. package/dist/repositories/billing/createBillingDeviceHistory.js +30 -0
  129. package/dist/repositories/billing/createBillingHubspotPaymentLog.js +61 -0
  130. package/dist/repositories/billing/createBillingStatusHistoryBraintree.js +32 -0
  131. package/dist/repositories/billing/getBillingCustomerBraintreeById.js +18 -0
  132. package/dist/repositories/billing/getBillingKlarnaOrderByImei.js +18 -0
  133. package/dist/repositories/billing/getBillingSubscriptionBraintreeByImei.js +18 -0
  134. package/dist/repositories/billing/getBillingSubscriptionsBraintree.js +25 -0
  135. package/dist/repositories/billing/getBillings.js +42 -0
  136. package/dist/repositories/billing/getCanceledImeis.js +84 -0
  137. package/dist/repositories/billing/getCanceledImeisMatchingMagentoData.js +100 -0
  138. package/dist/repositories/billing/getChurnStatusByClientId.js +27 -0
  139. package/dist/repositories/billing/getClientIdFromBraintreeCustomer.js +20 -0
  140. package/dist/repositories/billing/getMagentoPlan.js +21 -0
  141. package/dist/repositories/billing/getUserByBraintreeCustomerId.js +22 -0
  142. package/dist/repositories/billing/index.js +353 -0
  143. package/dist/repositories/billing/updateBilling.js +43 -0
  144. package/dist/repositories/billing/updateBillingCustomerBraintree.js +37 -0
  145. package/dist/repositories/billing/upsertBillingCustomerBraintree.js +39 -0
  146. package/dist/repositories/billing/upsertBillingKlarnaCustomer.js +52 -0
  147. package/dist/repositories/billing/upsertBillingKlarnaOrder.js +58 -0
  148. package/dist/repositories/billing/upsertBillingSubscriptionBraintree.js +20 -0
  149. package/dist/repositories/blacklist/getBlacklists.js +19 -0
  150. package/dist/repositories/blacklist/index.js +19 -0
  151. package/dist/repositories/boundaries/createBoundary.js +52 -0
  152. package/dist/repositories/boundaries/deleteBoundary.js +23 -0
  153. package/dist/repositories/boundaries/getBoundariesByClientId.js +17 -0
  154. package/dist/repositories/boundaries/getBoundariesIdsByClientId.js +19 -0
  155. package/dist/repositories/boundaries/getBoundariesReport.js +141 -0
  156. package/dist/repositories/boundaries/getBoundaryById.js +14 -0
  157. package/dist/repositories/boundaries/index.js +178 -0
  158. package/dist/repositories/boundaries/processBoundaryEvent.js +211 -0
  159. package/dist/repositories/boundaries/updateBoundary.js +53 -0
  160. package/dist/repositories/boundaries/upsertBoundaryEvent.js +23 -0
  161. package/dist/repositories/clients/createClient.js +35 -0
  162. package/dist/repositories/clients/createClientConfiguration.js +18 -0
  163. package/dist/repositories/clients/createCustomerAttribute.js +16 -0
  164. package/dist/repositories/clients/deleteClientAndConfiguration.js +25 -0
  165. package/dist/repositories/clients/getClient.js +32 -0
  166. package/dist/repositories/clients/getClientConfiguration.js +14 -0
  167. package/dist/repositories/clients/getClients.js +26 -0
  168. package/dist/repositories/clients/getCustomerAttribute.js +14 -0
  169. package/dist/repositories/clients/index.js +192 -0
  170. package/dist/repositories/clients/updateClient.js +52 -0
  171. package/dist/repositories/clients/updateClientConfiguration.js +31 -0
  172. package/dist/repositories/clients/updateCustomerAttribute.js +27 -0
  173. package/dist/repositories/countries/getCountries.js +14 -0
  174. package/dist/repositories/countries/getCountry.js +23 -0
  175. package/dist/repositories/countries/index.js +33 -0
  176. package/dist/repositories/deactivations/createDeactivation.js +16 -0
  177. package/dist/repositories/deactivations/getDeactivationReasons.js +24 -0
  178. package/dist/repositories/deactivations/getLatestDeactivationByImei.js +19 -0
  179. package/dist/repositories/deactivations/index.js +58 -0
  180. package/dist/repositories/deviceBehaviors/createDeviceBehaviorTask.js +48 -0
  181. package/dist/repositories/deviceBehaviors/getDeviceBehaviorTasks.js +40 -0
  182. package/dist/repositories/deviceBehaviors/getDeviceBehaviors.js +41 -0
  183. package/dist/repositories/deviceBehaviors/getDeviceBehaviorsByIds.js +16 -0
  184. package/dist/repositories/deviceBehaviors/getDevicesLastBehaviorTask.js +42 -0
  185. package/dist/repositories/deviceBehaviors/getLatestDeviceBehaviorTasks.js +40 -0
  186. package/dist/repositories/deviceBehaviors/index.js +147 -0
  187. package/dist/repositories/deviceBehaviors/updateDeviceBehaviorTask.js +27 -0
  188. package/dist/repositories/deviceBehaviors/upsertDeviceBehavior.js +20 -0
  189. package/dist/repositories/devicePairings/createDevicePairing.js +21 -0
  190. package/dist/repositories/devicePairings/deleteDevicePairing.js +16 -0
  191. package/dist/repositories/devicePairings/getDevicePairings.js +36 -0
  192. package/dist/repositories/devicePairings/getDevicePairingsByImei.js +20 -0
  193. package/dist/repositories/devicePairings/index.js +90 -0
  194. package/dist/repositories/devicePairings/updateDevicePairing.js +32 -0
  195. package/dist/repositories/devices/createClientDeviceSetting.js +25 -0
  196. package/dist/repositories/devices/createDevice.js +30 -0
  197. package/dist/repositories/devices/createDeviceReplacement.js +34 -0
  198. package/dist/repositories/devices/createDeviceType.js +15 -0
  199. package/dist/repositories/devices/deleteDevice.js +16 -0
  200. package/dist/repositories/devices/generateDeviceIdentifierKey.js +18 -0
  201. package/dist/repositories/devices/getCanceledDevicesWithActiveSimCards.js +40 -0
  202. package/dist/repositories/devices/getCarrierStatusUpdatedBefore.js +40 -0
  203. package/dist/repositories/devices/getClientDeviceSetting.js +20 -0
  204. package/dist/repositories/devices/getClientDeviceSettings.js +17 -0
  205. package/dist/repositories/devices/getDevice.js +33 -0
  206. package/dist/repositories/devices/getDeviceCustomConfig.js +37 -0
  207. package/dist/repositories/devices/getDeviceTypeByImei.js +18 -0
  208. package/dist/repositories/devices/getDeviceTypes.js +30 -0
  209. package/dist/repositories/devices/getDeviceTypesModelsOrderedByDeviceCount.js +27 -0
  210. package/dist/repositories/devices/getDeviceWithUsersInfo.js +59 -0
  211. package/dist/repositories/devices/getDevices.js +46 -0
  212. package/dist/repositories/devices/getFilteredImeisWithStatus.js +20 -0
  213. package/dist/repositories/devices/getIccidStatus.js +17 -0
  214. package/dist/repositories/devices/getImeiIccidCarrier.js +23 -0
  215. package/dist/repositories/devices/getImeiIccidCarriers.js +17 -0
  216. package/dist/repositories/devices/index.js +464 -0
  217. package/dist/repositories/devices/updateClientDeviceSetting.js +38 -0
  218. package/dist/repositories/devices/updateDevice.js +56 -0
  219. package/dist/repositories/devices/updateDeviceType.js +43 -0
  220. package/dist/repositories/devices/updateIccidStatus.js +28 -0
  221. package/dist/repositories/devices/updateImeiIccidCarrier.js +43 -0
  222. package/dist/repositories/devices/upsertIccidStatus.js +36 -0
  223. package/dist/repositories/firmwares/createDeviceFirmware.js +37 -0
  224. package/dist/repositories/firmwares/createFirmwareAutoUpgradeBlacklist.js +16 -0
  225. package/dist/repositories/firmwares/createFirmwareUpgradeTask.js +36 -0
  226. package/dist/repositories/firmwares/getDeviceFirmwares.js +21 -0
  227. package/dist/repositories/firmwares/getFirmwareAutoUpgradeBlacklist.js +23 -0
  228. package/dist/repositories/firmwares/getFirmwareUpgradeTasks.js +105 -0
  229. package/dist/repositories/firmwares/getFirmwareUpgradeTasksCount.js +56 -0
  230. package/dist/repositories/firmwares/index.js +194 -0
  231. package/dist/repositories/firmwares/updateDeviceFirmware.js +41 -0
  232. package/dist/repositories/firmwares/updateFirmwareUpgradeTasks.js +37 -0
  233. package/dist/repositories/index.js +31 -0
  234. package/dist/repositories/notificationRecipients/createNotificationRecipient.js +37 -0
  235. package/dist/repositories/notificationRecipients/deleteNotificationRecipients.js +26 -0
  236. package/dist/repositories/notificationRecipients/deleteNotificationRecipientsByEmailOrPhone.js +28 -0
  237. package/dist/repositories/notificationRecipients/getNotificationRecipients.js +16 -0
  238. package/dist/repositories/notificationRecipients/index.js +131 -0
  239. package/dist/repositories/notificationRecipients/updateNotificationRecipient.js +37 -0
  240. package/dist/repositories/notificationRecipients/updateUsersNotificationsUnsubscribedInfoStatus.js +98 -0
  241. package/dist/repositories/notificationRecipients/updateUsersNotificationsUnsuscribedStatus.js +35 -0
  242. package/dist/repositories/positions/createPosition.js +100 -0
  243. package/dist/repositories/positions/getLatestPositionByImei.js +26 -0
  244. package/dist/repositories/positions/getPositionsByImei.js +23 -0
  245. package/dist/repositories/positions/getPositionsReportByClient.js +87 -0
  246. package/dist/repositories/positions/index.js +101 -0
  247. package/dist/repositories/positions/upsertLatestPosition.js +41 -0
  248. package/dist/repositories/security/createUserRole.js +30 -0
  249. package/dist/repositories/security/getAllRoles.js +8 -0
  250. package/dist/repositories/security/getUserRoles.js +15 -0
  251. package/dist/repositories/security/getUserRolesByClientId.js +17 -0
  252. package/dist/repositories/security/index.js +111 -0
  253. package/dist/repositories/security/removeUserRoles.js +21 -0
  254. package/dist/repositories/security/updateUserRole.js +27 -0
  255. package/dist/repositories/security/userIsAdminOrOwner.js +20 -0
  256. package/dist/repositories/security/userIsInRole.js +18 -0
  257. package/dist/repositories/tasks/addTaskScheduleDevices.js +37 -0
  258. package/dist/repositories/tasks/completeTask.js +25 -0
  259. package/dist/repositories/tasks/createTask.js +22 -0
  260. package/dist/repositories/tasks/createTaskSchedule.js +33 -0
  261. package/dist/repositories/tasks/deleteTask.js +22 -0
  262. package/dist/repositories/tasks/deleteTaskSchedule.js +22 -0
  263. package/dist/repositories/tasks/deleteTaskScheduleDevices.js +17 -0
  264. package/dist/repositories/tasks/getDeviceTasks.js +28 -0
  265. package/dist/repositories/tasks/getTaskSchedule.js +31 -0
  266. package/dist/repositories/tasks/getTaskSchedules.js +75 -0
  267. package/dist/repositories/tasks/getTaskSchedulesCount.js +23 -0
  268. package/dist/repositories/tasks/getTasks.js +29 -0
  269. package/dist/repositories/tasks/getTasksCount.js +20 -0
  270. package/dist/repositories/tasks/index.js +441 -0
  271. package/dist/repositories/tasks/setTaskAsPastDue.js +23 -0
  272. package/dist/repositories/tasks/setTaskScheduleDevices.js +43 -0
  273. package/dist/repositories/tasks/updateTask.js +21 -0
  274. package/dist/repositories/tasks/updateTaskSchedule.js +35 -0
  275. package/dist/repositories/trips/createTrip.js +29 -0
  276. package/dist/repositories/trips/getTripById.js +15 -0
  277. package/dist/repositories/trips/getTrips.js +65 -0
  278. package/dist/repositories/trips/index.js +69 -0
  279. package/dist/repositories/trips/updateTripEndValues.js +36 -0
  280. package/dist/repositories/trips/upsertTrip.js +31 -0
  281. package/dist/repositories/userActivations/createUserActivation.js +26 -0
  282. package/dist/repositories/userActivations/createUserActivationDevice.js +35 -0
  283. package/dist/repositories/userActivations/createUserActivationEvent.js +34 -0
  284. package/dist/repositories/userActivations/createUserActivationMetric.js +28 -0
  285. package/dist/repositories/userActivations/deleteUserActivation.js +22 -0
  286. package/dist/repositories/userActivations/getLastActivationDevice.js +26 -0
  287. package/dist/repositories/userActivations/getUserActivationDevices.js +24 -0
  288. package/dist/repositories/userActivations/getUserActivationDevicesByClientId.js +26 -0
  289. package/dist/repositories/userActivations/getUserActivationMetrics.js +24 -0
  290. package/dist/repositories/userActivations/getUserActivations.js +29 -0
  291. package/dist/repositories/userActivations/index.js +229 -0
  292. package/dist/repositories/userActivations/updateUserActivationDevice.js +39 -0
  293. package/dist/repositories/userActivations/updateUserActivationMetrics.js +61 -0
  294. package/dist/repositories/userAppFeedback/createUserAppFeedback.js +26 -0
  295. package/dist/repositories/userAppFeedback/index.js +23 -0
  296. package/dist/repositories/userAppIncidents/getUserAppIncidents.js +28 -0
  297. package/dist/repositories/userAppIncidents/index.js +63 -0
  298. package/dist/repositories/userAppIncidents/upsertUserAppIncident.js +53 -0
  299. package/dist/repositories/userConfigurations/bulkCreateUserAlertConfigurations.js +46 -0
  300. package/dist/repositories/userConfigurations/createDeviceAlertTimeWindows.js +36 -0
  301. package/dist/repositories/userConfigurations/createUserAlertTimeWindows.js +33 -0
  302. package/dist/repositories/userConfigurations/createUserConfiguration.js +34 -0
  303. package/dist/repositories/userConfigurations/deleteDeviceAlertTimeWindows.js +17 -0
  304. package/dist/repositories/userConfigurations/deleteUserAlertConfigurations.js +24 -0
  305. package/dist/repositories/userConfigurations/deleteUserAlertTimeWindows.js +17 -0
  306. package/dist/repositories/userConfigurations/deleteUserConfiguration.js +23 -0
  307. package/dist/repositories/userConfigurations/getDeviceAlertTimeWindows.js +43 -0
  308. package/dist/repositories/userConfigurations/getUserAlertConfigurations.js +25 -0
  309. package/dist/repositories/userConfigurations/getUserAlertTimeWindows.js +35 -0
  310. package/dist/repositories/userConfigurations/getUserConfigurations.js +31 -0
  311. package/dist/repositories/userConfigurations/index.js +298 -0
  312. package/dist/repositories/userConfigurations/updateDeviceAlertTimeWindows.js +29 -0
  313. package/dist/repositories/userConfigurations/updateUserAlertConfigurations.js +46 -0
  314. package/dist/repositories/userConfigurations/updateUserAlertTimeWindows.js +28 -0
  315. package/dist/repositories/userConfigurations/updateUserConfiguration.js +49 -0
  316. package/dist/repositories/userDataDeletionRequests/createUserDataDeletionRequest.js +28 -0
  317. package/dist/repositories/userDataDeletionRequests/getUserDataDeletionRequest.js +29 -0
  318. package/dist/repositories/userDataDeletionRequests/index.js +66 -0
  319. package/dist/repositories/userDataDeletionRequests/removeUserDataDeletionRequest.js +17 -0
  320. package/dist/repositories/userDataDeletionRequests/updateUserDataDeletionRequest.js +38 -0
  321. package/dist/repositories/userInvitations/createUserInvitation.js +43 -0
  322. package/dist/repositories/userInvitations/getUserInvitationById.js +22 -0
  323. package/dist/repositories/userInvitations/getUserInvitations.js +31 -0
  324. package/dist/repositories/userInvitations/index.js +82 -0
  325. package/dist/repositories/userInvitations/updateUserInvitation.js +50 -0
  326. package/dist/repositories/userRatingRequests/createUserRatingRequest.js +34 -0
  327. package/dist/repositories/userRatingRequests/getUserRatingRequests.js +23 -0
  328. package/dist/repositories/userRatingRequests/index.js +41 -0
  329. package/dist/repositories/userRegistrationAttempts/createUserRegistrationAttempt.js +40 -0
  330. package/dist/repositories/userRegistrationAttempts/getUserRegistrationAttempts.js +29 -0
  331. package/dist/repositories/userRegistrationAttempts/index.js +70 -0
  332. package/dist/repositories/userRegistrationAttempts/updateUserRegistrationAttempt.js +40 -0
  333. package/dist/repositories/users/createUser.js +47 -0
  334. package/dist/repositories/users/deleteAccount.js +98 -0
  335. package/dist/repositories/users/deleteUser.js +22 -0
  336. package/dist/repositories/users/getUserById.js +22 -0
  337. package/dist/repositories/users/getUserData.js +66 -0
  338. package/dist/repositories/users/getUsers.js +49 -0
  339. package/dist/repositories/users/getUsersConfigurationByImei.js +29 -0
  340. package/dist/repositories/users/getUsersIdByPhoneAndCountryCode.js +21 -0
  341. package/dist/repositories/users/getUsersWithRoles.js +32 -0
  342. package/dist/repositories/users/index.js +195 -0
  343. package/dist/repositories/users/updateUser.js +109 -0
  344. package/dist/subscribers/allEntitiesSubscriber.js +52 -0
  345. package/dist/subscribers/index.js +2 -0
  346. package/dist/types/acumatica.js +1 -0
  347. package/dist/types/aempToken.js +1 -0
  348. package/dist/types/alert.js +1 -0
  349. package/dist/types/alertTypes.js +1 -0
  350. package/dist/types/appFeatures.js +1 -0
  351. package/dist/types/billing.js +1 -0
  352. package/dist/types/blacklist.js +1 -0
  353. package/dist/types/boundaries.js +1 -0
  354. package/dist/types/clients.js +1 -0
  355. package/dist/types/common.js +1 -0
  356. package/dist/types/countries.js +1 -0
  357. package/dist/types/deactivations.js +1 -0
  358. package/dist/types/deviceBehaviors.js +1 -0
  359. package/dist/types/devicePairings.js +1 -0
  360. package/dist/types/devices.js +1 -0
  361. package/dist/types/enums.js +74 -0
  362. package/dist/types/firmwares.js +17 -0
  363. package/dist/types/index.js +30 -0
  364. package/dist/types/logger.js +9 -0
  365. package/dist/types/notificationRecipients.js +1 -0
  366. package/dist/types/position.js +1 -0
  367. package/dist/types/security.js +1 -0
  368. package/dist/types/tasks.js +1 -0
  369. package/dist/types/trip.js +29 -0
  370. package/dist/types/user.js +1 -0
  371. package/dist/types/userActivations.js +1 -0
  372. package/dist/types/userAppFeedback.js +1 -0
  373. package/dist/types/userAppIncidents.js +1 -0
  374. package/dist/types/userConfigurations.js +1 -0
  375. package/dist/types/userDataDeletionRequests.js +1 -0
  376. package/dist/types/userInvitations.js +1 -0
  377. package/dist/types/userRatingRequests.js +1 -0
  378. package/dist/types/userRegistrationAttempts.js +1 -0
  379. package/dist/utils/anyAttributeHasValue.js +20 -0
  380. package/dist/utils/anyAttributeIsNull.js +12 -0
  381. package/dist/utils/boolToNumberTransformer.js +23 -0
  382. package/dist/utils/consoleLogger.js +42 -0
  383. package/dist/utils/filterTools.js +299 -0
  384. package/dist/utils/mapRawEntityToEntity.js +12 -0
  385. package/dist/utils/queryLogger.js +48 -0
  386. package/dist/utils/randomizer.js +39 -0
  387. package/dist/utils/stringToDateTransformer.js +16 -0
  388. package/dist/utils/uuidHelpers.js +30 -0
  389. package/package.json +10 -8
  390. 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
+ };