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,87 @@
1
+ import * as admin from "firebase-admin";
2
+ class Request {
3
+ id!: string;
4
+ message!: string;
5
+ phone!: string;
6
+ firstName!: string;
7
+ lastName!: string;
8
+ email!: string;
9
+ private _sendUpdates!: boolean;
10
+
11
+ public get sendUpdates(): boolean {
12
+ return this._sendUpdates;
13
+ }
14
+ public set sendUpdates(value: boolean) {
15
+ this._sendUpdates = value;
16
+ }
17
+
18
+ constructor() {}
19
+
20
+ argConstructor(
21
+ id: string,
22
+ message: string,
23
+ phone: string,
24
+ firstName: string,
25
+ lastName: string,
26
+ email: string,
27
+ _sendUpdates: boolean
28
+ ) {
29
+ this.id = id;
30
+ this.message = message;
31
+ this.phone = phone;
32
+ this.firstName = firstName;
33
+ this.lastName = lastName;
34
+ this.email = email;
35
+ this._sendUpdates = _sendUpdates
36
+ }
37
+
38
+ fromJSON(request: string) {
39
+ let requestJSON = JSON.parse(request);
40
+
41
+ this.id = requestJSON["phone"];
42
+ this.message = requestJSON["message"];
43
+ this.phone = requestJSON["phone"];
44
+ this.firstName = requestJSON["firstName"];
45
+ this.lastName = requestJSON["lastName"];
46
+ this.email = requestJSON["email"];
47
+ this._sendUpdates = requestJSON["sendUpdates"]
48
+ }
49
+
50
+ toJSON() {
51
+ return {
52
+ id: this.phone,
53
+ message: this.message,
54
+ phone: this.phone,
55
+ firstName: this.firstName,
56
+ lastName: this.lastName,
57
+ email: this.email,
58
+ sendUpdates: this._sendUpdates
59
+ };
60
+ }
61
+
62
+ async save(firestore: admin.firestore.Firestore) {
63
+ let requestDoc: admin.firestore.DocumentReference = firestore
64
+ .collection("Requests")
65
+ .doc(this.phone.toString());
66
+
67
+ const requestDocInfo = await requestDoc.get();
68
+ const reqsInfo = requestDocInfo.data();
69
+ if (reqsInfo) {
70
+ reqsInfo.requests.push(this.toJSON());
71
+ await requestDoc.set(reqsInfo)
72
+ } else {
73
+ const newRequest = {
74
+ id: this.phone,
75
+ requests: [this.toJSON()]
76
+ }
77
+ await requestDoc.set(newRequest);
78
+ }
79
+ return {
80
+ status: "OK",
81
+ message: "Request Added Successfully",
82
+ path: requestDoc.path,
83
+ };
84
+ }
85
+ }
86
+
87
+ export { Request };
@@ -0,0 +1,30 @@
1
+ import { Pool, PoolConnection, RowDataPacket, ResultSetHeader, OkPacket } from 'mysql2';
2
+
3
+ class CurdService {
4
+ private pool: Pool;
5
+
6
+ constructor(pool: Pool) {
7
+ this.pool = pool;
8
+ }
9
+
10
+ public async query(queryString: string): Promise<RowDataPacket[] | ResultSetHeader | OkPacket> {
11
+ return new Promise((resolve, reject) => {
12
+ this.pool.getConnection((err, connection: PoolConnection) => {
13
+ if (err) {
14
+ reject(err);
15
+ return;
16
+ }
17
+ connection.query(queryString, (err, result:any) => {
18
+ connection.release();
19
+ if (err) {
20
+ reject(err);
21
+ return;
22
+ }
23
+ resolve(result);
24
+ });
25
+ });
26
+ });
27
+ }
28
+ }
29
+
30
+ export default CurdService;
@@ -0,0 +1,47 @@
1
+ import * as admin from "firebase-admin"
2
+ import { User } from "./user.model";
3
+
4
+ class CustomCollection {
5
+ id: string = "";
6
+
7
+ static async createCustomCollection(
8
+ firestore: admin.firestore.Firestore,
9
+ collectionDetails: any
10
+ ) {
11
+ try {
12
+ let collection_snapshot = await firestore.collection("customCollection")
13
+ .get();
14
+ if (collection_snapshot.empty) {
15
+ console.log("no collection found: creating one...");
16
+ await CustomCollection.createNewCollection(firestore, collectionDetails);
17
+ } else {
18
+ throw new Error("there is already a collection with this name.");
19
+ }
20
+ } catch (error) {
21
+ console.log(error);
22
+ }
23
+ }
24
+
25
+ static async createNewCollection(firestore: admin.firestore.Firestore,
26
+ collectionDetails: any) {
27
+ let restructuredDetails: any = await CustomCollection.restructureDetails(collectionDetails);
28
+ let docRef = firestore.collection("CustomCollections").doc();
29
+ restructuredDetails.id = docRef.id;
30
+ await docRef.set(restructuredDetails);
31
+ return restructuredDetails;
32
+ }
33
+
34
+ static async restructureDetails(collectionDetails: any) {
35
+ // for now collectionDetails remain unaltered
36
+ return collectionDetails;
37
+ }
38
+
39
+ static async getUserWorkAreaList(firestore:admin.firestore.Firestore,companyId:string,phone:string){
40
+ let userId = await User.getUserIdByPhone(firestore,phone)
41
+ let workAreaSnapShot = await firestore.collection("CustomCollections").doc(companyId).collection("Users").doc(userId).get()
42
+ return workAreaSnapShot.data()
43
+ }
44
+
45
+ }
46
+
47
+ export { CustomCollection };
@@ -0,0 +1,85 @@
1
+ import { Firestore } from "@google-cloud/firestore";
2
+ import * as admin from "firebase-admin";
3
+
4
+ class Customer {
5
+ customerName: string;
6
+ address: string;
7
+ zipcode: string;
8
+ city: string;
9
+ state: string;
10
+ GSTNo: string;
11
+ contactName: string;
12
+ contactNo: string;
13
+
14
+ constructor(customerName: string,
15
+ address: string,
16
+ zipcode: string,
17
+ city: string,
18
+ state: string,
19
+ GSTNo: string,
20
+ contactName: string,
21
+ contactNo: string) {
22
+ this.customerName = customerName;
23
+ this.address = address;
24
+ this.zipcode = zipcode;
25
+ this.city = city;
26
+ this.state = state;
27
+ this.GSTNo = GSTNo;
28
+ this.contactName = contactName;
29
+ this.contactNo = contactNo;
30
+ }
31
+ }
32
+
33
+ class CustomerContact {
34
+ customerId: number;
35
+ contactName: string;
36
+ contactNo: string;
37
+ alternateContactNo: string;
38
+ designation: string;
39
+ constructor(
40
+ customerId: number,
41
+ contactName: string,
42
+ contactNo: string,
43
+ alternateContactNo: string,
44
+ designation: string
45
+ ) {
46
+ this.customerId = customerId;
47
+ this.contactName = contactName;
48
+ this.contactNo = contactNo;
49
+ this.alternateContactNo = alternateContactNo;
50
+ this.designation = designation;
51
+ }
52
+ }
53
+
54
+ class CustomerCard {
55
+ companyId: string;
56
+ userId: string;
57
+ createdAt: string;
58
+ actionName: string;
59
+ actionType: string;
60
+ actionId: string;
61
+ actionEvent: string;
62
+ extraData: any;
63
+ id: string;
64
+ constructor(companyId: string,
65
+ userId: string,
66
+ createdAt: string,
67
+ actionName: string,
68
+ actionType: string,
69
+ actionId: string,
70
+ actionEvent: string,
71
+ extraData: any,
72
+ id: string) {
73
+ this.companyId = companyId;
74
+ this.userId = userId;
75
+ this.createdAt = createdAt;
76
+ this.actionName = actionName;
77
+ this.actionType = actionType;
78
+ this.actionId = actionId;
79
+ this.actionEvent = actionEvent;
80
+ this.extraData = extraData;
81
+ this.id = id;
82
+ }
83
+ }
84
+
85
+ export { Customer, CustomerContact, CustomerCard };
@@ -0,0 +1,150 @@
1
+ import * as admin from "firebase-admin";
2
+ import { Action } from "./action.model";
3
+ import { Company } from "./company.model";
4
+ import { Offline } from "./offline.model";
5
+ class DeviceChangeReq {
6
+ static async checkIsReqPending(firestore: admin.firestore.Firestore,
7
+ deviceChangeInfo: any, company: string) {
8
+ const newDeviceId = deviceChangeInfo.extra.extraData.deviceId;
9
+ const nickName = "mobiOffice";
10
+ const requestCompanyId = await Company.getCompanyIdByNickName(firestore, company);
11
+ console.log("requestCompanyId", requestCompanyId);
12
+ const companyId = await Company.getCompanyIdByNickName(firestore, nickName);
13
+ const actionName = deviceChangeInfo.actionName;
14
+ let isReqPending = false;
15
+ console.log("companyId", companyId, "actionName", actionName);
16
+ const actionId = await Action.getActionId(firestore, companyId, actionName);
17
+ console.log(companyId, requestCompanyId);
18
+ const deviceChangeReqs = await firestore.collection("Companies")
19
+ .doc(companyId)
20
+ .collection("Actions")
21
+ .doc(actionId)
22
+ .collection(actionName)
23
+ .where("reqCompanyId", "==", requestCompanyId)
24
+ .get()
25
+ deviceChangeReqs.forEach((doc: any) => {
26
+ console.log("compare", doc.data().extraData.deviceId, newDeviceId, doc.data().isProcessed);
27
+ if (doc.data().extraData.deviceId === newDeviceId
28
+ && doc.data().isProcessed === false) {
29
+ isReqPending = true;
30
+ }
31
+ })
32
+ return isReqPending;
33
+ }
34
+
35
+ static async fetchOpenReqs(firestore: admin.firestore.Firestore,
36
+ companyId: string) {
37
+ const nickName = "mobiOffice";
38
+ const supportCompanyId = await Company.getCompanyIdByNickName(firestore, nickName);
39
+ const actionName = "requestForm";
40
+ const actionId = await Action.getActionId(firestore, supportCompanyId, actionName);
41
+ const allRequestsDocs = await firestore.collection("Companies")
42
+ .doc(supportCompanyId)
43
+ .collection("Actions")
44
+ .doc(actionId)
45
+ .collection(actionName)
46
+ .get();
47
+ let allRequestsData = allRequestsDocs.docs.map((doc) => {
48
+ return doc.data();
49
+ })
50
+ let openRequests = allRequestsData.filter((doc) => {
51
+ return doc.reqCompanyId === companyId && !doc.isProcessed;
52
+ })
53
+ return openRequests;
54
+ }
55
+
56
+ static async approve(firestore: admin.firestore.Firestore,
57
+ approvalDetails: any) {
58
+ const extraData = approvalDetails.extra.extraData;
59
+ const companyId = extraData.companyNameId;
60
+ const requestId = extraData.requestId;
61
+ const requestStatus = extraData.approval;
62
+ const openRequests = await this.fetchOpenReqs(firestore, companyId);
63
+ const objToProcess: any = [];
64
+ openRequests.forEach(async (doc) => {
65
+ if( doc.eventId === requestId) {
66
+ objToProcess.push(doc);
67
+ }
68
+ })
69
+ if (objToProcess.length !== 0) {
70
+ const licenseDoc = await firestore.collection("Licenses")
71
+ .where("company", "==", objToProcess[0].company)
72
+ .where("user", "==", `+${objToProcess[0].extraData.phone}`)
73
+ .get();
74
+ let license = licenseDoc.docs.map((doc) => {
75
+ return doc.data();
76
+ })[0];
77
+ const updatedLicense = await this.replaceOldDeviceWithNew(license, objToProcess[0]);
78
+ console.log(updatedLicense);
79
+ if (updatedLicense) {
80
+ licenseDoc.forEach(doc => {
81
+ doc.ref.set(updatedLicense);
82
+ })
83
+ }
84
+ await this.updateCompanyActionDoc(firestore, requestId, requestStatus);
85
+ } else {
86
+ throw new Error("no documents to process");
87
+ }
88
+ }
89
+
90
+ static async replaceOldDeviceWithNew(license: any, objToProcess: any) {
91
+ const extraDevices = license.extraDevices;
92
+ const newDeviceObj = {
93
+ fromDate: Date.now(),
94
+ modelName: objToProcess.extraData.model,
95
+ brandName: objToProcess.extraData.brand,
96
+ deviceId: objToProcess.extraData.deviceId
97
+ }
98
+ const indexToReplace = await this.getIndexToReplace(extraDevices, objToProcess.extraData.oldDeviceId);
99
+ if (indexToReplace === "not found") {
100
+ return null;
101
+ }
102
+ extraDevices.splice(indexToReplace, 1, newDeviceObj);
103
+ license.extraDevices = extraDevices;
104
+ return license;
105
+ }
106
+
107
+ static async getIndexToReplace(extraDevices: any, deviceId: string) {
108
+ for (let i = 0; i < extraDevices.length; i++) {
109
+ if (extraDevices[i].deviceId === deviceId) {
110
+ return i;
111
+ }
112
+ }
113
+ return "not found";
114
+ }
115
+
116
+ static async updateCompanyActionDoc(firestore: admin.firestore.Firestore,
117
+ requestId: string,
118
+ requestStatus: string) {
119
+ const companyId = await Company.getCompanyIdByNickName(firestore, "mobiOffice");
120
+ const actionName = "requestForm";
121
+ const actionId = await Action.getActionId(firestore, companyId, actionName);
122
+ const doc = await firestore.collection("Companies")
123
+ .doc(companyId)
124
+ .collection("Actions")
125
+ .doc(actionId)
126
+ .collection(actionName)
127
+ .doc(requestId)
128
+ .get();
129
+ await doc.ref.update({
130
+ isProcessed: true,
131
+ approval: requestStatus
132
+ })
133
+
134
+ const supportUsers = await Company.getUsersListbyCompany(firestore, "mobiOffice");
135
+
136
+ for(let user of supportUsers) {
137
+ const docRef = await firestore.collection("Feeds").doc(user.id).collection(companyId).doc(requestId).get();
138
+ const docData = docRef.data();
139
+ const extraData = docData?.extraData;
140
+ extraData["approval"] = requestStatus
141
+ await firestore.collection("Feeds").doc(user.id).collection(companyId).doc(requestId).update({
142
+ isProcessed: true,
143
+ extraData: extraData
144
+ })
145
+ }
146
+
147
+ }
148
+ }
149
+
150
+ export { DeviceChangeReq };
@@ -0,0 +1,99 @@
1
+ import { Post } from "./post.model"
2
+ import * as admin from "firebase-admin";
3
+ import { Offline } from "./offline.model";
4
+ import { TempCollection } from "./tempCollection.model";
5
+ import { User } from "./user.model";
6
+
7
+ class Dispatch extends Post {
8
+ actionEvent: string = "";
9
+ actionType: string = "worklog";
10
+ actionName: string = "dispatch";
11
+ customerName:string = ""
12
+
13
+ static async createPostforDispatch(firestore: admin.firestore.Firestore,postInfo: any,uniqueId:string){
14
+ let post = new Dispatch();
15
+ post = await Dispatch.setIncomingInfoToDispatch(postInfo, post);
16
+ console.log(post)
17
+ let eventId = await Post.createNewPost(firestore,post)
18
+ await TempCollection.deleteTempCollection(firestore,uniqueId)
19
+ return eventId
20
+ }
21
+
22
+ static async createPostForSODispatch(firestore: admin.firestore.Firestore, postInfo: any, status: string) {
23
+ console.log("in create post for dispatch");
24
+ const userInfo: any = await User.getUserInfoById(firestore, postInfo.userId, postInfo.companyId);
25
+ const extraData = postInfo.extra.extraData;
26
+ extraData.status = status;
27
+ extraData.time = postInfo.createdAt;
28
+ extraData.date = new Date(postInfo.createdAt).toLocaleDateString("en-GB");
29
+ extraData.userName = userInfo.name;
30
+ console.log(extraData);
31
+ let post = {
32
+ ...postInfo,
33
+ extraData: extraData,
34
+ actionId: postInfo.extra.actionId,
35
+ description: postInfo.extra.extraData.customerName,
36
+ actionType: "worklog"
37
+ };
38
+ delete post.extra;
39
+ console.log(post);
40
+ console.log("creating post for dispatch");
41
+ let eventId = await Post.createNewPost(firestore, post);
42
+ return eventId;
43
+ }
44
+
45
+ static async setIncomingInfoToDispatch(info:any, post:Dispatch){
46
+ post.actionEvent = info.extra.actionEvent;
47
+ post.id = info.id
48
+ post.customerName = info.customerName
49
+ post.actionId = info.extra.actionId;
50
+ post.companyId = info.extra.companyId;
51
+ post.createdAt = info.extra.createdAt;
52
+ post.description = info.description;
53
+ post.eventId = info.extra.eventId;
54
+ post.isGeofence = info.extra.isGeofence;
55
+ post.userId = info.userId;
56
+ const newExtraData = await this.modifyExtraDataForDispatch(info);
57
+ post.extraData = newExtraData;
58
+ post.seen = info.extra.seen;
59
+ post.startAt = "";
60
+ post.startLat = info.extra.startLat;
61
+ post.startLong = info.extra.startLong;
62
+ post.endAt = "";
63
+ post.endLat = info.extra.endLat;
64
+ post.endLong = info.extra.endLong;
65
+ post.stepValues = info.extra.stepValues;
66
+ post.time = info.extra.time;
67
+ post.checkInternet = info.extra.checkInternet;
68
+ return post;
69
+ }
70
+
71
+ static async modifyExtraDataForDispatch(info: any) {
72
+ const time = info.createdAt;
73
+ const date = new Date(time).toLocaleDateString("en-GB");
74
+ const newExtraData = {
75
+ ...info.extra.extraData,
76
+ status: "Pending",
77
+ customerName: info.description.split("--")[0],
78
+ date: date,
79
+ time: time
80
+ }
81
+ return newExtraData;
82
+ }
83
+
84
+ static async getSODesignsByDocId(firestore: admin.firestore.Firestore,
85
+ uniqueId: string) {
86
+ try {
87
+ const storedInfoDoc = await firestore.collection("TempCollection")
88
+ .doc(uniqueId)
89
+ .get();
90
+ const info: any = storedInfoDoc.data();
91
+ console.log(info.scannedTakas);
92
+ return info.scannedTakas;
93
+ } catch(error: any) {
94
+ throw new Error(error.message)
95
+ }
96
+ }
97
+ }
98
+
99
+ export { Dispatch };
@@ -0,0 +1,104 @@
1
+ import * as admin from 'firebase-admin';
2
+ import { Attendance } from './attendance.model';
3
+ import { Offline } from './offline.model';
4
+
5
+ class Feeds {
6
+
7
+ static async initFeed(firestore: admin.firestore.Firestore) {
8
+ let document = firestore.collection('Feeds').doc();
9
+ await document.set({
10
+ id: document.id,
11
+ })
12
+ return "success"
13
+ }
14
+
15
+ static async updateFeed(firestore: admin.firestore.Firestore, userId: string, companyId: string, eventId: string, data: any, isError: boolean, lotNo: string) {
16
+ console.log("going to update cards");
17
+ await Feeds.updateFeedForUser(firestore, userId, companyId, eventId, data, isError, lotNo);
18
+ let managersList = await Offline.getUserManagersList(firestore, companyId, userId);
19
+ for (let manager of managersList) {
20
+ await Feeds.updateFeedForUser(firestore, manager, companyId, eventId, data, isError, lotNo);
21
+ }
22
+ return "success"
23
+ }
24
+
25
+ static async updateFeedForUser(firestore: admin.firestore.Firestore, userId: string, companyId: string, eventId: string, data: any, isError: boolean, lotNo: string) {
26
+ console.log("received info");
27
+ let userFeedDoc = await firestore.collection("Feeds").doc(userId).collection(companyId).where("eventId", "==", eventId).get()
28
+ let description = userFeedDoc.docs[0].data().description || "";
29
+ let extraData = userFeedDoc.docs[0].data().extraData
30
+ const oldUserFeedDoc = userFeedDoc.docs[0].data();
31
+ delete oldUserFeedDoc.extraData;
32
+ console.log("deleted extraData from oldUserFeedDoc");
33
+ extraData = {
34
+ ...extraData,
35
+ lotNo,
36
+ status: data
37
+ }
38
+ let newUserFeedDoc: any = {};
39
+ if (isError) {
40
+ console.log("api sent error response");
41
+ newUserFeedDoc.cardColor = "#FFF44336";
42
+ } else {
43
+ console.log("api send success response");
44
+ if (extraData.toBePrinted) {
45
+ extraData.print = extraData.toBePrinted;
46
+ extraData.print["lot_no"] = lotNo
47
+ delete extraData.toBePrinted;
48
+ }
49
+ }
50
+
51
+ description = `${description}--${data.split(" ").slice(0, 3).join(" ")}`;
52
+
53
+ console.log("updated the description");
54
+ newUserFeedDoc = {
55
+ ...oldUserFeedDoc,
56
+ ...newUserFeedDoc,
57
+ description: description,
58
+ extraData: extraData
59
+ }
60
+ console.log("going to set the newUserFeedDoc");
61
+ userFeedDoc.forEach((doc) => {
62
+ doc.ref.set(newUserFeedDoc)
63
+ })
64
+ console.log("done");
65
+ // userFeedDoc.forEach((doc)=>{
66
+ // doc.ref.update({
67
+ // description:description,
68
+ // extraData:extraData
69
+ // })
70
+ // if (doc.data().tobePrinted) {
71
+ // doc.ref.update({
72
+ // print: doc.data().tobePrinted
73
+ // })
74
+ // }
75
+ // if (isError) {
76
+ // doc.ref.update({
77
+ // cardColor: "#FFF44336"
78
+ // })
79
+ // }
80
+ // })
81
+ return "success"
82
+ }
83
+
84
+ static async updateEndMeetingsTimeInFeeds(firestore: admin.firestore.Firestore, userId: string, companyId: string, eventId: string, endTime: number) {
85
+ let userFeedDoc = await firestore.collection("Feeds").doc(userId).collection(companyId).where("eventId", "==", eventId).get()
86
+ if (userFeedDoc.docs.length) {
87
+ let extraData = userFeedDoc.docs[0].data().extraData
88
+ extraData = {
89
+ ...extraData,
90
+ "End Time": endTime
91
+ }
92
+ console.log(extraData)
93
+ userFeedDoc.forEach((doc) => {
94
+ doc.ref.update({
95
+ extraData: extraData
96
+ })
97
+ })
98
+ return "success"
99
+ }
100
+ }
101
+
102
+
103
+ }
104
+ export { Feeds };
@@ -0,0 +1,61 @@
1
+ import * as admin from "firebase-admin";
2
+ import { Company } from "./company.model";
3
+
4
+ class Geofence{
5
+
6
+ static async getOrCreateGeoFence(firestore:admin.firestore.Firestore,geofenceDoc:any){
7
+ let snapshot = await firestore.collection('Geofence').where('companyNickName','==',geofenceDoc.companyNickName).get()
8
+ if(snapshot.empty){
9
+ if(!geofenceDoc.companyId){
10
+ let companynickname = await Company.getCompanyIdbyNickname(firestore,geofenceDoc.companyNickName)
11
+ geofenceDoc.companyId = companynickname
12
+ }
13
+ geofenceDoc = await Geofence.convertGeofenceDataType(geofenceDoc)
14
+ let geofence_snapshot = firestore.collection("Geofence").doc()
15
+ let docId = geofence_snapshot.id
16
+ geofenceDoc.id = docId
17
+ geofence_snapshot.set(geofenceDoc)
18
+ return geofenceDoc
19
+ }
20
+ return snapshot.docs[0].data()
21
+ }
22
+
23
+ static async convertGeofenceDataType(geoFenceDoc:any){
24
+ if(geoFenceDoc.geoFenceIds){
25
+ geoFenceDoc.geoFenceIds = geoFenceDoc.geoFenceIds.split('&').map(Number)
26
+ }else{
27
+ geoFenceDoc.geoFenceIds = []
28
+ }
29
+ for(let value of geoFenceDoc.geoFence){
30
+ if(value.area){
31
+ value.area = Number(value.area)
32
+ }
33
+ value.attributes = {}
34
+ if(value.calendarId){
35
+ value.calendarId = Number(value.calendarId)
36
+ }
37
+ if(value.id){
38
+ value.id = Number(value.id)
39
+ }
40
+ }
41
+ return geoFenceDoc
42
+ }
43
+
44
+ static async updateGeofence(firestore:admin.firestore.Firestore,arrayUnion:any,geofenceDoc:any){
45
+ let snapshot = await firestore.collection('Geofence').where('companyNickName','==',geofenceDoc.companyNickName).get()
46
+ if(snapshot.empty){
47
+ return `create geofence for this company ${geofenceDoc.nickName}`
48
+ }else{
49
+ for(let geofenceDetail of geofenceDoc.geoFence){
50
+ snapshot.forEach((doc)=>{
51
+ doc.ref.update({
52
+ geoFence: arrayUnion(geofenceDetail),
53
+ geoFenceIds:arrayUnion(geofenceDetail.id)
54
+ })
55
+ })
56
+ }
57
+ return "updated successfully"
58
+ }
59
+ }
60
+ }
61
+ export { Geofence }