my-typescript-library-rahul52us 1.3.4 → 1.3.6

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 (214) hide show
  1. package/dist/config/auth/passportConfig.js +1 -0
  2. package/dist/config/auth/passportConfig.js.map +1 -1
  3. package/dist/controllers/auth.controller.js.map +1 -1
  4. package/dist/controllers/license/license.controller.js +1 -1
  5. package/dist/controllers/license/license.controller.js.map +1 -1
  6. package/dist/controllers/rbac/rbac.controller.js +1 -5
  7. package/dist/controllers/rbac/rbac.controller.js.map +1 -1
  8. package/dist/repository/document.repository.js +174 -22
  9. package/dist/repository/document.repository.js.map +1 -1
  10. package/dist/repository/filesystem.repository.js +3 -3
  11. package/dist/repository/filesystem.repository.js.map +1 -1
  12. package/dist/repository/log.repository.js.map +1 -1
  13. package/dist/repository/notifications.repository.js.map +1 -1
  14. package/dist/repository/organisation.repository.js.map +1 -1
  15. package/dist/repository/schemas/accountdetails.schema.js.map +1 -1
  16. package/dist/repository/schemas/accounts.schema.js +10 -33
  17. package/dist/repository/schemas/accounts.schema.js.map +1 -1
  18. package/dist/repository/schemas/document.schema.js +12 -19
  19. package/dist/repository/schemas/document.schema.js.map +1 -1
  20. package/dist/repository/schemas/extracted.schema.js +3 -5
  21. package/dist/repository/schemas/extracted.schema.js.map +1 -1
  22. package/dist/repository/schemas/fileSystem.schema.js +2 -5
  23. package/dist/repository/schemas/fileSystem.schema.js.map +1 -1
  24. package/dist/repository/schemas/form.schema.js +1 -1
  25. package/dist/repository/schemas/form.schema.js.map +1 -1
  26. package/dist/repository/schemas/log.schema.js +4 -4
  27. package/dist/repository/schemas/log.schema.js.map +1 -1
  28. package/dist/repository/schemas/notifications.schema.js +2 -3
  29. package/dist/repository/schemas/notifications.schema.js.map +1 -1
  30. package/dist/repository/schemas/organisation.schema.js +25 -29
  31. package/dist/repository/schemas/organisation.schema.js.map +1 -1
  32. package/dist/repository/schemas/profile.schema.js +1 -1
  33. package/dist/repository/schemas/profile.schema.js.map +1 -1
  34. package/dist/repository/schemas/role.schema.js +1 -1
  35. package/dist/repository/schemas/role.schema.js.map +1 -1
  36. package/dist/repository/schemas/tokens.schema.js +5 -5
  37. package/dist/repository/schemas/tokens.schema.js.map +1 -1
  38. package/dist/repository/schemas/userrole.schema.js +1 -1
  39. package/dist/repository/schemas/userrole.schema.js.map +1 -1
  40. package/dist/repository/schemas/workflow.schema.js +14 -40
  41. package/dist/repository/schemas/workflow.schema.js.map +1 -1
  42. package/dist/repository/user.repository.js +32 -20
  43. package/dist/repository/user.repository.js.map +1 -1
  44. package/dist/repository/user_tokens.repository.js.map +1 -1
  45. package/dist/repository/userrole.repository.js +1 -1
  46. package/dist/repository/userrole.repository.js.map +1 -1
  47. package/dist/repository/workflow.repository.js +0 -1
  48. package/dist/repository/workflow.repository.js.map +1 -1
  49. package/dist/routes/auth.route.js +6 -5
  50. package/dist/routes/auth.route.js.map +1 -1
  51. package/dist/routes/document.route.js +2 -0
  52. package/dist/routes/document.route.js.map +1 -1
  53. package/dist/routes/fileSystem.route.js +1 -0
  54. package/dist/routes/fileSystem.route.js.map +1 -1
  55. package/dist/routes/form.route.js +1 -1
  56. package/dist/routes/form.route.js.map +1 -1
  57. package/dist/routes/index.js +1 -1
  58. package/dist/routes/index.js.map +1 -1
  59. package/dist/routes/log.route.js +1 -1
  60. package/dist/routes/log.route.js.map +1 -1
  61. package/dist/routes/notifications.route.js +1 -1
  62. package/dist/routes/notifications.route.js.map +1 -1
  63. package/dist/routes/profile.route.js +4 -3
  64. package/dist/routes/profile.route.js.map +1 -1
  65. package/dist/routes/role.route.js +7 -4
  66. package/dist/routes/role.route.js.map +1 -1
  67. package/dist/routes/user.route.js +10 -8
  68. package/dist/routes/user.route.js.map +1 -1
  69. package/dist/routes/userrole.route.js +6 -4
  70. package/dist/routes/userrole.route.js.map +1 -1
  71. package/dist/routes/workflow.route.js.map +1 -1
  72. package/dist/server.js +1 -3
  73. package/dist/server.js.map +1 -1
  74. package/dist/services/apikey/apikey.service.js +102 -0
  75. package/dist/services/apikey/apikey.service.js.map +1 -0
  76. package/dist/services/authentication/change-password.service.js +1 -1
  77. package/dist/services/authentication/change-password.service.js.map +1 -1
  78. package/dist/services/authentication/forgot-password.service.js.map +1 -1
  79. package/dist/services/authentication/login.service.js.map +1 -1
  80. package/dist/services/authentication/register.service.js.map +1 -1
  81. package/dist/services/authentication/resend-email.service.js.map +1 -1
  82. package/dist/services/authentication/reset-password.service.js +25 -7
  83. package/dist/services/authentication/reset-password.service.js.map +1 -1
  84. package/dist/services/authentication/verify-email.service.js.map +1 -1
  85. package/dist/services/document/document.services.js +172 -89
  86. package/dist/services/document/document.services.js.map +1 -1
  87. package/dist/services/document/dummy.js +85 -0
  88. package/dist/services/document/dummy.js.map +1 -0
  89. package/dist/services/fileSystem/fileSystem.service.js.map +1 -1
  90. package/dist/services/logs/vendorLog.service.js +1 -1
  91. package/dist/services/logs/vendorLog.service.js.map +1 -1
  92. package/dist/services/notifications/notifications.service.js.map +1 -1
  93. package/dist/services/organisation/organisation.service.js.map +1 -1
  94. package/dist/services/profile/profile.services.js.map +1 -1
  95. package/dist/services/userroles/userrole.service.js.map +1 -1
  96. package/dist/services/workflow/workflow.service.js +2 -0
  97. package/dist/services/workflow/workflow.service.js.map +1 -1
  98. package/dist/types/controllers/auth.controller.d.ts +3 -3
  99. package/dist/types/repository/document.repository.d.ts +56 -16
  100. package/dist/types/repository/form.repository.d.ts +7 -3
  101. package/dist/types/repository/organisation.repository.d.ts +1 -6
  102. package/dist/types/repository/profile.repository.d.ts +4 -3
  103. package/dist/types/repository/role.repository.d.ts +5 -2
  104. package/dist/types/repository/schemas/accounts.schema.d.ts +14 -11
  105. package/dist/types/repository/schemas/document.schema.d.ts +4 -4
  106. package/dist/types/repository/schemas/extracted.schema.d.ts +3 -3
  107. package/dist/types/repository/schemas/fileSystem.schema.d.ts +2 -6
  108. package/dist/types/repository/schemas/form.schema.d.ts +1 -1
  109. package/dist/types/repository/schemas/organisation.schema.d.ts +11 -11
  110. package/dist/types/repository/schemas/profile.schema.d.ts +1 -1
  111. package/dist/types/repository/schemas/role.schema.d.ts +1 -1
  112. package/dist/types/repository/schemas/userrole.schema.d.ts +1 -1
  113. package/dist/types/repository/schemas/workflow.schema.d.ts +2 -14
  114. package/dist/types/repository/user.repository.d.ts +45 -16
  115. package/dist/types/repository/userrole.repository.d.ts +5 -2
  116. package/dist/types/repository/workflow.repository.d.ts +4 -38
  117. package/dist/types/server.d.ts +0 -1
  118. package/dist/types/services/apikey/apikey.service.d.ts +12 -0
  119. package/dist/types/services/authentication/change-password.service.d.ts +1 -1
  120. package/dist/types/services/authentication/forgot-password.service.d.ts +2 -2
  121. package/dist/types/services/authentication/getuser.service.d.ts +29 -3
  122. package/dist/types/services/authentication/login.service.d.ts +1 -1
  123. package/dist/types/services/authentication/register.admin.service.d.ts +1 -1
  124. package/dist/types/services/authentication/register.service.d.ts +1 -1
  125. package/dist/types/services/authentication/resend-email.service.d.ts +2 -2
  126. package/dist/types/services/authentication/reset-password.service.d.ts +2 -2
  127. package/dist/types/services/authentication/verify-email.service.d.ts +1 -1
  128. package/dist/types/services/document/document.services.d.ts +42 -12
  129. package/dist/types/services/document/dummy.d.ts +45 -0
  130. package/dist/types/services/logs/log.service.d.ts +1 -1
  131. package/dist/types/services/profile/profile.services.d.ts +3 -3
  132. package/dist/types/services/roles/role.services.d.ts +33 -5
  133. package/dist/types/services/userroles/userrole.service.d.ts +5 -13
  134. package/dist/types/services/workflow/workflow.service.d.ts +2 -2
  135. package/dist/types/utils/common.d.ts +5 -0
  136. package/dist/utils/common.js +23 -1
  137. package/dist/utils/common.js.map +1 -1
  138. package/dist/utils/log.service.js +1 -1
  139. package/dist/utils/log.service.js.map +1 -1
  140. package/package.json +1 -1
  141. package/src/config/auth/passportConfig.ts +3 -0
  142. package/src/controllers/auth.controller.ts +2 -2
  143. package/src/controllers/license/license.controller.ts +1 -1
  144. package/src/controllers/rbac/rbac.controller.ts +1 -2
  145. package/src/repository/document.repository.ts +221 -37
  146. package/src/repository/filesystem.repository.ts +4 -4
  147. package/src/repository/form.repository.ts +4 -4
  148. package/src/repository/log.repository.ts +1 -1
  149. package/src/repository/notifications.repository.ts +1 -3
  150. package/src/repository/organisation.repository.ts +1 -2
  151. package/src/repository/profile.repository.ts +1 -1
  152. package/src/repository/role.repository.ts +1 -1
  153. package/src/repository/schemas/WorkflowSettingsScheme.ts +0 -2
  154. package/src/repository/schemas/accountdetails.schema.ts +2 -5
  155. package/src/repository/schemas/accounts.schema.ts +30 -31
  156. package/src/repository/schemas/document.schema.ts +15 -18
  157. package/src/repository/schemas/extracted.schema.ts +28 -31
  158. package/src/repository/schemas/fileSystem.schema.ts +4 -7
  159. package/src/repository/schemas/form.schema.ts +1 -2
  160. package/src/repository/schemas/log.schema.ts +6 -7
  161. package/src/repository/schemas/notifications.schema.ts +2 -4
  162. package/src/repository/schemas/organisation.schema.ts +44 -51
  163. package/src/repository/schemas/profile.schema.ts +1 -2
  164. package/src/repository/schemas/role.schema.ts +1 -2
  165. package/src/repository/schemas/tokens.schema.ts +18 -20
  166. package/src/repository/schemas/userrole.schema.ts +1 -2
  167. package/src/repository/schemas/workflow.schema.ts +41 -61
  168. package/src/repository/user.repository.ts +74 -56
  169. package/src/repository/user_tokens.repository.ts +1 -1
  170. package/src/repository/userrole.repository.ts +3 -3
  171. package/src/repository/workflow.repository.ts +4 -5
  172. package/src/routes/auth.route.ts +6 -5
  173. package/src/routes/document.route.ts +5 -1
  174. package/src/routes/fileSystem.route.ts +2 -0
  175. package/src/routes/form.route.ts +6 -1
  176. package/src/routes/index.ts +2 -1
  177. package/src/routes/log.route.ts +2 -4
  178. package/src/routes/notifications.route.ts +2 -2
  179. package/src/routes/org.route.ts +1 -1
  180. package/src/routes/profile.route.ts +4 -3
  181. package/src/routes/role.route.ts +7 -4
  182. package/src/routes/user.route.ts +29 -7
  183. package/src/routes/userrole.route.ts +6 -4
  184. package/src/routes/workflow.route.ts +10 -2
  185. package/src/server.ts +0 -1
  186. package/src/services/authentication/change-password.service.ts +3 -7
  187. package/src/services/authentication/forgot-password.service.ts +2 -2
  188. package/src/services/authentication/login.service.ts +1 -1
  189. package/src/services/authentication/register.admin.service.ts +1 -1
  190. package/src/services/authentication/register.service.ts +0 -2
  191. package/src/services/authentication/resend-email.service.ts +2 -3
  192. package/src/services/authentication/reset-password.service.ts +33 -12
  193. package/src/services/authentication/verify-email.service.ts +1 -1
  194. package/src/services/document/document.services.ts +216 -119
  195. package/src/services/document/dummy.ts +81 -0
  196. package/src/services/fileSystem/fileSystem.service.ts +3 -3
  197. package/src/services/logs/log.service.ts +1 -1
  198. package/src/services/logs/vendorLog.service.ts +1 -1
  199. package/src/services/notifications/notifications.service.ts +8 -9
  200. package/src/services/organisation/organisation.service.ts +5 -7
  201. package/src/services/profile/profile.services.ts +4 -7
  202. package/src/services/roles/role.services.ts +4 -4
  203. package/src/services/statement/accountdetails.service.ts +1 -1
  204. package/src/services/userroles/userrole.service.ts +5 -6
  205. package/src/services/workflow/workSettings.service.ts +1 -1
  206. package/src/services/workflow/workflow.service.ts +11 -5
  207. package/src/utils/common.ts +36 -13
  208. package/src/utils/log.service.ts +1 -1
  209. package/.vscode/extensions.json +0 -5
  210. package/dist/controllers/rbac/grantaccess.json +0 -72
  211. package/dist/setupModal.js +0 -58
  212. package/dist/setupModal.js.map +0 -1
  213. package/dist/types/setupModal.d.ts +0 -7
  214. package/src/setupModal.ts +0 -60
