mobioffice-cli 1.0.0 → 1.0.1

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 (253) hide show
  1. package/{src/index.ts → lib/index.d.ts} +1 -45
  2. package/lib/models/Feed-Details-Screen.model.d.ts +6 -0
  3. package/lib/models/Feed-Details-Screen.model.js +27 -0
  4. package/lib/models/action.model.d.ts +58 -0
  5. package/lib/models/action.model.js +315 -0
  6. package/lib/models/actions/doffing.d.ts +6 -0
  7. package/lib/models/actions/doffing.js +64 -0
  8. package/lib/models/actions/folding.d.ts +7 -0
  9. package/lib/models/actions/folding.js +37 -0
  10. package/lib/models/attendance.model.d.ts +44 -0
  11. package/lib/models/attendance.model.js +446 -0
  12. package/lib/models/cicoPost.model.d.ts +9 -0
  13. package/lib/models/cicoPost.model.js +19 -0
  14. package/lib/models/company.model.d.ts +67 -0
  15. package/lib/models/company.model.js +725 -0
  16. package/lib/models/contact-us/resquest.model.d.ts +30 -0
  17. package/lib/models/contact-us/resquest.model.js +73 -0
  18. package/lib/models/crud/crud.d.ts +7 -0
  19. package/lib/models/crud/crud.js +27 -0
  20. package/lib/models/customCollection.model.d.ts +9 -0
  21. package/lib/models/customCollection.model.js +40 -0
  22. package/lib/models/customer/customer.model.d.ts +32 -0
  23. package/lib/models/customer/customer.model.js +62 -0
  24. package/lib/models/deviceChangeReq.d.ts +10 -0
  25. package/lib/models/deviceChangeReq.js +138 -0
  26. package/lib/models/dispatch.model.d.ts +14 -0
  27. package/lib/models/dispatch.model.js +93 -0
  28. package/lib/models/feed.models.d.ts +8 -0
  29. package/lib/models/feed.models.js +97 -0
  30. package/lib/models/geofence.model.d.ts +7 -0
  31. package/lib/models/geofence.model.js +61 -0
  32. package/lib/models/leaveApplicationPost.model.d.ts +12 -0
  33. package/lib/models/leaveApplicationPost.model.js +72 -0
  34. package/lib/models/license.model.d.ts +25 -0
  35. package/lib/models/license.model.js +198 -0
  36. package/lib/models/log.model.d.ts +6 -0
  37. package/{src/models/log.model.ts → lib/models/log.model.js} +11 -11
  38. package/lib/models/meeting.model.d.ts +11 -0
  39. package/lib/models/meeting.model.js +79 -0
  40. package/lib/models/meter.model.d.ts +18 -0
  41. package/lib/models/meter.model.js +54 -0
  42. package/lib/models/missingPunchPost.model.d.ts +15 -0
  43. package/lib/models/missingPunchPost.model.js +69 -0
  44. package/lib/models/offline.model.d.ts +70 -0
  45. package/lib/models/offline.model.js +831 -0
  46. package/lib/models/post.model.d.ts +38 -0
  47. package/lib/models/post.model.js +94 -0
  48. package/lib/models/printDetailsScreen.model.d.ts +6 -0
  49. package/lib/models/printDetailsScreen.model.js +27 -0
  50. package/lib/models/pushNotifications/pushNotification.model.d.ts +4 -0
  51. package/lib/models/pushNotifications/pushNotification.model.js +17 -0
  52. package/lib/models/report-actions.model.d.ts +26 -0
  53. package/lib/models/report-actions.model.js +56 -0
  54. package/lib/models/report-definition-details.model.d.ts +13 -0
  55. package/lib/models/report-definition-details.model.js +85 -0
  56. package/lib/models/report-definition.model.d.ts +23 -0
  57. package/lib/models/report-definition.model.js +26 -0
  58. package/lib/models/report-definitions-summary.model.d.ts +8 -0
  59. package/lib/models/report-definitions-summary.model.js +59 -0
  60. package/lib/models/report-detail-data.model.d.ts +46 -0
  61. package/lib/models/report-detail-data.model.js +49 -0
  62. package/lib/models/report-visibility.model.d.ts +7 -0
  63. package/lib/models/report-visibility.model.js +42 -0
  64. package/lib/models/report.model.d.ts +19 -0
  65. package/lib/models/report.model.js +138 -0
  66. package/lib/models/reportGenerator.model.d.ts +164 -0
  67. package/lib/models/reportGenerator.model.js +642 -0
  68. package/lib/models/response.model.d.ts +18 -0
  69. package/lib/models/response.model.js +30 -0
  70. package/lib/models/steps.factory.model.d.ts +172 -0
  71. package/lib/models/steps.factory.model.js +187 -0
  72. package/lib/models/storeGupShupLog.model.d.ts +6 -0
  73. package/lib/models/storeGupShupLog.model.js +51 -0
  74. package/lib/models/summary.model.d.ts +10 -0
  75. package/{src/models/summary.model.ts → lib/models/summary.model.js} +28 -27
  76. package/lib/models/tasks/sub-task-group.model.d.ts +42 -0
  77. package/lib/models/tasks/sub-task-group.model.js +154 -0
  78. package/lib/models/tasks/tags.model.d.ts +29 -0
  79. package/lib/models/tasks/tags.model.js +70 -0
  80. package/lib/models/tasks/task-group.model.d.ts +53 -0
  81. package/lib/models/tasks/task-group.model.js +156 -0
  82. package/lib/models/tasks/task.model.d.ts +163 -0
  83. package/lib/models/tasks/task.model.js +603 -0
  84. package/lib/models/tempCollection.model.d.ts +40 -0
  85. package/{src/models/tempCollection.model.ts → lib/models/tempCollection.model.js} +114 -130
  86. package/lib/models/user.model.d.ts +42 -0
  87. package/lib/models/user.model.js +272 -0
  88. package/lib/models/utility.model.d.ts +13 -0
  89. package/lib/models/utility.model.js +93 -0
  90. package/lib/models/visitorManagement/acknowledgement.model.d.ts +9 -0
  91. package/lib/models/visitorManagement/acknowledgement.model.js +55 -0
  92. package/lib/models/visitorManagement/invite.model.d.ts +32 -0
  93. package/lib/models/visitorManagement/invite.model.js +326 -0
  94. package/lib/models/visitorManagement/newIn.model.d.ts +19 -0
  95. package/lib/models/visitorManagement/newIn.model.js +67 -0
  96. package/lib/models/visitorManagement/selfServe.model.d.ts +13 -0
  97. package/lib/models/visitorManagement/selfServe.model.js +46 -0
  98. package/lib/models/worklogPost.model.d.ts +6 -0
  99. package/lib/models/worklogPost.model.js +9 -0
  100. package/lib/services/customer.d.ts +30 -0
  101. package/lib/services/customer.js +354 -0
  102. package/lib/services/meeting.d.ts +19 -0
  103. package/lib/services/meeting.js +109 -0
  104. package/package.json +4 -1
  105. package/.prettierrc +0 -4
  106. package/a.js +0 -3
  107. package/scripts/1.ts +0 -1300
  108. package/scripts/GCloudPubSub/pub-sub-config.json +0 -12
  109. package/scripts/GCloudPubSub/visitorAutoRejection.ts +0 -86
  110. package/scripts/actions/assignUsersFromOneActionToOther.ts +0 -64
  111. package/scripts/actions/assignUsersListToAction.ts +0 -81
  112. package/scripts/actions/getActionsListOfUser.ts +0 -42
  113. package/scripts/actions/getCompanyUserDetails.ts +0 -49
  114. package/scripts/actions/giveActionToUser.ts +0 -41
  115. package/scripts/actions/giveUsersToActivitySelector.ts +0 -56
  116. package/scripts/actions/groupActionsInActivitySelector.ts +0 -101
  117. package/scripts/actions/modifySummaryReportDB.ts +0 -42
  118. package/scripts/actions/setUrlToActionStep.ts +0 -18
  119. package/scripts/actions/syncMySqlAttendanceDBWithFirebase.ts +0 -93
  120. package/scripts/actions/syncMySqlMeetingsDBWithFirebase.ts +0 -103
  121. package/scripts/actions/test.ts +0 -29
  122. package/scripts/actions/transferFeedsOldIdToNew.ts +0 -40
  123. package/scripts/actions/transformUserIntoManager.ts +0 -89
  124. package/scripts/argvConfig.js +0 -9
  125. package/scripts/backUpData/testCode.ts +0 -131
  126. package/scripts/benaraScripts/addWorkAreaMap.ts +0 -46
  127. package/scripts/benaraScripts/add_customers.ts +0 -26
  128. package/scripts/benaraScripts/add_customers_contact.ts +0 -27
  129. package/scripts/benaraScripts/add_empty_work_area.ts +0 -17
  130. package/scripts/benaraScripts/assignManagers.ts +0 -35
  131. package/scripts/benaraScripts/changeCheckInFlag.ts +0 -45
  132. package/scripts/benaraScripts/createCustomerContactsList.ts +0 -170
  133. package/scripts/benaraScripts/createUserByDeletingOldUser.ts +0 -70
  134. package/scripts/benaraScripts/createUsersAreaMapCollection.ts +0 -23
  135. package/scripts/benaraScripts/createWorkAreaMap.ts +0 -24
  136. package/scripts/benaraScripts/mapWorkAreasToUsers.ts +0 -112
  137. package/scripts/companies_data.json +0 -2496
  138. package/scripts/create_or_update_users.ts +0 -31
  139. package/scripts/csvToJson/csvToJson.ts +0 -90
  140. package/scripts/csvToJson/users.json +0 -3896
  141. package/scripts/db.js +0 -27
  142. package/scripts/db.json +0 -13
  143. package/scripts/dbMySql.ts +0 -63
  144. package/scripts/delete_action_steps.ts +0 -11
  145. package/scripts/delete_user.ts +0 -71
  146. package/scripts/dev_companies_data.json +0 -613
  147. package/scripts/enroll.xlsx +0 -0
  148. package/scripts/export_users.ts +0 -72
  149. package/scripts/files/visitorManagementFiles/displayScreen.json +0 -70
  150. package/scripts/files/visitorManagementFiles/init_report_visibility.ts +0 -79
  151. package/scripts/firebaseConfig.js +0 -12
  152. package/scripts/firebaseDocs/deleteIncommingCollection.ts +0 -47
  153. package/scripts/firebaseDocs/updateDoc.ts +0 -43
  154. package/scripts/getActionDataIntoJSON/getActionData.ts +0 -68
  155. package/scripts/get_attendance_by_any_date.ts +0 -14
  156. package/scripts/get_attendance_by_month.ts +0 -12
  157. package/scripts/get_attendance_monthly_by_team.ts +0 -11
  158. package/scripts/get_daily_report.ts +0 -10
  159. package/scripts/get_mangers.ts +0 -13
  160. package/scripts/grant_user_license.ts +0 -18
  161. package/scripts/init_CustomCollection.ts +0 -16
  162. package/scripts/init_action_steps.ts +0 -28
  163. package/scripts/init_actions.ts +0 -31
  164. package/scripts/init_company.ts +0 -18
  165. package/scripts/init_customer_mysql.ts +0 -12
  166. package/scripts/init_feed.ts +0 -4
  167. package/scripts/init_feed_details_screen.ts +0 -14
  168. package/scripts/init_geofence.ts +0 -26
  169. package/scripts/init_print_details_screen.ts +0 -14
  170. package/scripts/init_report_actions.ts +0 -24
  171. package/scripts/init_report_definition_detail.ts +0 -26
  172. package/scripts/init_report_definition_summary.ts +0 -16
  173. package/scripts/init_report_visibility.ts +0 -46
  174. package/scripts/init_user_customcollection.ts +0 -16
  175. package/scripts/json/action.json +0 -21
  176. package/scripts/json/company.json +0 -24
  177. package/scripts/json/report-action.json +0 -13
  178. package/scripts/json/report-def-deet.json +0 -43
  179. package/scripts/json/resp.json +0 -784
  180. package/scripts/json/steps.json +0 -24
  181. package/scripts/json/test.ts +0 -49
  182. package/scripts/mysqlConfig.ts +0 -9
  183. package/scripts/revoke_or_extend_license.ts +0 -14
  184. package/scripts/stream.js +0 -4
  185. package/scripts/testing1.ts +0 -35
  186. package/scripts/update/doc.json +0 -20
  187. package/scripts/update/getDocByPath.ts +0 -34
  188. package/scripts/update/updateDocByPath.ts +0 -47
  189. package/scripts/update/updateUsersOfCompanies.ts +0 -58
  190. package/scripts/update_actions.ts +0 -19
  191. package/scripts/update_actions_steps.ts +0 -19
  192. package/scripts/update_company.ts +0 -19
  193. package/scripts/update_geofence.ts +0 -20
  194. package/scripts/update_managers.ts +0 -16
  195. package/scripts/visitorMgmt/createArea.ts +0 -68
  196. package/scripts/visitorMgmt/createArea.txt +0 -3
  197. package/scripts/visitorMgmt/createVisitorPathInstructionDocs.ts +0 -130
  198. package/scripts/visitorMgmt/createVisitorPathInstructionDocs.txt +0 -18
  199. package/scripts/visitorMgmt/encryptDateString.ts +0 -71
  200. package/scripts/visitorMgmt/makeHostsManagersOfEachOther.ts +0 -117
  201. package/scripts/whatsapp_gupshup/sendMessage.ts +0 -97
  202. package/src/models/Feed-Details-Screen.model.ts +0 -29
  203. package/src/models/action.model.ts +0 -355
  204. package/src/models/actions/doffing.ts +0 -71
  205. package/src/models/actions/folding.ts +0 -39
  206. package/src/models/attendance.model.ts +0 -615
  207. package/src/models/cicoPost.model.ts +0 -20
  208. package/src/models/company.model.ts +0 -975
  209. package/src/models/contact-us/resquest.model.ts +0 -87
  210. package/src/models/crud/crud.ts +0 -30
  211. package/src/models/customCollection.model.ts +0 -47
  212. package/src/models/customer/customer.model.ts +0 -85
  213. package/src/models/deviceChangeReq.ts +0 -150
  214. package/src/models/dispatch.model.ts +0 -99
  215. package/src/models/feed.models.ts +0 -104
  216. package/src/models/geofence.model.ts +0 -61
  217. package/src/models/leaveApplicationPost.model.ts +0 -79
  218. package/src/models/license.model.ts +0 -215
  219. package/src/models/meeting.model.ts +0 -80
  220. package/src/models/meter.model.ts +0 -62
  221. package/src/models/missingPunchPost.model.ts +0 -84
  222. package/src/models/offline.model.ts +0 -1133
  223. package/src/models/post.model.ts +0 -105
  224. package/src/models/printDetailsScreen.model.ts +0 -30
  225. package/src/models/pushNotifications/pushNotification.model.ts +0 -17
  226. package/src/models/report-actions.model.ts +0 -57
  227. package/src/models/report-definition-details.model.ts +0 -89
  228. package/src/models/report-definition.model.ts +0 -26
  229. package/src/models/report-definitions-summary.model.ts +0 -59
  230. package/src/models/report-detail-data.model.ts +0 -49
  231. package/src/models/report-visibility.model.ts +0 -44
  232. package/src/models/report.model.ts +0 -179
  233. package/src/models/reportGenerator.model.ts +0 -883
  234. package/src/models/response.model.ts +0 -31
  235. package/src/models/steps.factory.model.ts +0 -195
  236. package/src/models/storeGupShupLog.model.ts +0 -49
  237. package/src/models/tasks/sub-task-group.model.ts +0 -173
  238. package/src/models/tasks/tags.model.ts +0 -113
  239. package/src/models/tasks/task-group.model.ts +0 -172
  240. package/src/models/tasks/task.model.ts +0 -681
  241. package/src/models/user.model.ts +0 -319
  242. package/src/models/utility.model.ts +0 -100
  243. package/src/models/visitorManagement/acknowledgement.model.ts +0 -71
  244. package/src/models/visitorManagement/invite.model.ts +0 -406
  245. package/src/models/visitorManagement/newIn.model.ts +0 -82
  246. package/src/models/visitorManagement/selfServe.model.ts +0 -58
  247. package/src/models/worklogPost.model.ts +0 -8
  248. package/src/services/customer.ts +0 -382
  249. package/src/services/meeting.ts +0 -123
  250. package/test/1.ts +0 -13
  251. package/test/db.js +0 -19
  252. package/test/firebaseConfig.js +0 -1
  253. package/tsconfig.json +0 -16
