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.
- package/.prettierrc +4 -0
- package/README.md +1 -0
- package/a.js +3 -0
- package/lib/index.js +87 -0
- package/package.json +50 -0
- package/scripts/1.ts +1300 -0
- package/scripts/GCloudPubSub/pub-sub-config.json +12 -0
- package/scripts/GCloudPubSub/visitorAutoRejection.ts +86 -0
- package/scripts/actions/assignUsersFromOneActionToOther.ts +64 -0
- package/scripts/actions/assignUsersListToAction.ts +81 -0
- package/scripts/actions/getActionsListOfUser.ts +42 -0
- package/scripts/actions/getCompanyUserDetails.ts +49 -0
- package/scripts/actions/giveActionToUser.ts +41 -0
- package/scripts/actions/giveUsersToActivitySelector.ts +56 -0
- package/scripts/actions/groupActionsInActivitySelector.ts +101 -0
- package/scripts/actions/modifySummaryReportDB.ts +42 -0
- package/scripts/actions/setUrlToActionStep.ts +18 -0
- package/scripts/actions/syncMySqlAttendanceDBWithFirebase.ts +93 -0
- package/scripts/actions/syncMySqlMeetingsDBWithFirebase.ts +103 -0
- package/scripts/actions/test.ts +29 -0
- package/scripts/actions/transferFeedsOldIdToNew.ts +40 -0
- package/scripts/actions/transformUserIntoManager.ts +89 -0
- package/scripts/argvConfig.js +9 -0
- package/scripts/backUpData/testCode.ts +131 -0
- package/scripts/benaraScripts/addWorkAreaMap.ts +46 -0
- package/scripts/benaraScripts/add_customers.ts +26 -0
- package/scripts/benaraScripts/add_customers_contact.ts +27 -0
- package/scripts/benaraScripts/add_empty_work_area.ts +17 -0
- package/scripts/benaraScripts/assignManagers.ts +35 -0
- package/scripts/benaraScripts/changeCheckInFlag.ts +45 -0
- package/scripts/benaraScripts/createCustomerContactsList.ts +170 -0
- package/scripts/benaraScripts/createUserByDeletingOldUser.ts +70 -0
- package/scripts/benaraScripts/createUsersAreaMapCollection.ts +23 -0
- package/scripts/benaraScripts/createWorkAreaMap.ts +24 -0
- package/scripts/benaraScripts/mapWorkAreasToUsers.ts +112 -0
- package/scripts/companies_data.json +2496 -0
- package/scripts/create_or_update_users.ts +31 -0
- package/scripts/csvToJson/csvToJson.ts +90 -0
- package/scripts/csvToJson/users.json +3896 -0
- package/scripts/db.js +27 -0
- package/scripts/db.json +13 -0
- package/scripts/dbMySql.ts +63 -0
- package/scripts/delete_action_steps.ts +11 -0
- package/scripts/delete_user.ts +71 -0
- package/scripts/dev_companies_data.json +613 -0
- package/scripts/enroll.xlsx +0 -0
- package/scripts/export_users.ts +72 -0
- package/scripts/files/visitorManagementFiles/displayScreen.json +70 -0
- package/scripts/files/visitorManagementFiles/init_report_visibility.ts +79 -0
- package/scripts/firebaseConfig.js +12 -0
- package/scripts/firebaseDocs/deleteIncommingCollection.ts +47 -0
- package/scripts/firebaseDocs/updateDoc.ts +43 -0
- package/scripts/getActionDataIntoJSON/getActionData.ts +68 -0
- package/scripts/get_attendance_by_any_date.ts +14 -0
- package/scripts/get_attendance_by_month.ts +12 -0
- package/scripts/get_attendance_monthly_by_team.ts +11 -0
- package/scripts/get_daily_report.ts +10 -0
- package/scripts/get_mangers.ts +13 -0
- package/scripts/grant_user_license.ts +18 -0
- package/scripts/init_CustomCollection.ts +16 -0
- package/scripts/init_action_steps.ts +28 -0
- package/scripts/init_actions.ts +31 -0
- package/scripts/init_company.ts +18 -0
- package/scripts/init_customer_mysql.ts +12 -0
- package/scripts/init_feed.ts +4 -0
- package/scripts/init_feed_details_screen.ts +14 -0
- package/scripts/init_geofence.ts +26 -0
- package/scripts/init_print_details_screen.ts +14 -0
- package/scripts/init_report_actions.ts +24 -0
- package/scripts/init_report_definition_detail.ts +26 -0
- package/scripts/init_report_definition_summary.ts +16 -0
- package/scripts/init_report_visibility.ts +46 -0
- package/scripts/init_user_customcollection.ts +16 -0
- package/scripts/json/action.json +21 -0
- package/scripts/json/company.json +24 -0
- package/scripts/json/report-action.json +13 -0
- package/scripts/json/report-def-deet.json +43 -0
- package/scripts/json/resp.json +784 -0
- package/scripts/json/steps.json +24 -0
- package/scripts/json/test.ts +49 -0
- package/scripts/mysqlConfig.ts +9 -0
- package/scripts/revoke_or_extend_license.ts +14 -0
- package/scripts/stream.js +4 -0
- package/scripts/testing1.ts +35 -0
- package/scripts/update/doc.json +20 -0
- package/scripts/update/getDocByPath.ts +34 -0
- package/scripts/update/updateDocByPath.ts +47 -0
- package/scripts/update/updateUsersOfCompanies.ts +58 -0
- package/scripts/update_actions.ts +19 -0
- package/scripts/update_actions_steps.ts +19 -0
- package/scripts/update_company.ts +19 -0
- package/scripts/update_geofence.ts +20 -0
- package/scripts/update_managers.ts +16 -0
- package/scripts/visitorMgmt/createArea.ts +68 -0
- package/scripts/visitorMgmt/createArea.txt +3 -0
- package/scripts/visitorMgmt/createVisitorPathInstructionDocs.ts +130 -0
- package/scripts/visitorMgmt/createVisitorPathInstructionDocs.txt +18 -0
- package/scripts/visitorMgmt/encryptDateString.ts +71 -0
- package/scripts/visitorMgmt/makeHostsManagersOfEachOther.ts +117 -0
- package/scripts/whatsapp_gupshup/sendMessage.ts +97 -0
- package/src/index.ts +87 -0
- package/src/models/Feed-Details-Screen.model.ts +29 -0
- package/src/models/action.model.ts +355 -0
- package/src/models/actions/doffing.ts +71 -0
- package/src/models/actions/folding.ts +39 -0
- package/src/models/attendance.model.ts +615 -0
- package/src/models/cicoPost.model.ts +20 -0
- package/src/models/company.model.ts +975 -0
- package/src/models/contact-us/resquest.model.ts +87 -0
- package/src/models/crud/crud.ts +30 -0
- package/src/models/customCollection.model.ts +47 -0
- package/src/models/customer/customer.model.ts +85 -0
- package/src/models/deviceChangeReq.ts +150 -0
- package/src/models/dispatch.model.ts +99 -0
- package/src/models/feed.models.ts +104 -0
- package/src/models/geofence.model.ts +61 -0
- package/src/models/leaveApplicationPost.model.ts +79 -0
- package/src/models/license.model.ts +215 -0
- package/src/models/log.model.ts +25 -0
- package/src/models/meeting.model.ts +80 -0
- package/src/models/meter.model.ts +62 -0
- package/src/models/missingPunchPost.model.ts +84 -0
- package/src/models/offline.model.ts +1133 -0
- package/src/models/post.model.ts +105 -0
- package/src/models/printDetailsScreen.model.ts +30 -0
- package/src/models/pushNotifications/pushNotification.model.ts +17 -0
- package/src/models/report-actions.model.ts +57 -0
- package/src/models/report-definition-details.model.ts +89 -0
- package/src/models/report-definition.model.ts +26 -0
- package/src/models/report-definitions-summary.model.ts +59 -0
- package/src/models/report-detail-data.model.ts +49 -0
- package/src/models/report-visibility.model.ts +44 -0
- package/src/models/report.model.ts +179 -0
- package/src/models/reportGenerator.model.ts +883 -0
- package/src/models/response.model.ts +31 -0
- package/src/models/steps.factory.model.ts +195 -0
- package/src/models/storeGupShupLog.model.ts +49 -0
- package/src/models/summary.model.ts +63 -0
- package/src/models/tasks/sub-task-group.model.ts +173 -0
- package/src/models/tasks/tags.model.ts +113 -0
- package/src/models/tasks/task-group.model.ts +172 -0
- package/src/models/tasks/task.model.ts +681 -0
- package/src/models/tempCollection.model.ts +398 -0
- package/src/models/user.model.ts +319 -0
- package/src/models/utility.model.ts +100 -0
- package/src/models/visitorManagement/acknowledgement.model.ts +71 -0
- package/src/models/visitorManagement/invite.model.ts +406 -0
- package/src/models/visitorManagement/newIn.model.ts +82 -0
- package/src/models/visitorManagement/selfServe.model.ts +58 -0
- package/src/models/worklogPost.model.ts +8 -0
- package/src/services/customer.ts +382 -0
- package/src/services/meeting.ts +123 -0
- package/test/1.ts +13 -0
- package/test/db.js +19 -0
- package/test/firebaseConfig.js +1 -0
- package/tsconfig.json +16 -0
@@ -0,0 +1,681 @@
|
|
1
|
+
import * as admin from "firebase-admin";
|
2
|
+
import { SubTaskGroup } from "./sub-task-group.model";
|
3
|
+
import { Tag } from "./tags.model";
|
4
|
+
import { TaskGroup } from "./task-group.model";
|
5
|
+
import { Company } from "../company.model";
|
6
|
+
import { Action } from "../action.model";
|
7
|
+
|
8
|
+
class Task {
|
9
|
+
private _id!: string | "";
|
10
|
+
public get id(): string | "" {
|
11
|
+
return this._id;
|
12
|
+
}
|
13
|
+
public set id(value: string | "") {
|
14
|
+
this._id = value;
|
15
|
+
}
|
16
|
+
|
17
|
+
private _taskGroupId!: string | "";
|
18
|
+
public get taskGroupId(): string | "" {
|
19
|
+
return this._taskGroupId;
|
20
|
+
}
|
21
|
+
public set taskGroupId(value: string | "") {
|
22
|
+
this._taskGroupId = value;
|
23
|
+
}
|
24
|
+
|
25
|
+
private _groupId!: string | "";
|
26
|
+
public get groupId(): string | "" {
|
27
|
+
return this._groupId;
|
28
|
+
}
|
29
|
+
public set groupId(value: string | "") {
|
30
|
+
this._groupId = value;
|
31
|
+
}
|
32
|
+
|
33
|
+
private _title!: string | "";
|
34
|
+
public get title(): string | "" {
|
35
|
+
return this._title;
|
36
|
+
}
|
37
|
+
public set title(value: string | "") {
|
38
|
+
this._title = value;
|
39
|
+
}
|
40
|
+
|
41
|
+
private _description!: string | "";
|
42
|
+
public get description(): string | "" {
|
43
|
+
return this._description;
|
44
|
+
}
|
45
|
+
public set description(value: string | "") {
|
46
|
+
this._description = value;
|
47
|
+
}
|
48
|
+
|
49
|
+
private _priority!: string | "";
|
50
|
+
public get priority(): string | "" {
|
51
|
+
return this._priority;
|
52
|
+
}
|
53
|
+
public set priority(value: string | "") {
|
54
|
+
this._priority = value;
|
55
|
+
}
|
56
|
+
|
57
|
+
private _assignee!: string[] | [];
|
58
|
+
public get assignee(): string[] | [] {
|
59
|
+
return this._assignee;
|
60
|
+
}
|
61
|
+
public set assignee(value: string[] | []) {
|
62
|
+
this._assignee = value;
|
63
|
+
}
|
64
|
+
|
65
|
+
private _assets!: string[] | [];
|
66
|
+
public get assets(): string[] | [] {
|
67
|
+
return this._assets;
|
68
|
+
}
|
69
|
+
public set assets(value: string[] | []) {
|
70
|
+
this._assets = value;
|
71
|
+
}
|
72
|
+
|
73
|
+
private _locations!: string[] | [];
|
74
|
+
public get locations(): string[] | [] {
|
75
|
+
return this._locations;
|
76
|
+
}
|
77
|
+
public set locations(value: string[] | []) {
|
78
|
+
this._locations = value;
|
79
|
+
}
|
80
|
+
|
81
|
+
private _watchers!: string[] | [];
|
82
|
+
public get watchers(): string[] | [] {
|
83
|
+
return this._watchers;
|
84
|
+
}
|
85
|
+
public set watchers(value: string[] | []) {
|
86
|
+
this._watchers = value;
|
87
|
+
}
|
88
|
+
|
89
|
+
private _reminderDate!: number | null;
|
90
|
+
public get reminderDate(): number | null {
|
91
|
+
return this._reminderDate;
|
92
|
+
}
|
93
|
+
public set reminderDate(value: number | null) {
|
94
|
+
this._reminderDate = value;
|
95
|
+
}
|
96
|
+
|
97
|
+
private _deadlineDate!: number | null;
|
98
|
+
public get deadlineDate(): number | null {
|
99
|
+
return this._deadlineDate;
|
100
|
+
}
|
101
|
+
public set deadlineDate(value: number | null) {
|
102
|
+
this._deadlineDate = value;
|
103
|
+
}
|
104
|
+
|
105
|
+
private _tags!: Tag[] | [];
|
106
|
+
public get tags(): Tag[] | [] {
|
107
|
+
return this._tags;
|
108
|
+
}
|
109
|
+
public set tags(value: Tag[] | []) {
|
110
|
+
this._tags = value;
|
111
|
+
}
|
112
|
+
|
113
|
+
private _subGroupId!: string;
|
114
|
+
public get subGroupId(): string {
|
115
|
+
return this._subGroupId;
|
116
|
+
}
|
117
|
+
public set subGroupId(value: string) {
|
118
|
+
this._subGroupId = value;
|
119
|
+
}
|
120
|
+
|
121
|
+
private cancelActionId!: string;
|
122
|
+
|
123
|
+
// private _taskGroup!: TaskGroup | null;
|
124
|
+
// public get taskGroup(): TaskGroup | null {
|
125
|
+
// return this._taskGroup;
|
126
|
+
// }
|
127
|
+
// public set taskGroup(value: TaskGroup | null) {
|
128
|
+
// this._taskGroup = value;
|
129
|
+
// }
|
130
|
+
|
131
|
+
// private _subTaskGroup!: SubTaskGroup | null;
|
132
|
+
// public get subTaskGroup(): SubTaskGroup | null {
|
133
|
+
// return this._subTaskGroup;
|
134
|
+
// }
|
135
|
+
// public set subTaskGroup(value: SubTaskGroup | null) {
|
136
|
+
// this._subTaskGroup = value;
|
137
|
+
// }
|
138
|
+
|
139
|
+
private _updatedAt!: number | null;
|
140
|
+
public get updatedAt(): number | null {
|
141
|
+
return this._updatedAt;
|
142
|
+
}
|
143
|
+
public set updatedAt(value: number | null) {
|
144
|
+
this._updatedAt = value;
|
145
|
+
}
|
146
|
+
|
147
|
+
private _createdAt!: number | null;
|
148
|
+
public get createdAt(): number | null {
|
149
|
+
return this._createdAt;
|
150
|
+
}
|
151
|
+
public set createdAt(value: number | null) {
|
152
|
+
this._createdAt = value;
|
153
|
+
}
|
154
|
+
|
155
|
+
private _isCompleted!: boolean | false;
|
156
|
+
public get isCompleted(): boolean | false {
|
157
|
+
return this._isCompleted;
|
158
|
+
}
|
159
|
+
public set isCompleted(value: boolean | false) {
|
160
|
+
this._isCompleted = value;
|
161
|
+
}
|
162
|
+
|
163
|
+
private _parentTaskId!: string | "";
|
164
|
+
public get parentTaskId(): string | "" {
|
165
|
+
return this._parentTaskId;
|
166
|
+
}
|
167
|
+
public set parentTaskId(value: string | "") {
|
168
|
+
this._parentTaskId = value;
|
169
|
+
}
|
170
|
+
|
171
|
+
private _order!: number | null;
|
172
|
+
public get order(): number | null {
|
173
|
+
return this._order;
|
174
|
+
}
|
175
|
+
public set order(value: number | null) {
|
176
|
+
this._order = value;
|
177
|
+
}
|
178
|
+
|
179
|
+
private _subTasks!: string[] | [];
|
180
|
+
public get subTasks(): string[] | [] {
|
181
|
+
return this._subTasks;
|
182
|
+
}
|
183
|
+
public set subTasks(value: string[] | []) {
|
184
|
+
this._subTasks = value;
|
185
|
+
}
|
186
|
+
|
187
|
+
private _companyId!: string | "";
|
188
|
+
public get companyId(): string | "" {
|
189
|
+
return this._companyId;
|
190
|
+
}
|
191
|
+
public set companyId(value: string | "") {
|
192
|
+
this._companyId = value;
|
193
|
+
}
|
194
|
+
|
195
|
+
private _actionId!: string | "";
|
196
|
+
public get actionId(): string | "" {
|
197
|
+
return this._actionId;
|
198
|
+
}
|
199
|
+
public set actionId(value: string | "") {
|
200
|
+
this._actionId = value;
|
201
|
+
}
|
202
|
+
|
203
|
+
private _csTaskId!: string | "";
|
204
|
+
public get csTaskId(): string | "" {
|
205
|
+
return this._csTaskId;
|
206
|
+
}
|
207
|
+
public set csTaskId(value: string | "") {
|
208
|
+
this._csTaskId = value;
|
209
|
+
}
|
210
|
+
|
211
|
+
constructor() {}
|
212
|
+
|
213
|
+
argConstructor(
|
214
|
+
id: string | "",
|
215
|
+
taskGroupId: string | "",
|
216
|
+
groupId: string | "",
|
217
|
+
title: string | "",
|
218
|
+
description: string,
|
219
|
+
priority: string,
|
220
|
+
assignee: string[],
|
221
|
+
assets:string[],
|
222
|
+
locations:string[],
|
223
|
+
watchers: string[],
|
224
|
+
reminderDate: number,
|
225
|
+
deadlineDate: number,
|
226
|
+
tags: Tag[],
|
227
|
+
subGroupId: string,
|
228
|
+
updatedAt: number,
|
229
|
+
createdAt: number,
|
230
|
+
isCompleted: boolean,
|
231
|
+
parentTaskId: string,
|
232
|
+
order: number,
|
233
|
+
subtasks: string[],
|
234
|
+
actionId: string,
|
235
|
+
csTaskId: string,
|
236
|
+
cancelActionId: string
|
237
|
+
) {
|
238
|
+
this.id = id;
|
239
|
+
this.assignee = assignee;
|
240
|
+
this.deadlineDate = deadlineDate;
|
241
|
+
this.description = description;
|
242
|
+
this.groupId = groupId;
|
243
|
+
this.order = order;
|
244
|
+
this.assets = assets;
|
245
|
+
this.locations = locations;
|
246
|
+
this.taskGroupId = taskGroupId;
|
247
|
+
this.title = title;
|
248
|
+
this.priority = priority;
|
249
|
+
this.watchers = watchers;
|
250
|
+
this.reminderDate = reminderDate;
|
251
|
+
this.tags = tags;
|
252
|
+
this.subGroupId = subGroupId;
|
253
|
+
this.updatedAt = updatedAt;
|
254
|
+
this.createdAt = createdAt;
|
255
|
+
this.isCompleted = isCompleted;
|
256
|
+
this.parentTaskId = parentTaskId;
|
257
|
+
this.subTasks = subtasks;
|
258
|
+
this.actionId = actionId;
|
259
|
+
this.csTaskId = csTaskId;
|
260
|
+
this.cancelActionId = cancelActionId;
|
261
|
+
}
|
262
|
+
|
263
|
+
fromJSON(task: string) {
|
264
|
+
let taskJSON = JSON.parse(task);
|
265
|
+
this.id = taskJSON["id"] ?? null;
|
266
|
+
this.assignee = taskJSON["assignee"] ?? null;
|
267
|
+
this.assets = taskJSON["assets"] ?? null;
|
268
|
+
this.locations = taskJSON["locations"] ?? null;
|
269
|
+
this.deadlineDate = taskJSON["deadlineDate"] ?? null;
|
270
|
+
this.description = taskJSON["description"] ?? null;
|
271
|
+
this.groupId = taskJSON["groupId"] ?? null;
|
272
|
+
this.order = parseInt(taskJSON["order"]) ?? null;
|
273
|
+
this.taskGroupId = taskJSON["taskGroupId"] ?? null;
|
274
|
+
this.title = taskJSON["title"] ?? null;
|
275
|
+
this.priority = taskJSON["priority"] ?? null;
|
276
|
+
this.watchers = taskJSON["watchers"] ?? null;
|
277
|
+
this.reminderDate = taskJSON["reminderDate"] ?? null;
|
278
|
+
this.subGroupId = taskJSON["subGroupId"] ?? null;
|
279
|
+
this.updatedAt = taskJSON["updatedAt"] ?? null;
|
280
|
+
this.createdAt = taskJSON["createdAt"] ?? null;
|
281
|
+
this.isCompleted = taskJSON["isCompleted"] ?? null;
|
282
|
+
this.parentTaskId = taskJSON["parentTaskId"] ?? null;
|
283
|
+
this.subTasks = taskJSON["subTasks"] ?? [];
|
284
|
+
this.companyId = taskJSON["companyId"] ?? null;
|
285
|
+
this.actionId = taskJSON["actionId"] ?? null;
|
286
|
+
this.csTaskId = taskJSON["csTaskId"];
|
287
|
+
this.cancelActionId = taskJSON["cancelActionId"];
|
288
|
+
if (taskJSON["tags"] != null) {
|
289
|
+
let allTags = taskJSON["tags"];
|
290
|
+
|
291
|
+
let arrayOfTagObjs = [];
|
292
|
+
for (let tag of allTags) {
|
293
|
+
let aTag = new Tag();
|
294
|
+
aTag.fromJSON(JSON.stringify(tag));
|
295
|
+
arrayOfTagObjs.push(aTag);
|
296
|
+
}
|
297
|
+
|
298
|
+
this.tags = arrayOfTagObjs;
|
299
|
+
}
|
300
|
+
}
|
301
|
+
|
302
|
+
toJSON() {
|
303
|
+
let allTagJSON = [];
|
304
|
+
if (this.tags != null && this.tags != undefined) {
|
305
|
+
let allTagObjs = this.tags;
|
306
|
+
for (let tag of allTagObjs) {
|
307
|
+
allTagJSON.push(tag.toJSON());
|
308
|
+
}
|
309
|
+
}
|
310
|
+
return {
|
311
|
+
id: this.id,
|
312
|
+
assignee: this.assignee ?? [],
|
313
|
+
deadlineDate: this.deadlineDate ?? null,
|
314
|
+
description: this.description ?? "",
|
315
|
+
groupId: this.groupId ?? "",
|
316
|
+
order: this.order ?? 0,
|
317
|
+
assets: this.assets ?? null,
|
318
|
+
locations: this.locations ?? null,
|
319
|
+
taskGroupId: this.taskGroupId ?? null,
|
320
|
+
title: this.title ?? null,
|
321
|
+
priority: this.priority ?? null,
|
322
|
+
watchers: this.watchers ?? null,
|
323
|
+
reminderDate: this.reminderDate ?? null,
|
324
|
+
tags: allTagJSON ?? null,
|
325
|
+
subGroupId: this.subGroupId ?? null,
|
326
|
+
updatedAt: this.updatedAt ?? null,
|
327
|
+
createdAt: this.createdAt ?? null,
|
328
|
+
isCompleted: this.isCompleted ?? null,
|
329
|
+
parentTaskId: this.parentTaskId ?? "pt",
|
330
|
+
subTasks: this.subTasks ?? null,
|
331
|
+
companyId: this.companyId ?? null,
|
332
|
+
actionId: this.actionId ?? null,
|
333
|
+
csTaskId: this.csTaskId ?? null,
|
334
|
+
cancelActionId: this.cancelActionId ?? null
|
335
|
+
};
|
336
|
+
}
|
337
|
+
|
338
|
+
async save(firestore: admin.firestore.Firestore) {
|
339
|
+
// Checking if the ID is null
|
340
|
+
if (this.id == null || this.id == "" || this.id == undefined) {
|
341
|
+
return { status: "ERROR", message: "Error Saving Task. ID Not Found" };
|
342
|
+
} else {
|
343
|
+
let taskDoc: admin.firestore.DocumentReference = firestore
|
344
|
+
.collection("Companies")
|
345
|
+
.doc(this.companyId)
|
346
|
+
.collection("Tasks")
|
347
|
+
.doc(this.id);
|
348
|
+
|
349
|
+
console.log("id => " + this.id + "company id => " + this.companyId);
|
350
|
+
|
351
|
+
if (
|
352
|
+
this.parentTaskId != null &&
|
353
|
+
this.parentTaskId != "pt" &&
|
354
|
+
this.parentTaskId != undefined
|
355
|
+
) {
|
356
|
+
let parentTaskDoc: admin.firestore.DocumentReference = firestore
|
357
|
+
.collection("Companies")
|
358
|
+
.doc(this.companyId)
|
359
|
+
.collection("Tasks")
|
360
|
+
.doc(this.parentTaskId);
|
361
|
+
let parentDoc:any = (await parentTaskDoc.get()).data()
|
362
|
+
console.log(
|
363
|
+
"id => " + this.parentTaskId + "company id => " + this.companyId + "parentTaksDoc =>"+ {...parentDoc}
|
364
|
+
);
|
365
|
+
|
366
|
+
try {
|
367
|
+
parentDoc.subTasks.push(this.id)
|
368
|
+
await parentTaskDoc.update({
|
369
|
+
subTasks: parentDoc.subTasks,
|
370
|
+
});
|
371
|
+
} catch (e) {
|
372
|
+
console.log("Error in task", e);
|
373
|
+
}
|
374
|
+
}
|
375
|
+
|
376
|
+
try {
|
377
|
+
await taskDoc.set(this.toJSON());
|
378
|
+
} catch (e) {
|
379
|
+
console.log("Error in task", e);
|
380
|
+
}
|
381
|
+
|
382
|
+
return {
|
383
|
+
status: "OK",
|
384
|
+
id:taskDoc.id,
|
385
|
+
message: "Task Added Successfully",
|
386
|
+
};
|
387
|
+
}
|
388
|
+
}
|
389
|
+
|
390
|
+
static async markTaskAsCompleted(
|
391
|
+
firestore: admin.firestore.Firestore,
|
392
|
+
companyId: string,
|
393
|
+
taskId: string
|
394
|
+
) {
|
395
|
+
try {
|
396
|
+
|
397
|
+
console.log("TaskId", taskId);
|
398
|
+
const taskDocs = await firestore
|
399
|
+
.collection("Companies")
|
400
|
+
.doc(companyId)
|
401
|
+
.collection("Tasks")
|
402
|
+
.where("id", "==", `${taskId}`)
|
403
|
+
.get();
|
404
|
+
console.log("here---------------");
|
405
|
+
const taskDoc = taskDocs.docs[0];
|
406
|
+
const updationRes = await taskDoc.ref.update({
|
407
|
+
isCompleted: true,
|
408
|
+
});
|
409
|
+
return updationRes;
|
410
|
+
} catch(error) {
|
411
|
+
throw new Error("Something Went wrong while updating");
|
412
|
+
}
|
413
|
+
}
|
414
|
+
|
415
|
+
static async checkIsParentTaskCompleted(firestore: admin.firestore.Firestore,
|
416
|
+
companyId: string,
|
417
|
+
taskId: string
|
418
|
+
) {
|
419
|
+
try {
|
420
|
+
const taskDocs = await firestore.collection("Companies")
|
421
|
+
.doc(companyId)
|
422
|
+
.collection("Tasks")
|
423
|
+
.where("id", "==", taskId)
|
424
|
+
.get();
|
425
|
+
if (taskDocs.docs.length) {
|
426
|
+
const taskInfo = taskDocs.docs[0].data();
|
427
|
+
const parentTaskId = taskInfo.parentTaskId;
|
428
|
+
if (parentTaskId) {
|
429
|
+
const parentTaskList = await firestore.collection("Companies")
|
430
|
+
.doc(companyId)
|
431
|
+
.collection("Tasks")
|
432
|
+
.where("id", "==", parentTaskId)
|
433
|
+
.get();
|
434
|
+
if (parentTaskList.docs.length) {
|
435
|
+
const parentTaskInfo = parentTaskList.docs[0].data();
|
436
|
+
const subTasksIdList = parentTaskInfo.subTasks;
|
437
|
+
const subTasksList = await firestore.collection("Companies")
|
438
|
+
.doc(companyId)
|
439
|
+
.collection("Tasks")
|
440
|
+
.where("id", "in", subTasksIdList)
|
441
|
+
.get();
|
442
|
+
const parentTaskStatus = subTasksList.docs.every((subTaskDoc) => {
|
443
|
+
const subTaskInfo = subTaskDoc.data();
|
444
|
+
return subTaskInfo.isCompleted
|
445
|
+
})
|
446
|
+
return {
|
447
|
+
status: parentTaskStatus,
|
448
|
+
parentTaskId: parentTaskId
|
449
|
+
}
|
450
|
+
} else {
|
451
|
+
return {
|
452
|
+
parentTaskId: parentTaskId,
|
453
|
+
status: null
|
454
|
+
}
|
455
|
+
}
|
456
|
+
} else {
|
457
|
+
return {
|
458
|
+
parentTaskId: null,
|
459
|
+
status: null
|
460
|
+
}
|
461
|
+
}
|
462
|
+
} else {
|
463
|
+
return null;
|
464
|
+
}
|
465
|
+
} catch(error: any) {
|
466
|
+
console.log(error.message);
|
467
|
+
throw {
|
468
|
+
message: error.message
|
469
|
+
}
|
470
|
+
}
|
471
|
+
}
|
472
|
+
|
473
|
+
static async createTaskAction(
|
474
|
+
firestore: admin.firestore.Firestore,
|
475
|
+
body: any
|
476
|
+
) {
|
477
|
+
try {
|
478
|
+
const nickname = "child_safety";
|
479
|
+
const companyId = await Company.getCompanyIdByNickName(firestore, nickname);
|
480
|
+
console.log(companyId);
|
481
|
+
console.log("-----------------", body.inputsList);
|
482
|
+
let inputTypes = body.inputsList;
|
483
|
+
let docId: string;
|
484
|
+
let newDoc;
|
485
|
+
if (inputTypes) {
|
486
|
+
docId = inputTypes.join("_");
|
487
|
+
} else {
|
488
|
+
throw {
|
489
|
+
message: "Please Provide inputs list",
|
490
|
+
status: 400
|
491
|
+
}
|
492
|
+
}
|
493
|
+
inputTypes = [
|
494
|
+
"select_location",
|
495
|
+
"select_asset",
|
496
|
+
...body.inputsList,
|
497
|
+
"summary",
|
498
|
+
];
|
499
|
+
const taskActionsDoc = await firestore
|
500
|
+
.collection("Companies")
|
501
|
+
.doc(companyId)
|
502
|
+
.collection("TaskActions")
|
503
|
+
.doc(docId)
|
504
|
+
.get();
|
505
|
+
const actionId = await Action.getActionId(
|
506
|
+
firestore,
|
507
|
+
companyId,
|
508
|
+
"completeTask"
|
509
|
+
);
|
510
|
+
if (taskActionsDoc.exists) {
|
511
|
+
return {
|
512
|
+
status: 200,
|
513
|
+
taskActions: docId,
|
514
|
+
message: "Successfully fetched taskActions",
|
515
|
+
};
|
516
|
+
} else {
|
517
|
+
newDoc = firestore
|
518
|
+
.collection("Companies")
|
519
|
+
.doc(companyId)
|
520
|
+
.collection("TaskActions")
|
521
|
+
.doc(docId);
|
522
|
+
const taskActionDoc = await firestore
|
523
|
+
.collection("Companies")
|
524
|
+
.doc(companyId)
|
525
|
+
.collection("Actions")
|
526
|
+
.doc(actionId)
|
527
|
+
.get();
|
528
|
+
const newAction: any = taskActionDoc.data();
|
529
|
+
newAction.id = newDoc.id;
|
530
|
+
newAction.name = docId;
|
531
|
+
console.log(newAction);
|
532
|
+
await newDoc.set(newAction);
|
533
|
+
console.log("newDocId", newDoc.id);
|
534
|
+
}
|
535
|
+
const feedDetailScreen = this.defFeedObj();
|
536
|
+
feedDetailScreen.screen_title = "Task Details"
|
537
|
+
await Promise.all(
|
538
|
+
inputTypes.map(async (inputType: string, idx: number) => {
|
539
|
+
console.log("actionId", actionId);
|
540
|
+
console.log("inputType", inputType);
|
541
|
+
const taskStep = await firestore
|
542
|
+
.collection("Companies")
|
543
|
+
.doc(companyId)
|
544
|
+
.collection("Actions")
|
545
|
+
.doc(actionId)
|
546
|
+
.collection("task_completion_steps")
|
547
|
+
.where("step_selector_key", "==", inputType)
|
548
|
+
.get();
|
549
|
+
// console.log("teskStepdata", taskStep);
|
550
|
+
if (taskStep.empty) {
|
551
|
+
throw "Invalid input type received.";
|
552
|
+
} else {
|
553
|
+
const doc = await firestore
|
554
|
+
.collection("Companies")
|
555
|
+
.doc(companyId)
|
556
|
+
.collection("TaskActions")
|
557
|
+
.doc(docId)
|
558
|
+
.get();
|
559
|
+
const newStep = taskStep.docs[0].data();
|
560
|
+
newStep.order = idx;
|
561
|
+
console.log("newStep =>", newStep);
|
562
|
+
if (newStep.step_selector_key != "summary") {
|
563
|
+
feedDetailScreen.data[0]["children"].push({
|
564
|
+
type: this.type(newStep.fieldType),
|
565
|
+
title: newStep.label,
|
566
|
+
isMultiText:(newStep.fieldType ==='InputField' && !!newStep.field.isMultiInput)||newStep.fieldType ==='CheckList',
|
567
|
+
key: newStep.field["keyForAPI"],
|
568
|
+
});
|
569
|
+
}
|
570
|
+
const newDocRef = doc.ref.collection("task_completion_steps").doc();
|
571
|
+
newStep.id = newDocRef.id;
|
572
|
+
await newDocRef.set(newStep);
|
573
|
+
// await newDoc.set(taskStep.docs[0].data());
|
574
|
+
}
|
575
|
+
})
|
576
|
+
);
|
577
|
+
feedDetailScreen.actionName = docId;
|
578
|
+
console.log(JSON.stringify(feedDetailScreen));
|
579
|
+
const fdsRef = firestore.collection("Companies")
|
580
|
+
.doc(companyId)
|
581
|
+
.collection("Feed-Details-Screen")
|
582
|
+
.doc();
|
583
|
+
feedDetailScreen.id = fdsRef.id;
|
584
|
+
console.log(feedDetailScreen);
|
585
|
+
await fdsRef.set(feedDetailScreen);
|
586
|
+
return {
|
587
|
+
status: 200,
|
588
|
+
taskActions: docId,
|
589
|
+
message: "Successfully created the taskAction"
|
590
|
+
}
|
591
|
+
} catch(error: any) {
|
592
|
+
return {
|
593
|
+
status: error?.status ?? 500,
|
594
|
+
error: error?.message ?? "Internal Server Error"
|
595
|
+
}
|
596
|
+
}
|
597
|
+
}
|
598
|
+
|
599
|
+
static defFeedObj() {
|
600
|
+
const children: any[] = [];
|
601
|
+
return {
|
602
|
+
"screen_title": "",
|
603
|
+
"id": "",
|
604
|
+
"cancelActionId": "",
|
605
|
+
"data": [
|
606
|
+
{
|
607
|
+
"children": children,
|
608
|
+
"height": "",
|
609
|
+
"order": 0
|
610
|
+
}
|
611
|
+
],
|
612
|
+
"actionName": "worklog"
|
613
|
+
}
|
614
|
+
}
|
615
|
+
static type(fieldType:string):string{
|
616
|
+
console.log(fieldType)
|
617
|
+
if(fieldType ==='InputField' || fieldType === 'CheckList' || fieldType === 'RadioList') return 'text'
|
618
|
+
if(fieldType === 'datePicker') return 'date '
|
619
|
+
if(fieldType === 'timePicker') return 'time '
|
620
|
+
if(fieldType === 'ImagePicker' || fieldType === 'Selfie') return 'image'
|
621
|
+
if(fieldType === 'MultiImagePicker') return 'multiImage'
|
622
|
+
return "text"
|
623
|
+
}
|
624
|
+
static async addUpdateTask(
|
625
|
+
firestore: admin.firestore.Firestore,
|
626
|
+
body: any
|
627
|
+
) {
|
628
|
+
try {
|
629
|
+
let taskModel = body["extra"];
|
630
|
+
console.log("The Task Model is ", taskModel);
|
631
|
+
console.log("--------taskModel-------", taskModel);
|
632
|
+
|
633
|
+
let newTask: Task = new Task();
|
634
|
+
try {
|
635
|
+
newTask.fromJSON(JSON.stringify(taskModel)); // id == ""
|
636
|
+
} catch (e) {
|
637
|
+
console.log("Error running newTask.fromJSON()", e);
|
638
|
+
throw {
|
639
|
+
message: "Error running newTask.fromJSON()",
|
640
|
+
status: 500
|
641
|
+
}
|
642
|
+
}
|
643
|
+
console.log("the newTask is ", newTask.toJSON());
|
644
|
+
|
645
|
+
let response;
|
646
|
+
try {
|
647
|
+
console.log(
|
648
|
+
"newTask.id => ",
|
649
|
+
newTask.id,
|
650
|
+
"newTask.companyId => ",
|
651
|
+
newTask.companyId
|
652
|
+
);
|
653
|
+
response = await newTask.save(firestore);
|
654
|
+
} catch (e) {
|
655
|
+
console.log("ERROR saving task ", e);
|
656
|
+
throw {
|
657
|
+
message: "ERROR saving task"
|
658
|
+
}
|
659
|
+
}
|
660
|
+
// Delete Incoming Ref
|
661
|
+
if (body["id"] != "") {
|
662
|
+
if (response?.["status"] == "OK") {
|
663
|
+
await firestore
|
664
|
+
.collection("Incoming")
|
665
|
+
.doc(body["id"])
|
666
|
+
.delete();
|
667
|
+
}
|
668
|
+
}
|
669
|
+
return {
|
670
|
+
...response
|
671
|
+
}
|
672
|
+
} catch(error: any) {
|
673
|
+
return {
|
674
|
+
error: error?.message ?? "Internal Server Error",
|
675
|
+
status: error?.status ?? 500
|
676
|
+
}
|
677
|
+
}
|
678
|
+
}
|
679
|
+
}
|
680
|
+
|
681
|
+
export { Task };
|