@@ -11,11 +11,13 @@ import {
11
11
  getDocumentCountByLevelAndStatus,
12
12
  getPendingApproval,
13
13
  getPendingDash,
14
+ saveAsDraftDocument,
14
15
  updateAlternativeDocument,
15
16
  updateComment,
16
17
  updateDocument,
17
18
  updateFile,
18
19
  updateStatus,
20
+ uploadAddtionalDocuments,
19
21
  } from "../../repository/document.repository";
20
22
  import { NextFunction, Request, Response } from "express";
21
23
  import { uploadFile } from "../../repository/filesystem.repository";
@@ -29,6 +31,8 @@ import sendMail from "../../libs/mail";
29
31
  import mongoose from "mongoose";
30
32
  import {
31
33
  findTriggerValues,
34
+ getDomain,
35
+ getUserDetails,
32
36
  handleSendTrigger,
33
37
  sendTriggerRequest,
34
38
  } from "../../utils/common";
@@ -45,7 +49,7 @@ interface UserRequest extends Request {
45
49
  };
46
50
  }
47
51
 
48
- export async function getCountService(req: UserRequest, res: Response): Promise<any> {
52
+ export async function getCountService(req: UserRequest, res: Response) {
49
53
  try {
50
54
  let { level, _id } = req.user;
51
55
  let exchangeType = (req.query.exchangeType as string) || null;
@@ -57,26 +61,25 @@ export async function getCountService(req: UserRequest, res: Response): Promise<
57
61
  }
58
62
  }
59
63
 
60
- export async function findOneAndDeleteDocument(req : any, res : any): Promise<any> {
61
- try
62
- {
64
+ export async function findOneAndDeleteDocument(req: any, res: any) {
65
+ try {
63
66
  await findOneByDocumentIdAndDelete({
64
67
  documentId: req.body?.documentId,
65
68
  });
66
69
  res.status(200).send({
67
- status : 'success',
68
- data : 'Document has been successfully'
70
+ status: 'success',
71
+ data: 'Document has been successfully'
69
72
  })
70
73
  }
71
- catch(err : any){
74
+ catch (err: any) {
72
75
  res.status(500).send({
73
- status : 'error',
74
- data : err?.message
76
+ status: 'error',
77
+ data: err?.message
75
78
  })
76
79
  }
77
80
  }
78
81
 
79
- export async function createPendingApprovalFunction(req: any) : Promise<any> {
82
+ export async function createPendingApprovalFunction(req: any) {
80
83
  try {
81
84
  if (req.body.documentId) {
82
85
  await findOneByDocumentIdAndDelete({
@@ -84,10 +87,12 @@ export async function createPendingApprovalFunction(req: any) : Promise<any> {
84
87
  });
85
88
  }
86
89
 
87
- let { values, file, tags, type, approval, partnerName, partnerId, order_taken_by } = req.body;
90
+ let { values, file, tags, type, approval } = req.body;
88
91
  const userID = req.user?._id;
92
+ const isguaranteed = req?.body?.fields?.Threshold_Value_Check === "True" ? true : false
89
93
  const company = req.user.company;
90
94
  const workflowId = req.body.activeWorkflow || req.user.defaultWorkflow;
95
+
91
96
  const { status, data } = await getSingleWorkFlowService(
92
97
  req,
93
98
  req.body.activeWorkflow || req.user.defaultWorkflow
@@ -120,11 +125,12 @@ export async function createPendingApprovalFunction(req: any) : Promise<any> {
120
125
  name: approval.name || req.user?.username,
121
126
  level: approval.level,
122
127
  userId: userID,
128
+ createdAt : new Date()
123
129
  },
124
130
  ],
125
131
  helpInfo: req.body.helpInfo || {},
126
132
  };
127
- } else if (type === "schema") {
133
+ } else if (type === "schema" || type === "signature_verification") {
128
134
  values = {
129
135
  user: userID,
130
136
  company: company,
@@ -153,14 +159,18 @@ export async function createPendingApprovalFunction(req: any) : Promise<any> {
153
159
  values = { ...values, file: uploadedFile.fileId };
154
160
  }
155
161
  } else {
156
- const uploadedFile: any = await uploadFile(
157
- file.file,
158
- file.name,
159
- file.type
160
- );
162
+ let uploadedFile : any = null
163
+ if(file){
164
+ uploadedFile = await uploadFile(
165
+ file.file,
166
+ file.name,
167
+ file.type
168
+ );
169
+ }
170
+
161
171
  let files: any = [];
162
172
 
163
- if (Array.isArray(data?.values?.table)) {
173
+ if (Array.isArray(data.values.table)) {
164
174
  let filterTable = data.values.table.filter(
165
175
  (item: any) => item.isActive === true
166
176
  );
@@ -176,13 +186,15 @@ export async function createPendingApprovalFunction(req: any) : Promise<any> {
176
186
  // Check if it's a file and if the key exists in 'values'
177
187
  if (isFile && values.hasOwnProperty(key)) {
178
188
  const fileData = values[key];
179
- try {
189
+ if(fileData){
180
190
  const uploadFiles: any = await uploadFile(
181
191
  fileData.file,
182
192
  fileData.name,
183
193
  fileData.type
184
194
  );
185
195
  output.push({ [key]: uploadFiles.fileId });
196
+ }
197
+ try {
186
198
  } catch (error) {
187
199
  console.log(error.message);
188
200
  }
@@ -197,13 +209,10 @@ export async function createPendingApprovalFunction(req: any) : Promise<any> {
197
209
  }
198
210
  }
199
211
  }
200
-
201
212
  values = {
202
213
  user: userID,
203
214
  company: company,
204
- partnerName : partnerName,
205
- partnerId : partnerId,
206
- order_taken_by:order_taken_by,
215
+ isguaranteed:isguaranteed,
207
216
  workflow: req.body.activeWorkflow || req.user.defaultWorkflow,
208
217
  values: {
209
218
  level: req.user.level,
@@ -212,23 +221,23 @@ export async function createPendingApprovalFunction(req: any) : Promise<any> {
212
221
  updated_At: new Date(),
213
222
  },
214
223
  originalValues: values,
215
- file: uploadedFile.fileId,
224
+ file: uploadedFile?.fileId || undefined,
216
225
  additionalFiles: output,
217
226
  tags: tags,
218
227
  approval:
219
228
  approval?.length > 0
220
229
  ? [
221
- {
222
- comment: approval[0].comment,
223
- type: approval[0].type,
224
- status: approval[0].status,
225
- name: approval[0].name || req.user?.username,
226
- level: approval[0].level,
227
- userId: userID,
228
- fileId: uploadedFile.fileId,
229
- createdAt: new Date(),
230
- },
231
- ]
230
+ {
231
+ comment: approval[0].comment,
232
+ type: approval[0].type,
233
+ status: approval[0].status,
234
+ name: approval[0].name || req.user?.username,
235
+ level: approval[0].level,
236
+ userId: userID,
237
+ fileId: uploadedFile?.fileId || undefined,
238
+ createdAt: new Date(),
239
+ },
240
+ ]
232
241
  : [],
233
242
  helpInfo: req.body.helpInfo || {},
234
243
  };
@@ -261,32 +270,25 @@ export async function createPendingApprovalFunction(req: any) : Promise<any> {
261
270
  if (req.body.status === "approved") {
262
271
  // console.log("this is an approved state");
263
272
 
264
- message = `${
265
- req.user?.username?.charAt(0)?.toUpperCase() +
273
+ message = `${req.user?.username?.charAt(0)?.toUpperCase() +
266
274
  req.user?.username?.slice(1)?.toLowerCase()
267
- } has ${
268
- req.body.status
269
- } the document and sent it for the approval in the next level process of the document.${
270
- commentText ? ` Added Comments: "${req.body.comment}"` : ""
271
- }`;
275
+ } has ${req.body.status
276
+ } the document and sent it for the approval in the next level process of the document.${commentText ? ` Added Comments: "${req.body.comment}"` : ""
277
+ }`;
272
278
  }
273
279
 
274
280
  if (req.body.status === "pending") {
275
- message = `${
276
- req.user?.username?.charAt(0)?.toUpperCase() +
281
+ message = `${req.user?.username?.charAt(0)?.toUpperCase() +
277
282
  req.user?.username?.slice(1)?.toLowerCase()
278
- } hasn't approved the document. The document status is ${
279
- req.body.status
280
- }.${commentText ? ` Added Comments: "${req.body.comment}"` : ""}`;
283
+ } hasn't approved the document. The document status is ${req.body.status
284
+ }.${commentText ? ` Added Comments: "${req.body.comment}"` : ""}`;
281
285
  }
282
286
 
283
287
  if (req.body.status === "rejected") {
284
- message = `${
285
- req.user?.username?.charAt(0)?.toUpperCase() +
288
+ message = `${req.user?.username?.charAt(0)?.toUpperCase() +
286
289
  req.user?.username?.slice(1)?.toLowerCase()
287
- } hasn't approved the document. The document status is ${
288
- req.body.status
289
- }.${commentText ? ` Added Comments: "${req.body.comment}"` : ""}`;
290
+ } hasn't approved the document. The document status is ${req.body.status
291
+ }.${commentText ? ` Added Comments: "${req.body.comment}"` : ""}`;
290
292
  }
291
293
 
292
294
  const datas = {
@@ -294,7 +296,7 @@ export async function createPendingApprovalFunction(req: any) : Promise<any> {
294
296
  message: message,
295
297
  documentId: createdDocument?._id,
296
298
  type: req.body.type,
297
- workflow: workflowId,
299
+ workflow: workflowId
298
300
  };
299
301
 
300
302
  const notificationsPromises = currentUser.map(
@@ -446,6 +448,7 @@ export async function createPendingApprovalFunction(req: any) : Promise<any> {
446
448
  }
447
449
  }
448
450
 
451
+
449
452
  return {
450
453
  status: "success",
451
454
  message: "Document Created successfully",
@@ -453,6 +456,8 @@ export async function createPendingApprovalFunction(req: any) : Promise<any> {
453
456
  data: {
454
457
  documentId: createdDocument.documentId,
455
458
  workflowId: createdDocument.workflow,
459
+ values : req.body.values,
460
+ file : file
456
461
  },
457
462
  };
458
463
  } else {
@@ -460,7 +465,7 @@ export async function createPendingApprovalFunction(req: any) : Promise<any> {
460
465
  status: "error",
461
466
  statusCode: 400,
462
467
  message:
463
- "workflow does not exists",
468
+ "Workflow does not exists",
464
469
  };
465
470
  }
466
471
  } catch (error) {
@@ -468,7 +473,7 @@ export async function createPendingApprovalFunction(req: any) : Promise<any> {
468
473
  status: "error",
469
474
  statusCode: 400,
470
475
  message:
471
- error
476
+ "Pending Approval couldn't be created, some error occured please contact sequelstring support",
472
477
  };
473
478
  }
474
479
  }
@@ -476,8 +481,9 @@ export async function createPendingApprovalFunction(req: any) : Promise<any> {
476
481
  export async function createPendingApprovalService(
477
482
  req: UserRequest,
478
483
  res: Response
479
- ) : Promise<any> {
484
+ ): Promise<any> {
480
485
  try {
486
+
481
487
  const { status, data, statusCode, message } =
482
488
  await createPendingApprovalFunction({ user: req?.user, body: req?.body });
483
489
  return res.status(statusCode).json({
@@ -495,10 +501,53 @@ export async function createPendingApprovalService(
495
501
  }
496
502
  }
497
503
 
504
+ export async function uploadAddtionalDocumentsService(
505
+ req: UserRequest,
506
+ res: Response
507
+ ): Promise<any> {
508
+ try {
509
+ let output = [];
510
+ for (const item of req.body.additionalDocument) {
511
+ if (item) {
512
+ console.log(item.name);
513
+ const uploadFiles: any = await uploadFile(
514
+ item.file,
515
+ item.name,
516
+ item.type
517
+ );
518
+ let key = item.name?.includes(".")
519
+ ? item.name.split(".")[0]
520
+ : item.name || "unknown";
521
+ output.push(uploadFiles.fileId);
522
+ }
523
+ }
524
+
525
+ console.log("Output data:", output); // Debugging log
526
+
527
+ const { status, data, statusCode, message } = await uploadAddtionalDocuments(
528
+ req.body.documentId,
529
+ output
530
+ );
531
+
532
+ return res.status(statusCode).json({
533
+ status: status,
534
+ message: message,
535
+ data: data,
536
+ });
537
+ } catch (error) {
538
+ return res.status(400).json({
539
+ status: "error",
540
+ message: error?.message,
541
+ });
542
+ }
543
+ }
544
+
545
+
546
+
498
547
  export async function getAllPendingApprovalService(
499
548
  req: UserRequest,
500
549
  res: Response
501
- ) : Promise<any>{
550
+ ) {
502
551
  try {
503
552
  let { company, _id } = req.user;
504
553
  let value = (req.query.value as string) || "";
@@ -523,7 +572,7 @@ export async function getAllPendingApprovalService(
523
572
  }
524
573
  }
525
574
 
526
- export async function getAllDocumentFunction(req: any) : Promise<any> {
575
+ export async function getAllDocumentFunction(req: any) {
527
576
  try {
528
577
  // let { company, _id, level, defaultWorkflow } = req.user;
529
578
  let { defaultWorkflow } = req.user;
@@ -555,11 +604,11 @@ export async function getAllDocumentFunction(req: any) : Promise<any> {
555
604
  );
556
605
  let files: any = [];
557
606
  if (statusCode === "success") {
558
- if (Array.isArray(data?.values?.table)) {
559
- let filterTable = data?.values?.table.filter(
607
+ if (Array.isArray(data.values.table)) {
608
+ let filterTable = data.values.table.filter(
560
609
  (item: any) => item.isActive === true
561
610
  );
562
- if (filterTable?.length) {
611
+ if (filterTable.length) {
563
612
  files = filterTable[0].columnName
564
613
  ?.filter((dt: any) => dt.isFile)
565
614
  .map((fl: any) => fl.key);
@@ -570,6 +619,7 @@ export async function getAllDocumentFunction(req: any) : Promise<any> {
570
619
  const differentiateFirstLevel = data?.values?.differentiateFirstLevel;
571
620
 
572
621
  const documents = await getAllDocument(
622
+ data,
573
623
  Number(totalLevel),
574
624
  req.body.activeWorkflow || defaultWorkflow,
575
625
  value,
@@ -586,7 +636,7 @@ export async function getAllDocumentFunction(req: any) : Promise<any> {
586
636
  manual,
587
637
  dateFrom,
588
638
  dateTo,
589
- searchField = "partnerName",
639
+ searchField,
590
640
  dateFilterKey,
591
641
  sortByKey,
592
642
  files
@@ -598,7 +648,7 @@ export async function getAllDocumentFunction(req: any) : Promise<any> {
598
648
  }
599
649
  }
600
650
 
601
- export async function getAllDocumentService(req: UserRequest, res: Response) : Promise<any> {
651
+ export async function getAllDocumentService(req: UserRequest, res: Response): Promise<any> {
602
652
  try {
603
653
  const { status, statusCode, documents } = await getAllDocumentFunction({
604
654
  body: req?.body,
@@ -620,10 +670,12 @@ export async function getCountByLevelAndStatusFunction(req: any) {
620
670
  const dateTo = (req.body.dateTo as string) || null;
621
671
  const dateFrom = (req.body.dateFrom as string) || null;
622
672
  let dateFilterKey = (req.body.dateFilterKey as string) || "created_At";
623
- let { totalLevel, approvals, differentiateFirstLevel } = await getWorkflowLevelService(
673
+ let { totalLevel, approvals, differentiateFirstLevel, workflow } = await getWorkflowLevelService(
624
674
  req.body.activeWorkflow || defaultWorkflow
625
675
  );
676
+
626
677
  const manual = await getDocumentCountByLevelAndStatus(
678
+ workflow.values[0]?.approvalLevel,
627
679
  company,
628
680
  Number(totalLevel),
629
681
  approvals,
@@ -645,7 +697,7 @@ export async function getCountByLevelAndStatusFunction(req: any) {
645
697
  export async function getcountDocumentsByLevelAndStatusService(
646
698
  req: UserRequest,
647
699
  res: Response
648
- ) : Promise<any> {
700
+ ): Promise<any> {
649
701
  try {
650
702
  const { status, statusCode, data } = await getCountByLevelAndStatusFunction(
651
703
  { body: req?.body, user: req?.user }
@@ -658,7 +710,7 @@ export async function getcountDocumentsByLevelAndStatusService(
658
710
  export async function getPendingApprovalService(
659
711
  req: UserRequest,
660
712
  res: Response
661
- ) : Promise<any>{
713
+ ) {
662
714
  try {
663
715
  let { company, _id } = req.user;
664
716
  let value = (req.query.value as string) || "";
@@ -686,7 +738,7 @@ export async function getPendingApprovalService(
686
738
  export async function updateCommentService(
687
739
  req: Request,
688
740
  res: Response
689
- ): Promise<Response> {
741
+ ): Promise<any> {
690
742
  try {
691
743
  const { id } = req.params;
692
744
  const updates = req.body;
@@ -746,6 +798,26 @@ export async function getPendingDashService(req: UserRequest, res: Response) {
746
798
  }
747
799
  }
748
800
 
801
+ export async function saveAsDraftService(req : any, res : any){
802
+ try
803
+ {
804
+ const {status, statusCode, data, message} = await saveAsDraftDocument(req.body.documentId, req.body)
805
+ res.status(statusCode).send({
806
+ status,
807
+ message,
808
+ data
809
+ })
810
+ }
811
+ catch(err : any)
812
+ {
813
+ res.status(500).send({
814
+ message : err?.message,
815
+ data : err?.message,
816
+ statusCode : 500
817
+ })
818
+ }
819
+ }
820
+
749
821
  export async function updateDocumentFunction(req: any, docId: any) {
750
822
  try {
751
823
  const id = docId;
@@ -786,23 +858,28 @@ export async function updateDocumentFunction(req: any, docId: any) {
786
858
  };
787
859
  }
788
860
 
789
- if (createType === "alternative") {
790
- updates.createdAt = new Date();
791
- await updateAlternativeDocument(id, updates);
792
- } else {
793
- await updateDocument(id, updates);
794
- }
795
861
  let {
796
862
  currentUser,
797
863
  currentUserDetails,
798
864
  workflow,
799
865
  notifications,
800
866
  triggerMailForLevel1,
867
+ triggers
801
868
  } = await getWorkflowLevelService(
802
869
  updates.workflow,
803
870
  req.user.level,
804
871
  req.body.status
805
872
  );
873
+
874
+ let updatedDocuments : any = null
875
+
876
+ if (createType === "alternative") {
877
+ updates.createdAt = new Date();
878
+ await updateAlternativeDocument(id, updates);
879
+ } else {
880
+ updatedDocuments = await updateDocument(id, updates, workflow);
881
+ }
882
+
806
883
  let commentText = "";
807
884
  if (req.body.comment) {
808
885
  commentText = ` and added the following comment: "${req.body.comment}"`;
@@ -810,32 +887,25 @@ export async function updateDocumentFunction(req: any, docId: any) {
810
887
 
811
888
  let message;
812
889
  if (req.body.status === "approved") {
813
- message = `${
814
- req.user.username?.charAt(0)?.toUpperCase() +
890
+ message = `${req.user.username?.charAt(0)?.toUpperCase() +
815
891
  req.user?.username?.slice(1)?.toLowerCase()
816
- } has ${
817
- req.body.status
818
- } the document and sent it for the approval in the next level process of the document.${
819
- commentText ? ` Added Comments: "${req.body.comment}"` : ""
820
- }`;
892
+ } has ${req.body.status
893
+ } the document and sent it for the approval in the next level process of the document.${commentText ? ` Added Comments: "${req.body.comment}"` : ""
894
+ }`;
821
895
  }
822
896
 
823
897
  if (req.body.status === "pending") {
824
- message = `${
825
- req.user.username?.charAt(0)?.toUpperCase() +
898
+ message = `${req.user.username?.charAt(0)?.toUpperCase() +
826
899
  req.user?.username?.slice(1)?.toLowerCase()
827
- } hasn't approved the document. The document status is ${
828
- req.body.status
829
- }.${commentText ? ` Added Comments: "${req.body.comment}"` : ""}`;
900
+ } hasn't approved the document. The document status is ${req.body.status
901
+ }.${commentText ? ` Added Comments: "${req.body.comment}"` : ""}`;
830
902
  }
831
903
 
832
904
  if (req.body.status === "rejected") {
833
- message = `${
834
- req.user.username?.charAt(0)?.toUpperCase() +
905
+ message = `${req.user.username?.charAt(0)?.toUpperCase() +
835
906
  req.user?.username?.slice(1)?.toLowerCase()
836
- } hasn't approved the document. The document status is ${
837
- req.body.status
838
- }.${commentText ? ` Added Comments: "${req.body.comment}"` : ""}`;
907
+ } hasn't approved the document. The document status is ${req.body.status
908
+ }.${commentText ? ` Added Comments: "${req.body.comment}"` : ""}`;
839
909
  }
840
910
 
841
911
  const data = {
@@ -843,7 +913,7 @@ export async function updateDocumentFunction(req: any, docId: any) {
843
913
  message: message,
844
914
  documentId: id,
845
915
  type: req.body.type,
846
- workflow: updates.workflow,
916
+ workflow: updates.workflow
847
917
  };
848
918
 
849
919
  const notificationsPromises = currentUser.map(
@@ -854,15 +924,15 @@ export async function updateDocumentFunction(req: any, docId: any) {
854
924
  };
855
925
 
856
926
  try {
857
- const filterNotify = notifications?.filter(
858
- (item: any) =>
859
- item.level.includes("level-1") &&
860
- triggerMailForLevel1 &&
861
- item.approval.includes(req.body.status) &&
862
- item.isActive
863
- );
864
-
865
- const filterUserNotify = notifications?.filter(
927
+ // const filterNotify = notifications?.filter(
928
+ // (item: any) =>
929
+ // item.level.includes("level-1") &&
930
+ // triggerMailForLevel1 &&
931
+ // item.approval.includes(req.body.status) &&
932
+ // item.isActive
933
+ // );
934
+
935
+ let filterUserNotify = notifications?.filter(
866
936
  (item: any) =>
867
937
  item.level.includes(currentUserDetails[index].level) &&
868
938
  item.approval.includes(req.body.status) &&
@@ -874,11 +944,15 @@ export async function updateDocumentFunction(req: any, docId: any) {
874
944
  const smsResults = [];
875
945
 
876
946
  for (const notifyItem of filterUserNotify) {
947
+ if(!workflow?.values[0]?.reset_to_level_1){
877
948
  if (
878
949
  (userData.receiver === docData?.user?._id.toString() &&
879
950
  currentUserDetails[index]?.level === "level-1") ||
880
951
  currentUserDetails[index]?.level !== "level-1"
881
952
  ) {
953
+
954
+ await createNotificationsService(userData);
955
+
882
956
  const dt: any = {
883
957
  username: req.user?.username,
884
958
  approver: currentUserDetails[index].username,
@@ -887,10 +961,9 @@ export async function updateDocumentFunction(req: any, docId: any) {
887
961
  documentUrl: process.env.FRONTEND_URL,
888
962
  comments:
889
963
  createType === "reupload" || createType === "alternative"
890
- ? `${
891
- req.user.username?.charAt(0)?.toUpperCase() +
892
- req.user?.username?.slice(1)?.toLowerCase()
893
- } has reuploaded the document`
964
+ ? `${req.user.username?.charAt(0)?.toUpperCase() +
965
+ req.user?.username?.slice(1)?.toLowerCase()
966
+ } has reuploaded the document`
894
967
  : `${data.message}`,
895
968
  logo: "https://www.sequelstring.com/_next/image?url=%2Fimages%2Flogo.webp&w=256&q=100",
896
969
  };
@@ -922,6 +995,7 @@ export async function updateDocumentFunction(req: any, docId: any) {
922
995
  }
923
996
  }
924
997
  }
998
+ }
925
999
  } catch (error) {
926
1000
  return {
927
1001
  status: "error",
@@ -930,7 +1004,7 @@ export async function updateDocumentFunction(req: any, docId: any) {
930
1004
  }
931
1005
  }
932
1006
  );
933
- if (triggerMailForLevel1) {
1007
+ if (triggerMailForLevel1 || (workflow?.values[0]?.reset_to_level_1 && req.body.status === "rejected")) {
934
1008
  const Level1Mail: any = {
935
1009
  username: req.user?.username,
936
1010
  approver: docData?.user.username,
@@ -965,19 +1039,42 @@ export async function updateDocumentFunction(req: any, docId: any) {
965
1039
 
966
1040
  // for (const item of triggers) {
967
1041
  // try {
968
- // if (item.action === "url") {
969
- // const { status, data } = await sendTriggerRequest(
970
- // item.method,
971
- // { values: req.body.values },
972
- // "token"
973
- // );
974
- // console.log("Status:", status);
1042
+ // if (item.action === "url" && Array.isArray(item.level)) {
1043
+ // if(item?.level?.includes(req.user?.level)){
1044
+ // const { status, data } = await sendTriggerRequest(
1045
+ // item.method,
1046
+ // { values: req.body.values },
1047
+ // "token"
1048
+ // );
1049
+ // }
975
1050
  // }
1051
+
976
1052
  // } catch (error) {
977
1053
  // console.error("Error processing trigger:", error?.message);
978
1054
  // }
979
1055
  // }
980
1056
 
1057
+ for (const item of triggers) {
1058
+ try {
1059
+ if (Array.isArray(item.level)) {
1060
+ if (item?.level.includes(req.body?.level) && item?.approval.includes(req.body.status)) {
1061
+ const helpInfo: any = findTriggerValues(docData?._doc?.helpInfo || {}, req.body.status);
1062
+
1063
+ if (item.action === "url") {
1064
+ const { status, data } = await handleSendTrigger(item, {
1065
+ values: req.body.values,
1066
+ ...helpInfo,
1067
+ level: req.body.level,
1068
+ workflowStatus: req.body.status,
1069
+ comment: req.body.comment,
1070
+ });
1071
+ }
1072
+ }}
1073
+ } catch (error) {
1074
+ console.error("Error processing trigger:", error?.message);
1075
+ }
1076
+ }
1077
+
981
1078
  if (success) {
982
1079
  return {
983
1080
  status: "success",
@@ -993,11 +1090,11 @@ export async function updateDocumentFunction(req: any, docId: any) {
993
1090
  }
994
1091
  } catch (error) {
995
1092
  console.log(error);
996
- return { status: "error", statusCode: 200, message: error.message };
1093
+ return { status: "error", statusCode: 500, message: error.message };
997
1094
  }
998
1095
  }
999
1096
 
1000
- export async function updateDocumentService(req: UserRequest, res: Response) : Promise<any> {
1097
+ export async function updateDocumentService(req: UserRequest, res: Response) : Promise<any>{
1001
1098
  try {
1002
1099
  const id = req?.params?.id;
1003
1100
  const { status, statusCode, message } = await updateDocumentFunction(
@@ -1017,7 +1114,7 @@ export async function updateDocumentService(req: UserRequest, res: Response) : P
1017
1114
  export async function updateDocumentLevel2Service(
1018
1115
  req: UserRequest,
1019
1116
  res: Response
1020
- ) : Promise<any>{
1117
+ ) {
1021
1118
  try {
1022
1119
  const id = req.params.id;
1023
1120
  const updates = req.body;
@@ -1074,7 +1171,7 @@ export async function updateDocumentLevel2Service(
1074
1171
  export async function updateDocumentLevelService(
1075
1172
  req: UserRequest,
1076
1173
  res: Response
1077
- ) : Promise<any>{
1174
+ ) {
1078
1175
  try {
1079
1176
  const id = req.params.id;
1080
1177
  const updates = req.body;
@@ -1134,7 +1231,7 @@ export async function updateDocumentLevelService(
1134
1231
  }
1135
1232
  }
1136
1233
 
1137
- export const getDashChartService = async (req: UserRequest, res: Response) : Promise<any> => {
1234
+ export const getDashChartService = async (req: UserRequest, res: Response) => {
1138
1235
  try {
1139
1236
  req.body.user = req.user;
1140
1237
  const result = await getDashChartdata(req.body);
@@ -1147,7 +1244,7 @@ export const getDashChartService = async (req: UserRequest, res: Response) : Pro
1147
1244
  }
1148
1245
  };
1149
1246
 
1150
- export const deleteAllDocumentsService = async (req: any, res: Response) : Promise<any> => {
1247
+ export const deleteAllDocumentsService = async (req: any, res: Response) => {
1151
1248
  try {
1152
1249
  const { status, data } = await deleteAllDocuments();
1153
1250
  if (status === "success") {
@@ -1169,7 +1266,7 @@ export const deleteAllDocumentsService = async (req: any, res: Response) : Promi
1169
1266
  }
1170
1267
  };
1171
1268
 
1172
- export const deleteSingleDocumentService = async (req: any, res: Response) : Promise<any> => {
1269
+ export const deleteSingleDocumentService = async (req: any, res: Response) => {
1173
1270
  try {
1174
1271
  const { status, data } = await deleteSingleDocument({
1175
1272
  id: new mongoose.Types.ObjectId(req.params.id),