mobioffice-cli 0.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 (156) hide show
  1. package/.prettierrc +4 -0
  2. package/README.md +1 -0
  3. package/a.js +3 -0
  4. package/lib/index.js +87 -0
  5. package/package.json +50 -0
  6. package/scripts/1.ts +1300 -0
  7. package/scripts/GCloudPubSub/pub-sub-config.json +12 -0
  8. package/scripts/GCloudPubSub/visitorAutoRejection.ts +86 -0
  9. package/scripts/actions/assignUsersFromOneActionToOther.ts +64 -0
  10. package/scripts/actions/assignUsersListToAction.ts +81 -0
  11. package/scripts/actions/getActionsListOfUser.ts +42 -0
  12. package/scripts/actions/getCompanyUserDetails.ts +49 -0
  13. package/scripts/actions/giveActionToUser.ts +41 -0
  14. package/scripts/actions/giveUsersToActivitySelector.ts +56 -0
  15. package/scripts/actions/groupActionsInActivitySelector.ts +101 -0
  16. package/scripts/actions/modifySummaryReportDB.ts +42 -0
  17. package/scripts/actions/setUrlToActionStep.ts +18 -0
  18. package/scripts/actions/syncMySqlAttendanceDBWithFirebase.ts +93 -0
  19. package/scripts/actions/syncMySqlMeetingsDBWithFirebase.ts +103 -0
  20. package/scripts/actions/test.ts +29 -0
  21. package/scripts/actions/transferFeedsOldIdToNew.ts +40 -0
  22. package/scripts/actions/transformUserIntoManager.ts +89 -0
  23. package/scripts/argvConfig.js +9 -0
  24. package/scripts/backUpData/testCode.ts +131 -0
  25. package/scripts/benaraScripts/addWorkAreaMap.ts +46 -0
  26. package/scripts/benaraScripts/add_customers.ts +26 -0
  27. package/scripts/benaraScripts/add_customers_contact.ts +27 -0
  28. package/scripts/benaraScripts/add_empty_work_area.ts +17 -0
  29. package/scripts/benaraScripts/assignManagers.ts +35 -0
  30. package/scripts/benaraScripts/changeCheckInFlag.ts +45 -0
  31. package/scripts/benaraScripts/createCustomerContactsList.ts +170 -0
  32. package/scripts/benaraScripts/createUserByDeletingOldUser.ts +70 -0
  33. package/scripts/benaraScripts/createUsersAreaMapCollection.ts +23 -0
  34. package/scripts/benaraScripts/createWorkAreaMap.ts +24 -0
  35. package/scripts/benaraScripts/mapWorkAreasToUsers.ts +112 -0
  36. package/scripts/companies_data.json +2496 -0
  37. package/scripts/create_or_update_users.ts +31 -0
  38. package/scripts/csvToJson/csvToJson.ts +90 -0
  39. package/scripts/csvToJson/users.json +3896 -0
  40. package/scripts/db.js +27 -0
  41. package/scripts/db.json +13 -0
  42. package/scripts/dbMySql.ts +63 -0
  43. package/scripts/delete_action_steps.ts +11 -0
  44. package/scripts/delete_user.ts +71 -0
  45. package/scripts/dev_companies_data.json +613 -0
  46. package/scripts/enroll.xlsx +0 -0
  47. package/scripts/export_users.ts +72 -0
  48. package/scripts/files/visitorManagementFiles/displayScreen.json +70 -0
  49. package/scripts/files/visitorManagementFiles/init_report_visibility.ts +79 -0
  50. package/scripts/firebaseConfig.js +12 -0
  51. package/scripts/firebaseDocs/deleteIncommingCollection.ts +47 -0
  52. package/scripts/firebaseDocs/updateDoc.ts +43 -0
  53. package/scripts/getActionDataIntoJSON/getActionData.ts +68 -0
  54. package/scripts/get_attendance_by_any_date.ts +14 -0
  55. package/scripts/get_attendance_by_month.ts +12 -0
  56. package/scripts/get_attendance_monthly_by_team.ts +11 -0
  57. package/scripts/get_daily_report.ts +10 -0
  58. package/scripts/get_mangers.ts +13 -0
  59. package/scripts/grant_user_license.ts +18 -0
  60. package/scripts/init_CustomCollection.ts +16 -0
  61. package/scripts/init_action_steps.ts +28 -0
  62. package/scripts/init_actions.ts +31 -0
  63. package/scripts/init_company.ts +18 -0
  64. package/scripts/init_customer_mysql.ts +12 -0
  65. package/scripts/init_feed.ts +4 -0
  66. package/scripts/init_feed_details_screen.ts +14 -0
  67. package/scripts/init_geofence.ts +26 -0
  68. package/scripts/init_print_details_screen.ts +14 -0
  69. package/scripts/init_report_actions.ts +24 -0
  70. package/scripts/init_report_definition_detail.ts +26 -0
  71. package/scripts/init_report_definition_summary.ts +16 -0
  72. package/scripts/init_report_visibility.ts +46 -0
  73. package/scripts/init_user_customcollection.ts +16 -0
  74. package/scripts/json/action.json +21 -0
  75. package/scripts/json/company.json +24 -0
  76. package/scripts/json/report-action.json +13 -0
  77. package/scripts/json/report-def-deet.json +43 -0
  78. package/scripts/json/resp.json +784 -0
  79. package/scripts/json/steps.json +24 -0
  80. package/scripts/json/test.ts +49 -0
  81. package/scripts/mysqlConfig.ts +9 -0
  82. package/scripts/revoke_or_extend_license.ts +14 -0
  83. package/scripts/stream.js +4 -0
  84. package/scripts/testing1.ts +35 -0
  85. package/scripts/update/doc.json +20 -0
  86. package/scripts/update/getDocByPath.ts +34 -0
  87. package/scripts/update/updateDocByPath.ts +47 -0
  88. package/scripts/update/updateUsersOfCompanies.ts +58 -0
  89. package/scripts/update_actions.ts +19 -0
  90. package/scripts/update_actions_steps.ts +19 -0
  91. package/scripts/update_company.ts +19 -0
  92. package/scripts/update_geofence.ts +20 -0
  93. package/scripts/update_managers.ts +16 -0
  94. package/scripts/visitorMgmt/createArea.ts +68 -0
  95. package/scripts/visitorMgmt/createArea.txt +3 -0
  96. package/scripts/visitorMgmt/createVisitorPathInstructionDocs.ts +130 -0
  97. package/scripts/visitorMgmt/createVisitorPathInstructionDocs.txt +18 -0
  98. package/scripts/visitorMgmt/encryptDateString.ts +71 -0
  99. package/scripts/visitorMgmt/makeHostsManagersOfEachOther.ts +117 -0
  100. package/scripts/whatsapp_gupshup/sendMessage.ts +97 -0
  101. package/src/index.ts +87 -0
  102. package/src/models/Feed-Details-Screen.model.ts +29 -0
  103. package/src/models/action.model.ts +355 -0
  104. package/src/models/actions/doffing.ts +71 -0
  105. package/src/models/actions/folding.ts +39 -0
  106. package/src/models/attendance.model.ts +615 -0
  107. package/src/models/cicoPost.model.ts +20 -0
  108. package/src/models/company.model.ts +975 -0
  109. package/src/models/contact-us/resquest.model.ts +87 -0
  110. package/src/models/crud/crud.ts +30 -0
  111. package/src/models/customCollection.model.ts +47 -0
  112. package/src/models/customer/customer.model.ts +85 -0
  113. package/src/models/deviceChangeReq.ts +150 -0
  114. package/src/models/dispatch.model.ts +99 -0
  115. package/src/models/feed.models.ts +104 -0
  116. package/src/models/geofence.model.ts +61 -0
  117. package/src/models/leaveApplicationPost.model.ts +79 -0
  118. package/src/models/license.model.ts +215 -0
  119. package/src/models/log.model.ts +25 -0
  120. package/src/models/meeting.model.ts +80 -0
  121. package/src/models/meter.model.ts +62 -0
  122. package/src/models/missingPunchPost.model.ts +84 -0
  123. package/src/models/offline.model.ts +1133 -0
  124. package/src/models/post.model.ts +105 -0
  125. package/src/models/printDetailsScreen.model.ts +30 -0
  126. package/src/models/pushNotifications/pushNotification.model.ts +17 -0
  127. package/src/models/report-actions.model.ts +57 -0
  128. package/src/models/report-definition-details.model.ts +89 -0
  129. package/src/models/report-definition.model.ts +26 -0
  130. package/src/models/report-definitions-summary.model.ts +59 -0
  131. package/src/models/report-detail-data.model.ts +49 -0
  132. package/src/models/report-visibility.model.ts +44 -0
  133. package/src/models/report.model.ts +179 -0
  134. package/src/models/reportGenerator.model.ts +883 -0
  135. package/src/models/response.model.ts +31 -0
  136. package/src/models/steps.factory.model.ts +195 -0
  137. package/src/models/storeGupShupLog.model.ts +49 -0
  138. package/src/models/summary.model.ts +63 -0
  139. package/src/models/tasks/sub-task-group.model.ts +173 -0
  140. package/src/models/tasks/tags.model.ts +113 -0
  141. package/src/models/tasks/task-group.model.ts +172 -0
  142. package/src/models/tasks/task.model.ts +681 -0
  143. package/src/models/tempCollection.model.ts +398 -0
  144. package/src/models/user.model.ts +319 -0
  145. package/src/models/utility.model.ts +100 -0
  146. package/src/models/visitorManagement/acknowledgement.model.ts +71 -0
  147. package/src/models/visitorManagement/invite.model.ts +406 -0
  148. package/src/models/visitorManagement/newIn.model.ts +82 -0
  149. package/src/models/visitorManagement/selfServe.model.ts +58 -0
  150. package/src/models/worklogPost.model.ts +8 -0
  151. package/src/services/customer.ts +382 -0
  152. package/src/services/meeting.ts +123 -0
  153. package/test/1.ts +13 -0
  154. package/test/db.js +19 -0
  155. package/test/firebaseConfig.js +1 -0
  156. package/tsconfig.json +16 -0