@@ -1,883 +0,0 @@
1
- import * as admin from "firebase-admin";
2
- import { User } from "./user.model";
3
- import { Company } from "./company.model";
4
- import { format, getDay } from "date-fns";
5
- import { Pool } from "mysql2";
6
- import CurdService from "./crud/crud";
7
-
8
- class ReportGenerator {
9
- constructor() { }
10
-
11
- async generateReport(
12
- firestore: admin.firestore.Firestore,
13
- actionDBMap: Record<string, { connection: Pool, tableName: string }>,
14
- nickName: string,
15
- action: string,
16
- timeInterval: any,
17
- phone: string
18
- ) {
19
- if (action === "summary") {
20
- const summaryReport = await this.getSummaryReport(
21
- firestore,
22
- nickName,
23
- timeInterval,
24
- actionDBMap,
25
- action,
26
- phone,
27
- false
28
- );
29
- return summaryReport;
30
- } else if (action === "teamSummary") {
31
- action = "summary";
32
- const teamSummaryReport = await this.getSummaryReport(
33
- firestore,
34
- nickName,
35
- timeInterval,
36
- actionDBMap,
37
- action,
38
- phone,
39
- true
40
- );
41
- return teamSummaryReport;
42
- } else if (action === "attendance") {
43
- const attendanceReport = await this.getAttendanceReport(
44
- firestore,
45
- actionDBMap,
46
- timeInterval,
47
- action,
48
- phone,
49
- nickName,
50
- false
51
- );
52
- return attendanceReport;
53
- } else if (action === "visitorMgmt") {
54
- const visitorMgmtReport = await this.getVisitorMgmtReport(
55
- firestore,
56
- actionDBMap,
57
- timeInterval,
58
- action,
59
- phone,
60
- nickName,
61
- false
62
- );
63
- return visitorMgmtReport;
64
- } else if (action === "teamAttendance") {
65
- action = "attendance";
66
- const attendanceReport = await this.getAttendanceReport(
67
- firestore,
68
- actionDBMap,
69
- timeInterval,
70
- action,
71
- phone,
72
- nickName,
73
- true
74
- );
75
- return attendanceReport;
76
- } else if (action === "visitorMgmtAll") {
77
- action = "visitorMgmt";
78
- const visitorMgmtReport = await this.getVisitorMgmtReport(
79
- firestore,
80
- actionDBMap,
81
- timeInterval,
82
- action,
83
- phone,
84
- nickName,
85
- true
86
- );
87
- return visitorMgmtReport;
88
- } else if (action === "meetings&&attendance") {
89
- const meetingsReport = await this.getTeamDetailsReport(
90
- firestore,
91
- actionDBMap,
92
- timeInterval,
93
- action,
94
- phone,
95
- nickName
96
- );
97
- console.log("hjere");
98
- return meetingsReport;
99
- }
100
- }
101
-
102
- async getPastVisits(
103
- actionDBMap: Record<string, { connection: Pool, tableName: string }>,
104
- companyId: string,
105
- subordinates: string[],
106
- todaysDate: string,
107
- last7Days: string
108
- ) {
109
- const qry = `SELECT COUNT(*) AS count FROM visits WHERE companyId = '${companyId}'
110
- AND checkInTime IS NOT NULL AND checkOutTime IS NOT NULL AND meetingTime IS NOT NULL
111
- AND meetingPersonPhone IN (${String(subordinates)})
112
- AND checkInTime >= '${last7Days} 00:00:00' AND checkInTime <= '${todaysDate} 23:59:59'
113
- ORDER BY checkInTime ASC;`;
114
-
115
- console.log(qry);
116
-
117
- const curdService = new CurdService(actionDBMap['visitorMgmt'].connection)
118
- try {
119
- return await curdService.query(qry)
120
- } catch (error: any) {
121
- return { statusCode: 502, message: error.body.message, details: error };
122
- }
123
- }
124
-
125
- async getFutureVisits(
126
- actionDBMap: Record<string, { connection: Pool, tableName: string }>,
127
- companyId: string,
128
- subordinates: string[],
129
- todaysDate: string,
130
- next7Days: string
131
- ) {
132
- const year = todaysDate.split("-")[0];
133
- const month = todaysDate.split("-")[1];
134
- const days = getDay(new Date(Number(year), Number(month)));
135
- const qry = `SELECT COUNT(*) AS count FROM visits WHERE companyId = '${companyId}'
136
- AND meetingPersonPhone IN (${String(subordinates)})
137
- AND checkInTime IS NULL AND meetingTime IS NULL AND checkOutTime IS NULL
138
- AND scheduledTime >= '${todaysDate} 00:00:00' AND scheduledTime <= '${next7Days} 23:59:59'
139
- ORDER BY checkInTime ASC;`;
140
-
141
- console.log(qry);
142
-
143
- const curdService = new CurdService(actionDBMap["visitorMgmt"].connection)
144
- try {
145
- return await curdService.query(qry);
146
- } catch (error: any) {
147
- return { statusCode: 502, message: error.body.message, details: error };
148
- }
149
- }
150
-
151
- async getCurrentVisits(
152
- actionDBMap: Record<string, { connection: Pool, tableName: string }>,
153
- companyId: string,
154
- subordinates: string[],
155
- todaysDate: string
156
- ) {
157
- const qry = `SELECT COUNT(*) as count FROM visits
158
- WHERE companyId = '${companyId}'
159
- AND meetingPersonPhone IN (${String(subordinates)})
160
- AND checkInTime IS NOT NULL AND checkOutTime IS NULL
161
- AND checkInTime >= '${todaysDate} 00:00:00' AND checkInTime <= '${todaysDate} 23:59:59'
162
- ORDER BY checkInTime ASC;`;
163
-
164
- console.log(qry);
165
- const curdService = new CurdService(actionDBMap['visitorMgmt'].connection)
166
- try {
167
- return await curdService.query(qry);
168
- } catch (error: any) {
169
- return { statusCode: 502, message: error.body.message, details: error };
170
- }
171
- }
172
-
173
- async getTodayVisitsOwner(
174
- actionDBMap: Record<string, { connection: Pool, tableName: string }>,
175
- companyId: string,
176
- subordinates: string[],
177
- todaysDate: string
178
- ) {
179
- const qry = `SELECT COUNT(*) AS count FROM visits
180
- WHERE companyId = '${companyId}'
181
- AND meetingPersonPhone IN (${String(subordinates)})
182
- AND checkInTime IS NOT NULL
183
- AND checkInTime <= '${todaysDate} 23:59:59'
184
- AND checkOutTime IS NOT NULL
185
- AND isApproved = TRUE
186
- AND checkInTime >= '${todaysDate} 00:00:00';`;
187
-
188
- console.log("getTodayVisitsOwner => ", qry);
189
- const curdService = new CurdService(actionDBMap['visitorMgmt'].connection)
190
- try {
191
- return await curdService.query(qry);
192
- } catch (error: any) {
193
- return { statusCode: 502, message: error.body.message, details: error };
194
- }
195
- }
196
-
197
- async getHostsForNotif(
198
- actionDBMap: Record<string, { connection: Pool, tableName: string }>,
199
- companyId: string,
200
- todaysDate: string
201
- ) {
202
- const qry = `SELECT * FROM visits WHERE companyId = '${companyId}'
203
- AND meetingTime IS NULL
204
- AND checkInTime IS NOT NULL
205
- AND isApproved = TRUE
206
- AND checkInTime >= '${todaysDate} 00:00:00'
207
- AND checkInTime <= '${todaysDate} 23:59:59';`;
208
-
209
- console.log("Get Hosts For Notif QRY: => ", qry);
210
- const curdService = new CurdService(actionDBMap['visitorMgmt'].connection)
211
- try {
212
- return await curdService.query(qry);
213
- } catch (error: any) {
214
- return { statusCode: 502, message: error.body.message, details: error };
215
- }
216
- }
217
-
218
- async getTodayVisitsById(actionDBMap: Record<string, { connection: Pool, tableName: string }>, companyId: string, phone: string) {
219
- const qry = `SELECT COUNT(*) as count FROM visits
220
- where checkOutTime IS NULL AND checkInTime IS NOT NULL
221
- AND companyId = '${companyId}'
222
- AND meetingPersonPhone = '${phone}';`;
223
- const curdService = new CurdService(actionDBMap['visitorMgmt'].connection)
224
- try {
225
- return await curdService.query(qry);
226
- } catch (error: any) {
227
- return { statusCode: 502, message: error.body.message, details: error };
228
- }
229
- }
230
-
231
- async latestVisitor(
232
- actionDBMap: Record<string, { connection: Pool, tableName: string }>,
233
- date: string,
234
- phone: string,
235
- companyId: string
236
- ) {
237
- const qry = `SELECT id, visitorName, scheduledTime, checkInTime
238
- FROM visits WHERE companyId = '${companyId}'
239
- AND meetingPersonPhone = '${phone}' AND scheduledTime IS NOT NULL AND meetingTime IS NULL
240
- AND checkOutTime IS NULL AND scheduledTime >= '${date}' ORDER BY scheduledTime ASC;`;
241
- const curdService = new CurdService(actionDBMap['visitorMgmt'].connection)
242
- try {
243
- return await curdService.query(qry);
244
- } catch (error: any) {
245
- return { statusCode: 502, message: error.body.message, details: error };
246
- }
247
- }
248
-
249
- async upcomingVisitorsForOwners(
250
- actionDBMap: Record<string, { connection: Pool, tableName: string }>,
251
- subordinates: string[],
252
- date: string,
253
- next7Days: string,
254
- companyId: string
255
- ) {
256
- const qry = `SELECT id, visitorName, scheduledTime FROM visits
257
- WHERE companyId = '${companyId}' AND meetingPersonPhone
258
- IN (${String(subordinates)}) AND visitType = 'invite'
259
- AND checkInTime IS NULL AND scheduledTime >= '${date} 00:00:00'
260
- AND scheduledTime <= '${next7Days} 23:59:59' ORDER BY scheduledTime ASC;`;
261
-
262
- console.log(qry);
263
- const curdService = new CurdService(actionDBMap['visitorMgmt'].connection)
264
- try {
265
- return await curdService.query(qry);
266
- } catch (error: any) {
267
- return { statusCode: 502, message: error.body.message, details: error };
268
- }
269
- }
270
-
271
- async approveVisitorList(actionDBMap: Record<string, { connection: Pool, tableName: string }>, companyId: string, phone: string) {
272
- // if (phone.charAt(0) != "+") {
273
- // phone = `+${phone}`;
274
- // }
275
- const currentDate = new Date();
276
- const formattedDate = format(currentDate, "yyyy-MM-dd");
277
- console.log('---> ', formattedDate);
278
- const qry = `SELECT visitorName, purposeOfVisit, visitId FROM visits
279
- WHERE checkInTime IS NOT NULL
280
- AND checkInTime >= '${formattedDate} 00:00:00'
281
- AND companyId = '${companyId}'
282
- AND approvedAt IS NULL
283
- AND meetingPersonPhone in (${String(phone)}) AND isApproved = false
284
- ORDER BY checkInTime DESC`;
285
- console.log(qry);
286
- const curdService = new CurdService(actionDBMap['visitorMgmt'].connection)
287
- try {
288
- return await curdService.query(qry);
289
- } catch (error: any) {
290
- return { statusCode: 502, message: error.body.message, details: error };
291
- }
292
- }
293
-
294
- async getVisitorsInTheBuilding(
295
- actionDBMap: Record<string, { connection: Pool, tableName: string }>,
296
- companyId: string,
297
- todaysDate: string
298
- ) {
299
- const qry = `SELECT id, visitorName, meetingPerson, cardColor, checkInTime FROM visits
300
- WHERE cardColor IS NOT NULL AND companyId = '${companyId}'
301
- AND checkInTime >= '${todaysDate} 00:00:00' AND checkInTime IS NOT NULL
302
- ORDER BY checkInTime DESC;`;
303
- console.log(qry);
304
- const curdService = new CurdService(actionDBMap['visitorMgmt'].connection)
305
- try {
306
- return await curdService.query(qry);
307
- } catch (error: any) {
308
- return { statusCode: 502, message: error.body.message, details: error };
309
- }
310
- }
311
-
312
- async upcomingVisits(
313
- actionDBMap: Record<string, { connection: Pool, tableName: string }>,
314
- hour: string,
315
- phone: string,
316
- companyId: string,
317
- date: string
318
- ) {
319
- const qry = `SELECT id, visitorName, scheduledTime FROM visits WHERE companyId = '${companyId}'
320
- AND checkInTime IS NULL AND meetingPersonPhone = '${phone}' AND scheduledTime >= '${date} ${hour}:00:00'
321
- AND visitType = 'invite' LIMIT 10;`;
322
- console.log(qry);
323
- const curdService = new CurdService(actionDBMap['visitorMgmt'].connection)
324
- try {
325
- return await curdService.query(qry);
326
- } catch (error: any) {
327
- return { statusCode: 502, message: error.body.message, details: error };
328
- }
329
- }
330
-
331
- async completedMeetings(actionDBMap: Record<string, { connection: Pool, tableName: string }>, phone: string, companyId: string) {
332
- const qry = `SELECT id, visitorName, scheduledTime FROM visits WHERE companyId = '${companyId}'
333
- AND meetingPersonPhone = '${phone}' AND meetingTime IS NOT NULL ORDER BY meetingTime DESC LIMIT 10;`;
334
- const curdService = new CurdService(actionDBMap['visitorMgmt'].connection)
335
- try {
336
- return await curdService.query(qry);
337
- } catch (error: any) {
338
- return { statusCode: 502, message: error.body.message, details: error };
339
- }
340
- }
341
-
342
- async completedMeetingsForOwner(
343
- actionDBMap: Record<string, { connection: Pool, tableName: string }>,
344
- companyId: string,
345
- subordinates: string[],
346
- todaysDate: string
347
- ) {
348
- const month = todaysDate.split("-")[1];
349
- const qry = `SELECT id, visitorName, scheduledTime FROM visits
350
- WHERE companyId = '${companyId}'
351
- AND meetingPersonPhone IN (${String(subordinates)})
352
- AND meetingTime IS NOT NULL AND meetingTime <= '${todaysDate} 23:59:59'
353
- AND meetingTime >= '2023-${month}-01 00:00:00' ORDER BY meetingTime ASC;`;
354
-
355
- console.log(qry);
356
- const curdService = new CurdService(actionDBMap['visitorMgmt'].connection)
357
- try {
358
- return await curdService.query(qry);
359
- } catch (error: any) {
360
- return { statusCode: 502, message: error.body.message, details: error };
361
- }
362
- }
363
-
364
- async getSummaryReport(
365
- firestore: admin.firestore.Firestore,
366
- nickName: string,
367
- timeInterval: any,
368
- actionDBMap: Record<string, { connection: Pool, tableName: string }>,
369
- action: string,
370
- phone: string,
371
- isTeamSummary: boolean
372
- ) {
373
- const curdService = new CurdService(actionDBMap[action].connection);
374
- try {
375
- const tableName = actionDBMap[action].tableName;
376
- const companyId = await Company.getCompanyIdByNickName(
377
- firestore,
378
- nickName
379
- );
380
- let targetPhones;
381
- if (isTeamSummary) {
382
- const teamList = await Company.getTeamListOfManager(
383
- firestore,
384
- nickName,
385
- phone
386
- );
387
- targetPhones = teamList.map((personObj) => personObj.phone);
388
- } else {
389
- targetPhones = [`+${phone}`];
390
- }
391
- console.log(targetPhones);
392
- const qryStr = `SELECT * FROM ${tableName}
393
- WHERE eventDate <= '${timeInterval.endTime}'
394
- AND eventDate >= '${timeInterval.startTime}'
395
- AND userPhone IN (${targetPhones})
396
- AND companyId = '${companyId}'
397
- ORDER BY createdAt ASC`;
398
- let reportInfo: any = await curdService.query(qryStr);
399
- reportInfo = this.groupReportInfoUserwise(reportInfo, "userPhone");
400
- const phonesArr = Object.keys(reportInfo);
401
- phonesArr.forEach((phone) => {
402
- const userReportObjList = reportInfo[phone];
403
- reportInfo[phone] = this.groupUserInfoDaywise(userReportObjList);
404
- });
405
- let usersReportList = await Promise.all(
406
- phonesArr.map(async (phone) => {
407
- const userId = await User.getUserIdByPhone(firestore, phone);
408
- console.log(userId, companyId);
409
- if (userId) {
410
- const userInfo: any = await User.getUserInfoById(
411
- firestore,
412
- userId,
413
- companyId
414
- );
415
- const name = userInfo.name;
416
- const userReportObj = {
417
- phone: phone,
418
- userName: name,
419
- daywiseInfoObj: reportInfo[phone],
420
- };
421
- return userReportObj;
422
- }
423
- })
424
- );
425
- console.log(usersReportList);
426
- usersReportList = usersReportList.filter((userReport) =>
427
- Boolean(userReport)
428
- );
429
- return usersReportList;
430
- } catch (error: any) {
431
- console.log(error.message);
432
- }
433
- }
434
-
435
- groupReportInfoUserwise(reportInfo: any, groupingKey: string) {
436
- const groupedReportInfo = reportInfo.reduce(
437
- (accumulator: any, currVal: any) => {
438
- if (accumulator[currVal[groupingKey]]) {
439
- accumulator[currVal[groupingKey]].push(currVal);
440
- } else {
441
- accumulator[currVal[groupingKey]] = [currVal];
442
- }
443
- return accumulator;
444
- },
445
- {}
446
- );
447
- return groupedReportInfo;
448
- }
449
-
450
- groupUserInfoDaywise(userReportsObjList: any) {
451
- const daywiseInfoObj = userReportsObjList.reduce(
452
- (accumulator: any, currVal: any) => {
453
- if (accumulator[currVal.eventDetails.date]) {
454
- accumulator[currVal.eventDetails.date].push(currVal.eventDetails);
455
- } else {
456
- accumulator[currVal.eventDetails.date] = [currVal.eventDetails];
457
- }
458
- return accumulator;
459
- },
460
- {}
461
- );
462
- return daywiseInfoObj;
463
- }
464
-
465
- groupVisitsInfoDaywise(userReportObjList: any, timeStringKey: string) {
466
- const daywiseInfoObj = userReportObjList.reduce((acc: any, curr: any) => {
467
- const date = curr[timeStringKey].split(" ")[0];
468
- if (acc[date]) {
469
- acc[date].push(curr);
470
- } else {
471
- acc[date] = [curr];
472
- }
473
- return acc;
474
- }, {});
475
- return daywiseInfoObj;
476
- }
477
-
478
- groupInfoDaywise(userReportObjList: any, timeStringKey: string) {
479
- const daywiseInfoObj = userReportObjList.reduce((acc: any, curr: any) => {
480
- const date = curr[timeStringKey].split(" ")[0];
481
- let eventType = curr.eventType == "checkIn" ? "checkIn" : "checkOut";
482
- let otherEventType = eventType == "checkIn" ? "checkOut" : "checkIn";
483
- let time = curr.time.split(" ");
484
- if (acc[date]) {
485
- acc[date][eventType] = time[1];
486
- } else {
487
- acc[date] = {
488
- [eventType]: time[1],
489
- date: date,
490
- [otherEventType]: "--",
491
- };
492
- }
493
- return acc;
494
- }, {});
495
- return daywiseInfoObj;
496
- }
497
-
498
- groupAndCountMeetingInfo(userReportObjList: any, timeStringKey: string) {
499
- const daywiseInfoObj = userReportObjList.reduce((acc: any, curr: any) => {
500
- console.log(curr[timeStringKey]);
501
- const date = new Date(Number(curr[timeStringKey]))
502
- .toISOString()
503
- .split("T")[0];
504
- if (acc[date]) {
505
- acc[date].count = acc[date].count + 1;
506
- } else {
507
- acc[date] = {
508
- count: 0,
509
- };
510
- acc[date]["count"] = 1;
511
- }
512
- return acc;
513
- }, {});
514
- return daywiseInfoObj;
515
- }
516
-
517
- async getAttendanceReport(
518
- firestore: admin.firestore.Firestore,
519
- actionDBMap: Record<string, { connection: Pool, tableName: string }>,
520
- timeInterval: any,
521
- action: string,
522
- phone: string,
523
- nickName: string,
524
- isTeamAttendance: boolean
525
- ) {
526
- try {
527
- const tableName = actionDBMap[action].tableName;
528
- console.log(tableName);
529
- const companyId = await Company.getCompanyIdByNickName(
530
- firestore,
531
- nickName
532
- );
533
- let targetPhones;
534
- if (isTeamAttendance) {
535
- const teamList = await Company.getTeamListOfManager(
536
- firestore,
537
- nickName,
538
- phone
539
- );
540
- targetPhones = teamList.map((personObj) => personObj.phone);
541
- } else {
542
- targetPhones = [`+${phone}`];
543
- }
544
- console.log("164", targetPhones);
545
- const qryStr = `SELECT * FROM ${tableName}
546
- WHERE time >= '${timeInterval.startTime}'
547
- AND time <= '${timeInterval.endTime}'
548
- AND phoneNo IN (${targetPhones})
549
- AND companyId = '${companyId}'
550
- ORDER BY time`;
551
- const curdService = new CurdService(actionDBMap[action].connection)
552
- let reportInfo: any = await curdService.query(qryStr);
553
- reportInfo = this.groupReportInfoUserwise(reportInfo, "phoneNo");
554
- const phonesArr = Object.keys(reportInfo);
555
- const nameNPhoneInfo = new Map();
556
- phonesArr.forEach((phone) => {
557
- const name = reportInfo[phone][0].employeeName;
558
- nameNPhoneInfo.set(phone, name);
559
- });
560
- phonesArr.forEach((phone) => {
561
- const userReportObjList = reportInfo[phone];
562
- reportInfo[phone] = this.groupVisitsInfoDaywise(
563
- userReportObjList,
564
- "time"
565
- );
566
- });
567
- let usersReportsList = phonesArr.map((phone) => {
568
- return {
569
- phone,
570
- name: nameNPhoneInfo.get(phone),
571
- daywiseInfoObj: reportInfo[phone],
572
- };
573
- });
574
- usersReportsList = usersReportsList.filter((report) => Boolean(report));
575
- console.log(usersReportsList);
576
- return usersReportsList;
577
- } catch (error: any) {
578
- console.log(error.message);
579
- throw new Error(error.message);
580
- }
581
- }
582
-
583
- async getTeamDetailsReport(
584
- firestore: admin.firestore.Firestore,
585
- actionDBMap: Record<string, { connection: Pool, tableName: string }>,
586
- timeInterval: any,
587
- action: any,
588
- phone: string,
589
- nickName: string
590
- ) {
591
- try {
592
- let actionList = action.split("&&");
593
- let meetings = actionList[0];
594
- let attendance = actionList[1];
595
- let userAttendanceReport = await this.getCustomAttendanceReport(
596
- firestore,
597
- actionDBMap,
598
- timeInterval,
599
- attendance,
600
- phone,
601
- nickName
602
- );
603
- let userMeetingsReport = await this.getMeetingsReport(
604
- firestore,
605
- actionDBMap,
606
- timeInterval,
607
- meetings,
608
- phone,
609
- nickName
610
- );
611
- let startTime = timeInterval.startTime.split(" ");
612
- let endTime = timeInterval.endTime.split(" ");
613
-
614
- let dataRange = await this.getDatesInRange(startTime[0], endTime[0]);
615
- let arr = [];
616
- for (let element of userAttendanceReport) {
617
- let obj = {
618
- phone: element.phone,
619
- name: element.name,
620
- daywiseInfoObj: dataRange.map((str: any) => {
621
- return {
622
- [str]: {
623
- checkIn: "--",
624
- date: str,
625
- checkOut: "--",
626
- noOfMeeting: 0,
627
- },
628
- };
629
- }),
630
- };
631
- arr.push(obj);
632
- }
633
- let mergedData: any = [];
634
-
635
- for (const person of userAttendanceReport) {
636
- const { phone, name, daywiseInfoObj } = person;
637
- console.log(name, "./././././");
638
- let idx = userMeetingsReport.findIndex((obj) => {
639
- // console.log(obj.name, "118525255", name , typeof name, typeof obj.name)
640
- return obj.name == name;
641
- });
642
- console.log(idx);
643
- let obj = {
644
- phone,
645
- name,
646
- daywiseInfoObj,
647
- };
648
- for (let day in daywiseInfoObj) {
649
- if (!!userMeetingsReport[idx])
650
- console.log(
651
- userMeetingsReport[idx],
652
- userMeetingsReport[idx]["daywiseInfoObj"],
653
- userMeetingsReport[idx]["daywiseInfoObj"][day],
654
- day
655
- );
656
- // console.log(userMeetingsReport[idx]["daywiseInfoObj"][day]["count"])
657
- obj.daywiseInfoObj[day] = {
658
- checkIn: daywiseInfoObj[day].checkIn,
659
- checkOut: daywiseInfoObj[day].checkOut,
660
- date: daywiseInfoObj[day].date,
661
- noOfMeetings: userMeetingsReport[idx]
662
- ? userMeetingsReport[idx]["daywiseInfoObj"][day]
663
- ? userMeetingsReport[idx]["daywiseInfoObj"][day]["count"]
664
- : 0
665
- : "",
666
- };
667
- }
668
- mergedData.push(obj);
669
- }
670
- return mergedData;
671
- } catch (error: any) {
672
- console.log(error.message);
673
- throw new Error(error.message);
674
- }
675
- }
676
-
677
- async getDatesInRange(startDate: any, endDate: any) {
678
- const dates: any = [];
679
- const currentDate = new Date(startDate);
680
- const endDateLimit = new Date(endDate);
681
- while (currentDate <= endDateLimit) {
682
- const date = new Date(currentDate).toLocaleString("en-US", {
683
- year: "numeric",
684
- month: "2-digit",
685
- day: "2-digit",
686
- });
687
- dates.push(date);
688
- currentDate.setDate(currentDate.getDate() + 1);
689
- }
690
- return dates;
691
- }
692
-
693
- async getCustomAttendanceReport(
694
- firestore: admin.firestore.Firestore,
695
- actionDBMap: Record<string, { connection: Pool, tableName: string }>,
696
- timeInterval: any,
697
- action: any,
698
- phone: string,
699
- nickName: string
700
- ) {
701
- try {
702
- const tableName = actionDBMap[action].tableName;
703
- const companyId = await Company.getCompanyIdByNickName(
704
- firestore,
705
- nickName
706
- );
707
- const teamList = await Company.getTeamListOfManager(
708
- firestore,
709
- nickName,
710
- phone
711
- );
712
- let targetPhones = teamList.map((personObj) => personObj.phone);
713
- const qryStr = `SELECT * FROM ${tableName}
714
- WHERE time >= '${timeInterval.startTime}'
715
- AND time <= '${timeInterval.endTime}'
716
- AND phoneNo IN (${targetPhones})
717
- AND companyId = '${companyId}'
718
- ORDER BY time`;
719
- console.log(actionDBMap[action]);
720
- const curdService = new CurdService(actionDBMap[action].connection)
721
- let reportInfo: any = await curdService.query(qryStr);
722
- console.log(reportInfo);
723
- reportInfo = this.groupReportInfoUserwise(reportInfo, "phoneNo");
724
- // console.log(reportInfo)
725
- const phonesArr = Object.keys(reportInfo);
726
- const nameNPhoneInfo = new Map();
727
- phonesArr.forEach((phone) => {
728
- const name = reportInfo[phone][0].employeeName;
729
- nameNPhoneInfo.set(phone, name);
730
- });
731
- phonesArr.forEach((phone) => {
732
- const userReportObjList = reportInfo[phone];
733
- reportInfo[phone] = this.groupInfoDaywise(userReportObjList, "time");
734
- });
735
- let usersReportsList = phonesArr.map((phone) => {
736
- return {
737
- phone,
738
- name: nameNPhoneInfo.get(phone),
739
- daywiseInfoObj: reportInfo[phone],
740
- };
741
- });
742
- usersReportsList = usersReportsList.filter((report) => Boolean(report));
743
- console.log(usersReportsList[0]);
744
- return usersReportsList;
745
- } catch (error: any) {
746
- console.log(error.message);
747
- throw new Error(error.message);
748
- }
749
- }
750
-
751
- async getMeetingsReport(
752
- firestore: admin.firestore.Firestore,
753
- actionDBMap: Record<string, { connection: Pool, tableName: string }>,
754
- timeInterval: any,
755
- action: any,
756
- phone: string,
757
- nickName: string
758
- ) {
759
- try {
760
- console.log(timeInterval, "time");
761
- const tableName = actionDBMap[action].tableName;
762
- const companyId = await Company.getCompanyIdByNickName(
763
- firestore,
764
- nickName
765
- );
766
- let startTime = new Date(timeInterval.startTime).getTime() / 1000;
767
- let endTime = new Date(timeInterval.endTime).getTime() / 1000;
768
- const teamList = await Company.getTeamListOfManager(
769
- firestore,
770
- nickName,
771
- phone
772
- );
773
- let targetPhones = teamList.map((personObj) => personObj.phone);
774
- const qryStr = `SELECT * FROM ${tableName}
775
- WHERE meetingDate >= '${startTime}'
776
- AND meetingDate <= '${endTime}'
777
- AND phone IN (${targetPhones})
778
- AND companyId = '${companyId}'
779
- ORDER BY meetingDate`;
780
- console.log(actionDBMap[action]);
781
- const curdService = new CurdService(actionDBMap[action].connection)
782
- let reportInfo: any = await curdService.query(qryStr);
783
- console.log(reportInfo);
784
- reportInfo = this.groupReportInfoUserwise(reportInfo, "phone");
785
- // console.log(reportInfo)
786
- const phonesArr = Object.keys(reportInfo);
787
- const nameNPhoneInfo = new Map();
788
- phonesArr.forEach((phone) => {
789
- const name = reportInfo[phone][0].name;
790
- nameNPhoneInfo.set(phone, name);
791
- });
792
- phonesArr.forEach((phone) => {
793
- const userReportObjList = reportInfo[phone];
794
- reportInfo[phone] = this.groupAndCountMeetingInfo(
795
- userReportObjList,
796
- "meetingDate"
797
- );
798
- });
799
- let usersReportsList = phonesArr.map((phone) => {
800
- return {
801
- phone,
802
- name: nameNPhoneInfo.get(phone),
803
- daywiseInfoObj: reportInfo[phone],
804
- };
805
- });
806
- usersReportsList = usersReportsList.filter((report) => Boolean(report));
807
- console.log(usersReportsList[0]);
808
- return usersReportsList;
809
- } catch (error: any) {
810
- console.log(error.message);
811
- throw new Error(error.message);
812
- }
813
- }
814
-
815
- async getVisitorMgmtReport(
816
- firestore: admin.firestore.Firestore,
817
- actionDBMap: Record<string, { connection: Pool, tableName: string }>,
818
- timeInterval: any,
819
- action: string,
820
- phone: string,
821
- nickName: string,
822
- isAllVisits: boolean
823
- ) {
824
- try {
825
- const tableName = actionDBMap[action].tableName;
826
- const companyId = await Company.getCompanyIdByNickName(
827
- firestore,
828
- nickName
829
- );
830
- let targetPhones;
831
- if (isAllVisits) {
832
- const teamList = await Company.getTeamListOfManager(
833
- firestore,
834
- nickName,
835
- phone
836
- );
837
- targetPhones = teamList.map((personObj) => personObj.phone);
838
- } else {
839
- targetPhones = [`+${phone}`];
840
- }
841
- targetPhones.push(`+${phone}`);
842
- const qryStr = `SELECT * FROM ${tableName}
843
- WHERE scheduledTime >= '${timeInterval.startTime}'
844
- AND scheduledTime <= '${timeInterval.endTime}'
845
- AND meetingPersonPhone IN (${targetPhones})
846
- AND companyId = '${companyId}'
847
- ORDER BY scheduledTime`;
848
- const curdService = new CurdService(actionDBMap[action].connection)
849
- let reportInfo: any = await curdService.query(qryStr);
850
- reportInfo = this.groupReportInfoUserwise(
851
- reportInfo,
852
- "meetingPersonPhone"
853
- );
854
- const phonesArr = Object.keys(reportInfo);
855
- const nameNPhoneInfo = new Map();
856
- phonesArr.forEach((phone) => {
857
- const name = reportInfo[phone][0].meetingPerson;
858
- nameNPhoneInfo.set(phone, name);
859
- });
860
- phonesArr.forEach((phone) => {
861
- const userReportObjList = reportInfo[phone];
862
- reportInfo[phone] = this.groupVisitsInfoDaywise(
863
- userReportObjList,
864
- "scheduledTime"
865
- );
866
- });
867
- let usersReportsList = phonesArr.map((phone) => {
868
- return {
869
- phone,
870
- name: nameNPhoneInfo.get(phone),
871
- daywiseInfoObj: reportInfo[phone],
872
- };
873
- });
874
- usersReportsList = usersReportsList.filter((report) => Boolean(report));
875
- console.log(usersReportsList);
876
- return usersReportsList;
877
- } catch (error: any) {
878
- console.log(error.message);
879
- }
880
- }
881
- }
882
-
883
- export { ReportGenerator };