@@ -0,0 +1,105 @@
1
+ import { Offline } from "./offline.model";
2
+ import * as admin from "firebase-admin";
3
+ import { Dispatch } from "./dispatch.model";
4
+ import { Company } from "./company.model";
5
+ import { User } from "./user.model";
6
+ import { Action } from "./action.model";
7
+ class Post {
8
+ actionEvent: string = "";
9
+ actionId : string = "";
10
+ actionName: string = "";
11
+ actionType: string = "";
12
+ companyId: string = "";
13
+ createdAt: string = "";
14
+ refId: string = "";
15
+ description: string = "";
16
+ eventId : string = "";
17
+ isGeofence: boolean = false;
18
+ userId: string = "";
19
+ id: string = "";
20
+ forApproval: boolean = false;
21
+ forApprovalText: string = "";
22
+ object: any = null;
23
+ origin: any = null;
24
+ seen: boolean = false;
25
+ startAt: string = "";
26
+ startLat: string = "";
27
+ startLong: string = "";
28
+ endAt: string = "";
29
+ endLat: string = "";
30
+ endLong: string = "";
31
+ stepValues: any[] = [];
32
+ target: string = "";
33
+ time: string = "";
34
+ extraData: any = {};
35
+ checkInternet: boolean = false;
36
+ image: string = "";
37
+ eventDetails: string = "";
38
+ isProcessed: boolean = false;
39
+ missedEvent: string = "";
40
+
41
+ static async createNewPost(firestore:admin.firestore.Firestore,postInfo: any){
42
+ let incomingDocId = postInfo.id
43
+ try{
44
+ let userRef = await Offline.createRefForUser(firestore, postInfo.companyId, postInfo.userId);
45
+ postInfo.id = userRef.id;
46
+ const postToSave = JSON.parse(JSON.stringify(postInfo));
47
+ console.log("------before saving in company")
48
+ let postEventId = await Offline.addDetailsToCompanyActions(firestore,
49
+ postInfo.companyId,
50
+ postInfo.actionId,
51
+ postToSave,
52
+ postInfo.actionName);
53
+ postToSave.eventId = postEventId;
54
+ await userRef.set(postToSave);
55
+ console.log("post sent to user feed");
56
+ await Offline.sendFeedToManagers(firestore,
57
+ postInfo.companyId,
58
+ postInfo.userId,
59
+ postToSave);
60
+ console.log("post sent to managers' feed",postToSave.startAt)
61
+ await Offline.deleteInfoFromIncoming(firestore, incomingDocId);
62
+ console.log("document deleted from incoming");
63
+ return postEventId
64
+ }
65
+ catch(error){
66
+ await firestore.collection("Incoming").doc(incomingDocId).update({
67
+ message: "Error",
68
+ errorDetail: error,
69
+ errorId: "err101",
70
+ })
71
+ console.log(error)
72
+ return error
73
+ }
74
+ }
75
+
76
+ static async sendDCRPost(firestore: admin.firestore.Firestore,
77
+ postToSave: any) {
78
+ const nickName = "mobiOffice";
79
+ const companyId = await Company.getCompanyIdByNickName(firestore, nickName);
80
+ const actionId = await Action.getActionId(firestore, companyId, postToSave.actionName)
81
+ const supportUsers = await Company.getUsersListbyCompany(firestore, nickName);
82
+ console.log(actionId, companyId);
83
+ const postEventDocRef = firestore.collection("Companies")
84
+ .doc(companyId)
85
+ .collection("Actions")
86
+ .doc(actionId)
87
+ .collection(postToSave.actionName)
88
+ .doc(postToSave.id)
89
+ postToSave.eventId = postToSave.id;
90
+ await postEventDocRef.set(postToSave)
91
+ const feedIdObj: any = {}
92
+ for (let user of supportUsers) {
93
+ let userRef = firestore.collection("Feeds")
94
+ .doc(user.id)
95
+ .collection(companyId)
96
+ .doc(postToSave.id)
97
+ // postToSave.id = userRef.id;
98
+ await userRef.set(postToSave);
99
+ // feedIdObj[user.id] = userRef.id;
100
+ }
101
+ // return feedIdObj;
102
+ }
103
+ }
104
+
105
+ export { Post };
@@ -0,0 +1,30 @@
1
+ import * as admin from 'firebase-admin';
2
+ import { Company } from './company.model';
3
+
4
+ class PrintDetailsScreen {
5
+
6
+ static async createPrintDetailsScreen(firestore:admin.firestore.Firestore,nickName:string,data:any){
7
+ let companyId = await Company.getCompanyIdbyNickname(firestore,nickName);
8
+ let snapshot = firestore
9
+ .collection("Companies")
10
+ .doc(companyId)
11
+ .collection("Print-Details-Screen").doc()
12
+ data.id = snapshot.id
13
+ await snapshot.set(data)
14
+ return data
15
+ }
16
+
17
+
18
+ static async updatePrintDetailsScreen(firestore:admin.firestore.Firestore,nickName:string,data:any){
19
+ let companyId = await Company.getCompanyIdbyNickname(firestore,nickName);
20
+ let snapshot = await firestore
21
+ .collection("Companies")
22
+ .doc(companyId)
23
+ .collection("Print-Details-Screen").where("actionName","==",data.actionName).get()
24
+ snapshot.forEach((doc)=>{
25
+ doc.ref.update(data)
26
+ })
27
+ }
28
+
29
+ }
30
+ export { PrintDetailsScreen };
@@ -0,0 +1,17 @@
1
+ import { firestore } from "firebase-admin";
2
+
3
+ class PushNotifications {
4
+ static async sendPushNotification(admin: any,
5
+ fcmTokens: string[], message: any) {
6
+ try {
7
+ const response = await admin.messaging().sendToDevice(fcmTokens, message);
8
+ console.log(response.results);
9
+ // console.log(response[0].error)
10
+ return "Notification Sent Successfully"
11
+ } catch (error: any) {
12
+ throw new Error(error.message)
13
+ }
14
+ }
15
+ }
16
+
17
+ export { PushNotifications };
@@ -0,0 +1,57 @@
1
+ import * as admin from 'firebase-admin';
2
+ import { Action } from './action.model';
3
+ import { Company } from './company.model';
4
+ class ReportActions {
5
+ darkColor: string = "";
6
+ lightColor: string = "";
7
+ description: string = "";
8
+ icon: string = "";
9
+ title: string = "";
10
+ url: string = "";
11
+ id:string = "";
12
+ order: string = "";
13
+ keys: string = "";
14
+
15
+ static async getOrCreateReportActions(firestore:admin.firestore.Firestore,nickName:string,reportAction:any){
16
+ if(!reportAction.title){
17
+ return "Please provide title"
18
+ }
19
+ let companyId = await Company.getCompanyIdbyNickname(firestore,nickName)
20
+ let snapshot = firestore.collection('Companies').doc(companyId).collection('Report-Actions')
21
+ let reportAction_data = await snapshot.where('title','==',reportAction.title).get()
22
+ if(reportAction_data.empty){
23
+ let actionId = await Action.getActionIdByDisplayName(firestore,companyId,reportAction.title);
24
+ //reportAction = await ReportActions.convertReportActionsDataType(reportAction)
25
+ reportAction.id = actionId
26
+ let reportaction_snapshot_newData = snapshot.doc(actionId)
27
+ await reportaction_snapshot_newData.set(reportAction)
28
+ return (await reportaction_snapshot_newData.get()).data()
29
+ }else{
30
+ return reportAction_data.docs[0].data()
31
+ }
32
+ }
33
+
34
+ static async convertReportActionsDataType(data:any){
35
+ if(data.keys){
36
+ data.keys = data.keys.split('&')
37
+ }
38
+ if(data.order){
39
+ data.order = Number(data.order)
40
+ }
41
+ return data
42
+ }
43
+
44
+ static reportActionsTemplate = {
45
+ darkColor: null,
46
+ lightColor: null,
47
+ description: null,
48
+ icon: null,
49
+ title: null,
50
+ url: null,
51
+ id: null,
52
+ order: null,
53
+ keys: null,
54
+ };
55
+ }
56
+
57
+ export { ReportActions };
@@ -0,0 +1,89 @@
1
+ import * as admin from 'firebase-admin';
2
+ import { Action } from './action.model';
3
+ import { Company } from './company.model';
4
+ import { ReportDefinitionSummary } from './report-definitions-summary.model';
5
+
6
+
7
+ class ReportDefinitionDetail {
8
+ color:string = "";
9
+ data:any[] = [];
10
+ detailOf:string = "";
11
+ name:string = "";
12
+ toHome:boolean = false;
13
+ id:string = ""
14
+ nickname?:string = ""
15
+
16
+
17
+ static async getOrCreateReportDefinitionDetail(firestore:admin.firestore.Firestore,nickName:string,reportDefinitionDetail:ReportDefinitionDetail){
18
+ let companyId = await Company.getCompanyIdbyNickname(firestore,nickName);
19
+ let snapshot = firestore
20
+ .collection("Companies")
21
+ .doc(companyId)
22
+ .collection("Report-Definition-Detail")
23
+ let reportDefinitionDetials_snapshot = await snapshot.where('name','==',reportDefinitionDetail.name).get()
24
+ if(reportDefinitionDetials_snapshot.empty){
25
+ //reportDefinitionDetail = await ReportDefinitionDetail.convertReportDefinitionDetail(reportDefinitionDetail)
26
+ let docRef = snapshot.doc()
27
+ let id = await ReportDefinitionSummary.getReportDefinitionSummaryId(firestore,nickName,reportDefinitionDetail.name)
28
+ if(!id.length){
29
+ id = await Action.getActionIdByDisplayName(firestore,companyId,reportDefinitionDetail.name)
30
+ }
31
+ reportDefinitionDetail.detailOf = id
32
+ reportDefinitionDetail.id = docRef.id
33
+ await docRef.set(reportDefinitionDetail);
34
+ return (await docRef.get()).data()
35
+ }else{
36
+ return reportDefinitionDetials_snapshot.docs[0].data()
37
+ }
38
+ }
39
+
40
+ static async convertReportDefinitionDetail(data:any){
41
+ if(data.toHome){
42
+ data.toHome = await Action.booleanConvertion(data.toHome.toLowerCase());
43
+ }
44
+ if(data.share){
45
+ data.share = await Action.booleanConvertion(data.share.toLowerCase());
46
+ }
47
+ if(data.keys){
48
+ data.keys = await data.keys.split("&")
49
+ }
50
+ if(data.data){
51
+ for(let subData of data.data){
52
+ if(subData.autoAPICalled){
53
+ subData.autoAPICalled = await Action.booleanConvertion(subData.autoAPICalled);
54
+ }
55
+ if(subData.isSSL){
56
+ subData.isSSL = await Action.booleanConvertion(subData.isSSL);
57
+ }
58
+ if(subData.halfPage){
59
+ subData.halfPage = await Action.booleanConvertion(subData.halfPage);
60
+ }
61
+ if(subData.fullPage){
62
+ subData.fullPage = await Action.booleanConvertion(subData.fullPage);
63
+ }
64
+ if(subData.keys){
65
+ subData.keys = subData.keys.split('&')
66
+ }
67
+ if(subData.nextPage){
68
+ subData.nextPage = Number(subData.nextPage)
69
+ }
70
+ if(subData.pageSize){
71
+ subData.pageSize = Number(subData.pageSize)
72
+ }
73
+ if(subData.rowHeight){
74
+ subData.rowHeight = Number(subData.rowHeight)
75
+ }
76
+ if(subData.order){
77
+ subData.order = Number(subData.order)
78
+ }
79
+ if(subData.totalItems){
80
+ subData.totalItems = Number(subData.totalItems)
81
+ }
82
+ }
83
+ }
84
+
85
+ return data
86
+ }
87
+ }
88
+
89
+ export { ReportDefinitionDetail }
@@ -0,0 +1,26 @@
1
+ class ReportDefinition {
2
+
3
+ id:string = "";
4
+ name:string = "";
5
+ detailOf: string = "";
6
+ toHome: boolean = true;
7
+ share:boolean = false;
8
+ keys:[] = [];
9
+ color:string = "";
10
+ downloadUrl:string = "";
11
+ data:[] = [];
12
+
13
+ static reportDefTemplate = {
14
+ id: "",
15
+ name: "",
16
+ detailOf: "",
17
+ toHome: true,
18
+ share: false,
19
+ keys: [],
20
+ color: "",
21
+ downloadUrl: "",
22
+ data: [],
23
+ };
24
+ }
25
+
26
+ export { ReportDefinition };
@@ -0,0 +1,59 @@
1
+ import * as admin from 'firebase-admin';
2
+ import { Action } from './action.model';
3
+ import { Company } from './company.model';
4
+ class ReportDefinitionSummary {
5
+ static async getOrCreateReportDefinitionSummary(firestore:admin.firestore.Firestore,nickName:string,reportSummary:any){
6
+ let companyId = await Company.getCompanyIdbyNickname(firestore,nickName)
7
+ let snapshot = await firestore
8
+ .collection("Companies")
9
+ .doc(companyId)
10
+ .collection("Report-Definition-Summary");
11
+ let ReportDefinitionSummary_data = await snapshot.where("name", "==", reportSummary.name).get();
12
+ if(ReportDefinitionSummary_data.empty){
13
+ reportSummary = await ReportDefinitionSummary.convertReportDefinitionSummary(reportSummary)
14
+ let docRef = snapshot.doc()
15
+ reportSummary.id = docRef.id
16
+ await docRef.set(reportSummary);
17
+ return (await docRef.get()).data()
18
+ }else{
19
+ return ReportDefinitionSummary_data.docs[0].data()
20
+ }
21
+ }
22
+
23
+ static async convertReportDefinitionSummary(data:any){
24
+ if(data.autoAPICall){
25
+ data.autoAPICall = await Action.booleanConvertion(data.autoAPICall.toLowerCase())
26
+ }
27
+ return data
28
+ }
29
+
30
+ static async getReportDefinitionSummaryId(firestore:admin.firestore.Firestore,nickName:string,reportDefinitionSummaryName:string){
31
+ let companyId = await Company.getCompanyIdbyNickname(firestore,nickName)
32
+ let docRef = await firestore
33
+ .collection("Companies")
34
+ .doc(companyId)
35
+ .collection("Report-Definition-Summary")
36
+ .where('name','==',reportDefinitionSummaryName)
37
+ .get()
38
+ let id = ""
39
+ docRef.forEach((doc)=>{
40
+ id = doc.data().id
41
+ })
42
+ return id
43
+ }
44
+
45
+ static async getReportDefinitionSummaryDocById(firestore:admin.firestore.Firestore,companyId:string,docId:string){
46
+ try{
47
+ let snapshot = await firestore.collection("Companies")
48
+ .doc(companyId)
49
+ .collection("Report-Definition-Summary")
50
+ .doc(docId)
51
+ .get()
52
+ return snapshot.data()
53
+ }
54
+ catch(error:any){
55
+ throw new Error(error.message)
56
+ }
57
+ }
58
+ }
59
+ export { ReportDefinitionSummary };
@@ -0,0 +1,49 @@
1
+ class ReportDetailData {
2
+ id:string = "";
3
+ url:string ="";
4
+ reportType:string = "";
5
+ halfPage:boolean = true;
6
+ fullPage:boolean = false ;
7
+ pageSize:number = 10;
8
+ nextPage:number = 1;
9
+ totalItems:number = 30;
10
+ data: []= [];
11
+ autoAPICalled:boolean = false;
12
+ showPrint:boolean = false;
13
+ showBarcode:boolean = false;
14
+ isSSL :boolean = true;
15
+ saveInPublicStorage:boolean = true;
16
+ keys:[] = [];
17
+ order:number = 0;
18
+ type:string = "";
19
+
20
+ static reportDataType = {
21
+ TILE: "tile",
22
+ TABLE: "table",
23
+ PDF: "pdf",
24
+ TEXT: "text",
25
+ };
26
+
27
+ static reportDetailDataTemplate = {
28
+ id: "",
29
+ url: "",
30
+ loadingText: "",
31
+ reportType: "",
32
+ halfPage: true,
33
+ fullPage: false,
34
+ pageSize: 10,
35
+ nextPage: 1,
36
+ totalItems: 30,
37
+ data: [],
38
+ type: "tile",
39
+ autoAPICalled: false,
40
+ showPrint: false,
41
+ showBarcode: false,
42
+ isSSL: true,
43
+ saveInPublicStorage: true,
44
+ keys: [],
45
+ order: 0,
46
+ };
47
+ }
48
+
49
+ export { ReportDetailData };
@@ -0,0 +1,44 @@
1
+ import * as admin from 'firebase-admin';
2
+ import { Company } from './company.model';
3
+
4
+ class ReportVisibility{
5
+
6
+ static async setReportVisibility(firestore:admin.firestore.Firestore,nickName:string,reportVisibilityData:any){
7
+ let companyId = await Company.getCompanyIdbyNickname(firestore,nickName);
8
+ let docRef = firestore
9
+ .collection("Companies")
10
+ .doc(companyId)
11
+ .collection("Report-Visibility")
12
+ .doc(reportVisibilityData.id);
13
+ docRef.set(reportVisibilityData);
14
+ return docRef.id;
15
+ }
16
+
17
+ static async updateReportVisibility(firestore:admin.firestore.Firestore,arrayUnion:any,nickName:string,userId:string,reportVisibilityData:any){
18
+ let companyId = await Company.getCompanyIdbyNickname(firestore,nickName);
19
+ let docRef = await firestore.collection("Companies")
20
+ .doc(companyId)
21
+ .collection("Report-Visibility")
22
+ .doc(userId).get();
23
+ await docRef.ref.update({
24
+ "report-sections": arrayUnion(reportVisibilityData)
25
+ })
26
+ return docRef.data()?.id
27
+ }
28
+
29
+ static async getUserReportList(firestore:admin.firestore.Firestore,companyId:string,userId:string){
30
+ try{
31
+ let userReportSnapshot = await firestore.collection("Companies")
32
+ .doc(companyId)
33
+ .collection("Report-Visibility")
34
+ .doc(userId)
35
+ .get()
36
+ let userReportsList = userReportSnapshot.data()
37
+ return userReportsList;
38
+ }
39
+ catch(error:any){
40
+ throw new Error(error.message)
41
+ }
42
+ }
43
+ }
44
+ export { ReportVisibility };
@@ -0,0 +1,179 @@
1
+ import { ReportDefinition } from "./report-definition.model";
2
+ import * as admin from "firebase-admin";
3
+ import { ReportActions } from "./report-actions.model";
4
+ import { Action } from "./action.model";
5
+ import { Utilities } from "./utility.model";
6
+ import { ReportGenerator } from "./reportGenerator.model";
7
+ import { Pool } from "mysql2";
8
+
9
+ class Report {
10
+ static async addReport(
11
+ firebase: admin.firestore.Firestore,
12
+ companyId: string,
13
+ report: ReportDefinition
14
+ ) {
15
+ let reportRef = firebase
16
+ .collection("Companies")
17
+ .doc(companyId)
18
+ .collection("Report-Definition-Detail")
19
+ .doc();
20
+ report.id = reportRef.id;
21
+ try {
22
+ await reportRef.set({ ...report });
23
+ return report;
24
+ } catch (e) {
25
+ throw e;
26
+ }
27
+ }
28
+
29
+ static async addReportAction(
30
+ firestore: admin.firestore.Firestore,
31
+ companyId: string,
32
+ reportActionMap: ReportActions
33
+ ) {
34
+ var raRef = firestore
35
+ .collection("Companies")
36
+ .doc(companyId)
37
+ .collection("Report-Actions")
38
+ .doc(reportActionMap.id);
39
+ raRef.set({ ...reportActionMap });
40
+
41
+ return reportActionMap;
42
+ }
43
+
44
+ static async getReport(
45
+ firestore: admin.firestore.Firestore,
46
+ actionDBMap: Record<string, { connection: Pool, tableName: string }>,
47
+ nickName: string,
48
+ action: string,
49
+ timeStamps: any,
50
+ phone: string
51
+ ) {
52
+ try {
53
+ console.log("Inside getReport");
54
+ const startTime = await Utilities.epochToMySqlDateTime(timeStamps.fromDate);
55
+ const endTime = await Utilities.epochToMySqlDateTime(timeStamps.toDate);
56
+ const timeInterval = {
57
+ startTime,
58
+ endTime,
59
+ };
60
+ console.log(timeInterval);
61
+ const reportGenerator = new ReportGenerator();
62
+ const reportInfo = await reportGenerator.generateReport(
63
+ firestore,
64
+ actionDBMap,
65
+ nickName,
66
+ action,
67
+ timeInterval,
68
+ phone
69
+ );
70
+ return reportInfo;
71
+ } catch (error) {
72
+ throw error;
73
+ }
74
+ }
75
+
76
+ static async getCicoInfoForDay(
77
+ firestore: admin.firestore.Firestore,
78
+ userId: string,
79
+ companyId: string,
80
+ startTime: number
81
+ ) {
82
+ const cicoActionName = "check_in_out";
83
+ const cicoInfo = {
84
+ checkIn: "",
85
+ checkOut: "",
86
+ };
87
+ const cicoActionId = await Action.getActionId(
88
+ firestore,
89
+ companyId,
90
+ cicoActionName
91
+ );
92
+ const cicoInfo_snapshot = await firestore
93
+ .collection("Companies")
94
+ .doc(companyId)
95
+ .collection("Actions")
96
+ .doc(cicoActionId)
97
+ .collection(cicoActionName)
98
+ .where("userId", "==", userId)
99
+ .where("createdAt", ">=", startTime)
100
+ .where("createdAt", "<=", startTime + 86400000)
101
+ .orderBy("createdAt", "desc")
102
+ .get();
103
+ let checkInTime: number = 0;
104
+ let checkOutTime: number = 0;
105
+ cicoInfo_snapshot.forEach((doc: any) => {
106
+ if (doc.data().startAt) {
107
+ checkInTime = doc.data().startAt;
108
+ }
109
+ if (doc.data().endAt) {
110
+ checkOutTime = doc.data().endAt;
111
+ }
112
+ });
113
+ if (checkInTime === 0) {
114
+ cicoInfo.checkIn = "Not Found";
115
+ } else {
116
+ cicoInfo.checkIn = new Date(checkInTime).toLocaleTimeString("en-GB", {
117
+ timeZone: "asia/kolkata",
118
+ });
119
+ }
120
+ if (checkOutTime === 0) {
121
+ cicoInfo.checkOut = "Not Found";
122
+ } else {
123
+ cicoInfo.checkOut = new Date(checkOutTime).toLocaleTimeString("en-GB", {
124
+ timeZone: "asia/kolkata",
125
+ });
126
+ }
127
+ return cicoInfo;
128
+ }
129
+
130
+ static async getReportObjForUser(
131
+ firestore: admin.firestore.Firestore,
132
+ userId: any,
133
+ companyId: string,
134
+ action: string,
135
+ timeStamps: any
136
+ ) {
137
+ try {
138
+ let reportDocs: any = [];
139
+ const actionId = await Action.getActionId(firestore, companyId, action);
140
+ const userInfo_snapshot = await firestore
141
+ .collection("Companies")
142
+ .doc(companyId)
143
+ .collection("Actions")
144
+ .doc(actionId)
145
+ .collection(action)
146
+ .where("userId", "==", userId)
147
+ .get();
148
+ userInfo_snapshot.forEach((doc) => {
149
+ if (
150
+ doc.data().createdAt >= timeStamps.fromDate &&
151
+ doc.data().createdAt <= timeStamps.toDate
152
+ ) {
153
+ reportDocs.push(doc.data());
154
+ }
155
+ });
156
+ return reportDocs;
157
+ } catch (error) {
158
+ throw error;
159
+ }
160
+ }
161
+
162
+ static async getReportObjForDay(reportObjects: any, startTime: number) {
163
+ try {
164
+ const milliSecondsInADay = 24 * 60 * 60 * 1000;
165
+ let reportObjectsForDay = reportObjects.filter((obj: any) => {
166
+ if (obj.createdAt < startTime + milliSecondsInADay) {
167
+ return true;
168
+ } else {
169
+ return false;
170
+ }
171
+ });
172
+ return reportObjectsForDay;
173
+ } catch (error) {
174
+ throw error;
175
+ }
176
+ }
177
+ }
178
+
179
+ export { Report };