my-typescript-library-rahul52us 1.3.4 → 1.3.5
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/dist/config/auth/passportConfig.js +3 -2
- package/dist/config/auth/passportConfig.js.map +1 -1
- package/dist/controllers/auth.controller.js +1 -1
- package/dist/controllers/auth.controller.js.map +1 -1
- package/dist/controllers/rbac/rbac.controller.js +1 -5
- package/dist/controllers/rbac/rbac.controller.js.map +1 -1
- package/dist/helpers/jwt.helper.js +1 -1
- package/dist/helpers/jwt.helper.js.map +1 -1
- package/dist/libs/mail.js +1 -1
- package/dist/libs/mail.js.map +1 -1
- package/dist/repository/accountdetails.repository.js +1 -1
- package/dist/repository/accountdetails.repository.js.map +1 -1
- package/dist/repository/document.repository.js +175 -23
- package/dist/repository/document.repository.js.map +1 -1
- package/dist/repository/filesystem.repository.js +3 -3
- package/dist/repository/filesystem.repository.js.map +1 -1
- package/dist/repository/log.repository.js +3 -3
- package/dist/repository/log.repository.js.map +1 -1
- package/dist/repository/notifications.repository.js.map +1 -1
- package/dist/repository/schemas/accountdetails.schema.js.map +1 -1
- package/dist/repository/schemas/accounts.schema.js +10 -33
- package/dist/repository/schemas/accounts.schema.js.map +1 -1
- package/dist/repository/schemas/document.schema.js +12 -19
- package/dist/repository/schemas/document.schema.js.map +1 -1
- package/dist/repository/schemas/extracted.schema.js +3 -5
- package/dist/repository/schemas/extracted.schema.js.map +1 -1
- package/dist/repository/schemas/fileSystem.schema.js +2 -5
- package/dist/repository/schemas/fileSystem.schema.js.map +1 -1
- package/dist/repository/schemas/form.schema.js +1 -1
- package/dist/repository/schemas/form.schema.js.map +1 -1
- package/dist/repository/schemas/log.schema.js +4 -4
- package/dist/repository/schemas/log.schema.js.map +1 -1
- package/dist/repository/schemas/notifications.schema.js +2 -3
- package/dist/repository/schemas/notifications.schema.js.map +1 -1
- package/dist/repository/schemas/organisation.schema.js +25 -29
- package/dist/repository/schemas/organisation.schema.js.map +1 -1
- package/dist/repository/schemas/profile.schema.js +1 -1
- package/dist/repository/schemas/profile.schema.js.map +1 -1
- package/dist/repository/schemas/role.schema.js +1 -1
- package/dist/repository/schemas/role.schema.js.map +1 -1
- package/dist/repository/schemas/tokens.schema.js +5 -5
- package/dist/repository/schemas/tokens.schema.js.map +1 -1
- package/dist/repository/schemas/userrole.schema.js +1 -1
- package/dist/repository/schemas/userrole.schema.js.map +1 -1
- package/dist/repository/schemas/workflow.schema.js +14 -40
- package/dist/repository/schemas/workflow.schema.js.map +1 -1
- package/dist/repository/user.repository.js +32 -20
- package/dist/repository/user.repository.js.map +1 -1
- package/dist/repository/user_tokens.repository.js +1 -1
- package/dist/repository/user_tokens.repository.js.map +1 -1
- package/dist/repository/userrole.repository.js.map +1 -1
- package/dist/repository/workflow.repository.js +0 -1
- package/dist/repository/workflow.repository.js.map +1 -1
- package/dist/routes/accountdetails.route.js +2 -2
- package/dist/routes/accountdetails.route.js.map +1 -1
- package/dist/routes/auth.route.js +6 -5
- package/dist/routes/auth.route.js.map +1 -1
- package/dist/routes/document.route.js +4 -2
- package/dist/routes/document.route.js.map +1 -1
- package/dist/routes/fileSystem.route.js +2 -1
- package/dist/routes/fileSystem.route.js.map +1 -1
- package/dist/routes/form.route.js +2 -2
- package/dist/routes/form.route.js.map +1 -1
- package/dist/routes/index.js +1 -1
- package/dist/routes/index.js.map +1 -1
- package/dist/routes/log.route.js +3 -3
- package/dist/routes/log.route.js.map +1 -1
- package/dist/routes/notifications.route.js +1 -1
- package/dist/routes/notifications.route.js.map +1 -1
- package/dist/routes/org.route.js +2 -2
- package/dist/routes/org.route.js.map +1 -1
- package/dist/routes/profile.route.js +4 -3
- package/dist/routes/profile.route.js.map +1 -1
- package/dist/routes/role.route.js +7 -4
- package/dist/routes/role.route.js.map +1 -1
- package/dist/routes/user.route.js +12 -10
- package/dist/routes/user.route.js.map +1 -1
- package/dist/routes/userrole.route.js +6 -4
- package/dist/routes/userrole.route.js.map +1 -1
- package/dist/routes/workflow.route.js +3 -3
- package/dist/routes/workflow.route.js.map +1 -1
- package/dist/server.js +1 -3
- package/dist/server.js.map +1 -1
- package/dist/services/apikey/apikey.service.js +102 -0
- package/dist/services/apikey/apikey.service.js.map +1 -0
- package/dist/services/authentication/change-password.service.js +4 -4
- package/dist/services/authentication/change-password.service.js.map +1 -1
- package/dist/services/authentication/forgot-password.service.js +6 -6
- package/dist/services/authentication/forgot-password.service.js.map +1 -1
- package/dist/services/authentication/getuser.service.js +2 -2
- package/dist/services/authentication/getuser.service.js.map +1 -1
- package/dist/services/authentication/login.service.js +4 -4
- package/dist/services/authentication/login.service.js.map +1 -1
- package/dist/services/authentication/register.admin.service.js +1 -1
- package/dist/services/authentication/register.admin.service.js.map +1 -1
- package/dist/services/authentication/register.service.js +8 -8
- package/dist/services/authentication/register.service.js.map +1 -1
- package/dist/services/authentication/resend-email.service.js +6 -6
- package/dist/services/authentication/resend-email.service.js.map +1 -1
- package/dist/services/authentication/reset-password.service.js +29 -11
- package/dist/services/authentication/reset-password.service.js.map +1 -1
- package/dist/services/authentication/verify-email.service.js +4 -4
- package/dist/services/authentication/verify-email.service.js.map +1 -1
- package/dist/services/document/document.services.js +177 -94
- package/dist/services/document/document.services.js.map +1 -1
- package/dist/services/document/dummy.js +85 -0
- package/dist/services/document/dummy.js.map +1 -0
- package/dist/services/fileSystem/fileSystem.service.js +1 -1
- package/dist/services/fileSystem/fileSystem.service.js.map +1 -1
- package/dist/services/form/form.service.js +1 -1
- package/dist/services/form/form.service.js.map +1 -1
- package/dist/services/logs/log.service.js +1 -1
- package/dist/services/logs/log.service.js.map +1 -1
- package/dist/services/notifications/notifications.service.js +1 -1
- package/dist/services/notifications/notifications.service.js.map +1 -1
- package/dist/services/organisation/organisation.service.js +2 -2
- package/dist/services/organisation/organisation.service.js.map +1 -1
- package/dist/services/profile/profile.services.js +1 -1
- package/dist/services/profile/profile.services.js.map +1 -1
- package/dist/services/roles/role.services.js +1 -1
- package/dist/services/roles/role.services.js.map +1 -1
- package/dist/services/statement/accountdetails.service.js +1 -1
- package/dist/services/statement/accountdetails.service.js.map +1 -1
- package/dist/services/userroles/userrole.service.js +1 -1
- package/dist/services/userroles/userrole.service.js.map +1 -1
- package/dist/services/workflow/workSettings.service.js +1 -1
- package/dist/services/workflow/workSettings.service.js.map +1 -1
- package/dist/services/workflow/workflow.service.js +9 -7
- package/dist/services/workflow/workflow.service.js.map +1 -1
- package/dist/types/controllers/auth.controller.d.ts +4 -4
- package/dist/types/repository/document.repository.d.ts +56 -16
- package/dist/types/repository/form.repository.d.ts +7 -3
- package/dist/types/repository/organisation.repository.d.ts +1 -6
- package/dist/types/repository/profile.repository.d.ts +4 -3
- package/dist/types/repository/role.repository.d.ts +5 -2
- package/dist/types/repository/schemas/accounts.schema.d.ts +14 -11
- package/dist/types/repository/schemas/document.schema.d.ts +4 -4
- package/dist/types/repository/schemas/extracted.schema.d.ts +3 -3
- package/dist/types/repository/schemas/fileSystem.schema.d.ts +2 -6
- package/dist/types/repository/schemas/form.schema.d.ts +1 -1
- package/dist/types/repository/schemas/organisation.schema.d.ts +11 -11
- package/dist/types/repository/schemas/profile.schema.d.ts +1 -1
- package/dist/types/repository/schemas/role.schema.d.ts +1 -1
- package/dist/types/repository/schemas/userrole.schema.d.ts +1 -1
- package/dist/types/repository/schemas/workflow.schema.d.ts +2 -14
- package/dist/types/repository/user.repository.d.ts +45 -16
- package/dist/types/repository/userrole.repository.d.ts +5 -2
- package/dist/types/repository/workflow.repository.d.ts +4 -38
- package/dist/types/server.d.ts +0 -1
- package/dist/types/services/apikey/apikey.service.d.ts +12 -0
- package/dist/types/services/authentication/change-password.service.d.ts +1 -1
- package/dist/types/services/authentication/forgot-password.service.d.ts +2 -2
- package/dist/types/services/authentication/getuser.service.d.ts +29 -3
- package/dist/types/services/authentication/login.service.d.ts +1 -1
- package/dist/types/services/authentication/register.admin.service.d.ts +1 -1
- package/dist/types/services/authentication/register.service.d.ts +1 -1
- package/dist/types/services/authentication/resend-email.service.d.ts +2 -2
- package/dist/types/services/authentication/reset-password.service.d.ts +2 -2
- package/dist/types/services/authentication/verify-email.service.d.ts +1 -1
- package/dist/types/services/document/document.services.d.ts +42 -12
- package/dist/types/services/document/dummy.d.ts +45 -0
- package/dist/types/services/logs/log.service.d.ts +1 -1
- package/dist/types/services/profile/profile.services.d.ts +3 -3
- package/dist/types/services/roles/role.services.d.ts +33 -5
- package/dist/types/services/userroles/userrole.service.d.ts +5 -13
- package/dist/types/services/workflow/workflow.service.d.ts +2 -2
- package/dist/types/utils/common.d.ts +5 -0
- package/dist/utils/common.js +23 -1
- package/dist/utils/common.js.map +1 -1
- package/package.json +1 -1
- package/src/config/auth/passportConfig.ts +5 -2
- package/src/controllers/auth.controller.ts +3 -3
- package/src/controllers/rbac/rbac.controller.ts +1 -2
- package/src/helpers/jwt.helper.ts +1 -1
- package/src/libs/mail.ts +2 -2
- package/src/repository/accountdetails.repository.ts +1 -1
- package/src/repository/document.repository.ts +222 -38
- package/src/repository/filesystem.repository.ts +5 -5
- package/src/repository/form.repository.ts +4 -4
- package/src/repository/log.repository.ts +3 -3
- package/src/repository/notifications.repository.ts +2 -1
- package/src/repository/organisation.repository.ts +1 -1
- package/src/repository/profile.repository.ts +1 -1
- package/src/repository/role.repository.ts +1 -1
- package/src/repository/schemas/WorkflowSettingsScheme.ts +0 -2
- package/src/repository/schemas/accountdetails.schema.ts +2 -5
- package/src/repository/schemas/accounts.schema.ts +30 -31
- package/src/repository/schemas/document.schema.ts +15 -18
- package/src/repository/schemas/extracted.schema.ts +28 -31
- package/src/repository/schemas/fileSystem.schema.ts +4 -7
- package/src/repository/schemas/form.schema.ts +1 -2
- package/src/repository/schemas/log.schema.ts +6 -7
- package/src/repository/schemas/notifications.schema.ts +2 -4
- package/src/repository/schemas/organisation.schema.ts +44 -51
- package/src/repository/schemas/profile.schema.ts +1 -2
- package/src/repository/schemas/role.schema.ts +1 -2
- package/src/repository/schemas/tokens.schema.ts +18 -20
- package/src/repository/schemas/userrole.schema.ts +1 -2
- package/src/repository/schemas/workflow.schema.ts +41 -61
- package/src/repository/user.repository.ts +75 -54
- package/src/repository/user_tokens.repository.ts +3 -3
- package/src/repository/userrole.repository.ts +2 -2
- package/src/repository/workflow.repository.ts +4 -5
- package/src/routes/accountdetails.route.ts +3 -2
- package/src/routes/auth.route.ts +6 -5
- package/src/routes/document.route.ts +6 -2
- package/src/routes/fileSystem.route.ts +3 -1
- package/src/routes/form.route.ts +7 -2
- package/src/routes/index.ts +2 -1
- package/src/routes/log.route.ts +4 -4
- package/src/routes/notifications.route.ts +1 -1
- package/src/routes/org.route.ts +2 -2
- package/src/routes/profile.route.ts +4 -3
- package/src/routes/role.route.ts +7 -4
- package/src/routes/user.route.ts +30 -8
- package/src/routes/userrole.route.ts +6 -4
- package/src/routes/workflow.route.ts +12 -4
- package/src/server.ts +0 -1
- package/src/services/authentication/change-password.service.ts +8 -8
- package/src/services/authentication/forgot-password.service.ts +8 -8
- package/src/services/authentication/getuser.service.ts +3 -3
- package/src/services/authentication/login.service.ts +5 -5
- package/src/services/authentication/register.admin.service.ts +2 -2
- package/src/services/authentication/register.service.ts +9 -9
- package/src/services/authentication/resend-email.service.ts +10 -10
- package/src/services/authentication/reset-password.service.ts +37 -16
- package/src/services/authentication/verify-email.service.ts +5 -5
- package/src/services/document/document.services.ts +222 -124
- package/src/services/document/dummy.ts +81 -0
- package/src/services/fileSystem/fileSystem.service.ts +8 -4
- package/src/services/form/form.service.ts +1 -1
- package/src/services/logs/log.service.ts +2 -2
- package/src/services/notifications/notifications.service.ts +9 -9
- package/src/services/organisation/organisation.service.ts +8 -8
- package/src/services/profile/profile.services.ts +6 -6
- package/src/services/roles/role.services.ts +5 -5
- package/src/services/statement/accountdetails.service.ts +2 -2
- package/src/services/userroles/userrole.service.ts +6 -6
- package/src/services/workflow/workSettings.service.ts +2 -2
- package/src/services/workflow/workflow.service.ts +18 -12
- package/src/utils/common.ts +36 -13
- package/.vscode/extensions.json +0 -5
- package/dist/controllers/rbac/grantaccess.json +0 -72
- package/dist/setupModal.js +0 -58
- package/dist/setupModal.js.map +0 -1
- package/dist/types/setupModal.d.ts +0 -7
- package/src/setupModal.ts +0 -60
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { IDocument } from "./schemas/document.schema";
|
|
2
|
+
import Document from "~/repository/schemas/document.schema";
|
|
2
3
|
import mongoose from "mongoose";
|
|
3
|
-
import {
|
|
4
|
-
import { generateLevels } from "../constants/status.constant";
|
|
5
|
-
import fs from "fs";
|
|
4
|
+
import { generateLevels } from "~/constants/status.constant";
|
|
6
5
|
import { deleteAllNotifications } from "./notifications.repository";
|
|
7
6
|
import { findUser } from "./user.repository";
|
|
8
7
|
|
|
@@ -50,7 +49,7 @@ export async function getCount(
|
|
|
50
49
|
level: string | null,
|
|
51
50
|
exchangeType?: string | null,
|
|
52
51
|
billType?: string | null
|
|
53
|
-
)
|
|
52
|
+
) {
|
|
54
53
|
try {
|
|
55
54
|
let pipeline: any = [
|
|
56
55
|
{
|
|
@@ -103,7 +102,7 @@ export async function createPendingApproval(data: IDocument): Promise<any> {
|
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
104
|
|
|
106
|
-
export const findOneByDocumentIdAndDelete = async (data: any)
|
|
105
|
+
export const findOneByDocumentIdAndDelete = async (data: any) => {
|
|
107
106
|
try {
|
|
108
107
|
await Document.findOneAndDelete({ documentId: data.documentId });
|
|
109
108
|
return {
|
|
@@ -128,6 +127,7 @@ interface Data {
|
|
|
128
127
|
}
|
|
129
128
|
|
|
130
129
|
export async function getAllDocument(
|
|
130
|
+
workflowData: any,
|
|
131
131
|
noOfLevels: number,
|
|
132
132
|
workflow: string,
|
|
133
133
|
searchValue: string,
|
|
@@ -148,11 +148,11 @@ export async function getAllDocument(
|
|
|
148
148
|
dateFilterKey: string,
|
|
149
149
|
sortByKey: string,
|
|
150
150
|
additionalFiles: string[]
|
|
151
|
-
)
|
|
151
|
+
) {
|
|
152
152
|
try {
|
|
153
153
|
let matchQuery: any = {};
|
|
154
154
|
if (searchField && searchValue?.trim()) {
|
|
155
|
-
matchQuery[
|
|
155
|
+
matchQuery[`originalValues.${searchField}`] = {
|
|
156
156
|
$regex: searchValue,
|
|
157
157
|
$options: "i",
|
|
158
158
|
};
|
|
@@ -176,6 +176,10 @@ export async function getAllDocument(
|
|
|
176
176
|
deleted_At: { $exists: false },
|
|
177
177
|
};
|
|
178
178
|
|
|
179
|
+
if (level === workflowData?.values?.approvalLevel) {
|
|
180
|
+
matchConditions.isguaranteed = { $eq: true };
|
|
181
|
+
}
|
|
182
|
+
|
|
179
183
|
if (exchangeType && Array.isArray(exchangeType)) {
|
|
180
184
|
exchangeType.forEach((typeObj) => {
|
|
181
185
|
Object.entries(typeObj).forEach(([field, value]) => {
|
|
@@ -197,7 +201,7 @@ export async function getAllDocument(
|
|
|
197
201
|
|
|
198
202
|
let expr: any = {};
|
|
199
203
|
|
|
200
|
-
let levels = generateLevels(noOfLevels
|
|
204
|
+
let levels = generateLevels(noOfLevels);
|
|
201
205
|
switch (level) {
|
|
202
206
|
case levels[0]:
|
|
203
207
|
switch (status) {
|
|
@@ -769,14 +773,14 @@ export async function getAllDocument(
|
|
|
769
773
|
},
|
|
770
774
|
];
|
|
771
775
|
|
|
772
|
-
const lookupStages = additionalFiles.map((obj: any) => ({
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
}));
|
|
776
|
+
// const lookupStages = additionalFiles.map((obj: any) => ({
|
|
777
|
+
// $lookup: {
|
|
778
|
+
// from: "fs.files",
|
|
779
|
+
// localField: `additionalFiles.${obj}`,
|
|
780
|
+
// foreignField: "_id",
|
|
781
|
+
// as: obj,
|
|
782
|
+
// },
|
|
783
|
+
// }));
|
|
780
784
|
|
|
781
785
|
pipeline = [
|
|
782
786
|
...pipeline,
|
|
@@ -788,6 +792,14 @@ export async function getAllDocument(
|
|
|
788
792
|
as: "file",
|
|
789
793
|
},
|
|
790
794
|
},
|
|
795
|
+
{
|
|
796
|
+
$lookup: {
|
|
797
|
+
from: "fs.files",
|
|
798
|
+
localField: "additionalFiles",
|
|
799
|
+
foreignField: "_id",
|
|
800
|
+
as: "additionalFilesDetails",
|
|
801
|
+
},
|
|
802
|
+
},
|
|
791
803
|
{
|
|
792
804
|
$lookup: {
|
|
793
805
|
from: "fs.files",
|
|
@@ -796,7 +808,7 @@ export async function getAllDocument(
|
|
|
796
808
|
as: "filexls",
|
|
797
809
|
},
|
|
798
810
|
},
|
|
799
|
-
...lookupStages,
|
|
811
|
+
// ...lookupStages,
|
|
800
812
|
...approvalStage,
|
|
801
813
|
];
|
|
802
814
|
|
|
@@ -844,6 +856,7 @@ export async function getAllDocument(
|
|
|
844
856
|
}
|
|
845
857
|
|
|
846
858
|
export async function getDocumentCount(
|
|
859
|
+
approvalLevel: string,
|
|
847
860
|
company: string,
|
|
848
861
|
noOfLevels: number,
|
|
849
862
|
workflow: string,
|
|
@@ -892,6 +905,15 @@ export async function getDocumentCount(
|
|
|
892
905
|
}
|
|
893
906
|
});
|
|
894
907
|
|
|
908
|
+
// let extractedLevel = parseInt(level.split('-')[1]);
|
|
909
|
+
// if (noOfLevels === extractedLevel) {
|
|
910
|
+
// matchConditions.isguaranteed = true;
|
|
911
|
+
// }
|
|
912
|
+
|
|
913
|
+
if (level === approvalLevel) {
|
|
914
|
+
matchConditions.isguaranteed = { $eq: true };
|
|
915
|
+
}
|
|
916
|
+
|
|
895
917
|
let pipeline: any = [];
|
|
896
918
|
|
|
897
919
|
let expr: any = {};
|
|
@@ -1382,6 +1404,7 @@ export async function getDocumentCount(
|
|
|
1382
1404
|
}
|
|
1383
1405
|
|
|
1384
1406
|
export async function getDocumentCountByLevelAndStatus(
|
|
1407
|
+
approvalLevel: string,
|
|
1385
1408
|
company: string,
|
|
1386
1409
|
noOfLevels: number,
|
|
1387
1410
|
approvals: any[],
|
|
@@ -1393,7 +1416,7 @@ export async function getDocumentCountByLevelAndStatus(
|
|
|
1393
1416
|
dateFrom: Date | string,
|
|
1394
1417
|
exchangeType?: string | null,
|
|
1395
1418
|
dateFilterKey?: string
|
|
1396
|
-
)
|
|
1419
|
+
) {
|
|
1397
1420
|
try {
|
|
1398
1421
|
const promises: any = [];
|
|
1399
1422
|
let filteredApprovals: any = [];
|
|
@@ -1435,6 +1458,7 @@ export async function getDocumentCountByLevelAndStatus(
|
|
|
1435
1458
|
promises.push(
|
|
1436
1459
|
Document.aggregate(
|
|
1437
1460
|
await getDocumentCount(
|
|
1461
|
+
approvalLevel,
|
|
1438
1462
|
company,
|
|
1439
1463
|
noOfLevels,
|
|
1440
1464
|
workflow,
|
|
@@ -1472,7 +1496,7 @@ export async function countDocumentsByLevelAndStatus(
|
|
|
1472
1496
|
status: string,
|
|
1473
1497
|
exchangeType: string | null,
|
|
1474
1498
|
billType: string | null
|
|
1475
|
-
)
|
|
1499
|
+
) {
|
|
1476
1500
|
try {
|
|
1477
1501
|
const matchStage = {
|
|
1478
1502
|
status,
|
|
@@ -1520,7 +1544,7 @@ export async function getDocumentCountDetails(
|
|
|
1520
1544
|
status: string,
|
|
1521
1545
|
exchangeType: string | null,
|
|
1522
1546
|
billType: string | null
|
|
1523
|
-
)
|
|
1547
|
+
) {
|
|
1524
1548
|
try {
|
|
1525
1549
|
const pipeline = [
|
|
1526
1550
|
{
|
|
@@ -1553,7 +1577,7 @@ export async function getAllPendingApproval(
|
|
|
1553
1577
|
page: string | null = "1",
|
|
1554
1578
|
exchangeType: string | null,
|
|
1555
1579
|
billType: string | null
|
|
1556
|
-
)
|
|
1580
|
+
) {
|
|
1557
1581
|
try {
|
|
1558
1582
|
// Create an array to hold the aggregation pipeline stages
|
|
1559
1583
|
const pipeline: any = [
|
|
@@ -1627,7 +1651,7 @@ export async function getPendingApproval(
|
|
|
1627
1651
|
page: string | null = "1",
|
|
1628
1652
|
exchangeType: string | null,
|
|
1629
1653
|
billType: string | null
|
|
1630
|
-
)
|
|
1654
|
+
) {
|
|
1631
1655
|
try {
|
|
1632
1656
|
// company: string, userId: string
|
|
1633
1657
|
const matchConditions: any = {
|
|
@@ -1695,12 +1719,95 @@ export async function getPendingApproval(
|
|
|
1695
1719
|
}
|
|
1696
1720
|
}
|
|
1697
1721
|
|
|
1698
|
-
export async function
|
|
1722
|
+
export async function saveAsDraftDocument(id: string, data: any) {
|
|
1723
|
+
try {
|
|
1724
|
+
const documentData: any = await Document.findOne({ documentId: id });
|
|
1725
|
+
if (documentData) {
|
|
1726
|
+
documentData.workflow = new mongoose.Types.ObjectId(
|
|
1727
|
+
documentData.workflow
|
|
1728
|
+
);
|
|
1729
|
+
|
|
1730
|
+
if (
|
|
1731
|
+
Array.isArray(documentData.values) &&
|
|
1732
|
+
documentData.values.length > 0
|
|
1733
|
+
) {
|
|
1734
|
+
documentData.values[documentData.values.length - 1].values =
|
|
1735
|
+
data.values;
|
|
1736
|
+
documentData.updated_At = new Date();
|
|
1737
|
+
} else {
|
|
1738
|
+
documentData.values = [
|
|
1739
|
+
{
|
|
1740
|
+
level: "level-1",
|
|
1741
|
+
values: data.values,
|
|
1742
|
+
updated_At: new Date(),
|
|
1743
|
+
},
|
|
1744
|
+
];
|
|
1745
|
+
documentData.updated_At = new Date();
|
|
1746
|
+
}
|
|
1747
|
+
documentData.markModified("values");
|
|
1748
|
+
|
|
1749
|
+
documentData.status = "draft";
|
|
1750
|
+
await documentData.save();
|
|
1751
|
+
|
|
1752
|
+
return {
|
|
1753
|
+
status: "success",
|
|
1754
|
+
data: documentData,
|
|
1755
|
+
message: "Document has been saved Successfully",
|
|
1756
|
+
statusCode: 200,
|
|
1757
|
+
};
|
|
1758
|
+
} else {
|
|
1759
|
+
return {
|
|
1760
|
+
status: "error",
|
|
1761
|
+
message: "No such document exists",
|
|
1762
|
+
statusCode: 400,
|
|
1763
|
+
data: "No such document exists",
|
|
1764
|
+
};
|
|
1765
|
+
}
|
|
1766
|
+
} catch (err: any) {
|
|
1767
|
+
console.log(err?.message);
|
|
1768
|
+
return {
|
|
1769
|
+
status: "error",
|
|
1770
|
+
message: err?.message,
|
|
1771
|
+
statusCode: 400,
|
|
1772
|
+
data: err?.message,
|
|
1773
|
+
};
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
export async function uploadAddtionalDocuments(id: string, data: any) {
|
|
1778
|
+
try {
|
|
1779
|
+
|
|
1780
|
+
// Find the document by ID and workflow
|
|
1781
|
+
const updatedDocument: any = await Document.findOne({
|
|
1782
|
+
_id: id
|
|
1783
|
+
});
|
|
1784
|
+
|
|
1785
|
+
|
|
1786
|
+
let workflowId = updatedDocument.workflow
|
|
1787
|
+
|
|
1788
|
+
updatedDocument.workflow = workflowId
|
|
1789
|
+
|
|
1790
|
+
updatedDocument.additionalFiles = [
|
|
1791
|
+
...(updatedDocument.additionalFiles || []),
|
|
1792
|
+
...data,
|
|
1793
|
+
];
|
|
1794
|
+
|
|
1795
|
+
const savedData = await updatedDocument.save();
|
|
1796
|
+
|
|
1797
|
+
return {statusCode : 200, data : savedData, status : 'success', message : 'Document has been updated successfully'};
|
|
1798
|
+
} catch (error: any) {
|
|
1799
|
+
console.log(error)
|
|
1800
|
+
throw new Error(`Failed to update document: ${error.message}`);
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
export async function updateDocument(id: string, data: any, workflow?: any) {
|
|
1699
1805
|
try {
|
|
1700
1806
|
if (!data || !data.workflow) {
|
|
1701
1807
|
throw new Error("Invalid data provided");
|
|
1702
1808
|
}
|
|
1703
1809
|
|
|
1810
|
+
// Find the document by ID and workflow
|
|
1704
1811
|
const updatedDocument: any = await Document.findOne({
|
|
1705
1812
|
_id: id,
|
|
1706
1813
|
workflow: data.workflow,
|
|
@@ -1711,8 +1818,48 @@ export async function updateDocument(id: string, data: any) : Promise<any>{
|
|
|
1711
1818
|
}
|
|
1712
1819
|
|
|
1713
1820
|
updatedDocument.workflow = data.workflow;
|
|
1714
|
-
updatedDocument.
|
|
1821
|
+
updatedDocument.additionalFiles = [
|
|
1822
|
+
...(updatedDocument.additionalFiles || []),
|
|
1823
|
+
...(Array.isArray(data.updatedDocument) ? data.updatedDocument : []),
|
|
1824
|
+
];
|
|
1825
|
+
updatedDocument.approval.push({ ...data, createdAt: new Date() });
|
|
1715
1826
|
|
|
1827
|
+
let array: any[] = [];
|
|
1828
|
+
|
|
1829
|
+
if (
|
|
1830
|
+
data.status === "rejected" &&
|
|
1831
|
+
data?.level !== "level-1" &&
|
|
1832
|
+
data?.level !== "level-2" &&
|
|
1833
|
+
workflow?.values[0]?.reset_to_level_1
|
|
1834
|
+
) {
|
|
1835
|
+
for (
|
|
1836
|
+
let index = updatedDocument.approval.length - 1;
|
|
1837
|
+
index >= 0;
|
|
1838
|
+
index--
|
|
1839
|
+
) {
|
|
1840
|
+
const approval = updatedDocument.approval[index];
|
|
1841
|
+
if (approval.level === "level-1") {
|
|
1842
|
+
break;
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
if (index !== 0 && approval.level !== data.level) {
|
|
1846
|
+
let newApproval = {
|
|
1847
|
+
...approval,
|
|
1848
|
+
status: "rejected",
|
|
1849
|
+
comment: `Rejected automatically as the document was rejected at ${data.level}`,
|
|
1850
|
+
createdAt: new Date(Date.now() + 60 * 1000), // Explicitly assigning a new Date
|
|
1851
|
+
updatedAt: new Date(Date.now() + 60 * 1000), // Explicitly assigning a new Date
|
|
1852
|
+
};
|
|
1853
|
+
|
|
1854
|
+
array.push(newApproval);
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
const reversedArray = [...array];
|
|
1860
|
+
updatedDocument.approval = [...updatedDocument.approval, ...reversedArray];
|
|
1861
|
+
|
|
1862
|
+
// Update values array
|
|
1716
1863
|
if (Array.isArray(updatedDocument.values)) {
|
|
1717
1864
|
updatedDocument.values = [...updatedDocument.values, data.values];
|
|
1718
1865
|
updatedDocument.updated_At = new Date();
|
|
@@ -1721,10 +1868,47 @@ export async function updateDocument(id: string, data: any) : Promise<any>{
|
|
|
1721
1868
|
updatedDocument.updated_At = new Date();
|
|
1722
1869
|
}
|
|
1723
1870
|
|
|
1871
|
+
// Fetch file metadata and content if a file is associated
|
|
1872
|
+
if (updatedDocument.file) {
|
|
1873
|
+
const db = mongoose.connection.db;
|
|
1874
|
+
const bucket = new mongoose.mongo.GridFSBucket(db, { bucketName: "fs" });
|
|
1875
|
+
|
|
1876
|
+
// Fetch file metadata
|
|
1877
|
+
const fileMetadata = await bucket
|
|
1878
|
+
.find({ _id: updatedDocument.file })
|
|
1879
|
+
.toArray();
|
|
1880
|
+
if (fileMetadata.length > 0) {
|
|
1881
|
+
const fileInfo = fileMetadata[0];
|
|
1882
|
+
updatedDocument.fileInfo = {
|
|
1883
|
+
filename: fileInfo.filename,
|
|
1884
|
+
contentType:
|
|
1885
|
+
fileInfo.metadata?.contentType || "application/octet-stream",
|
|
1886
|
+
};
|
|
1887
|
+
|
|
1888
|
+
// Fetch file content
|
|
1889
|
+
const fileStream = bucket.openDownloadStream(updatedDocument.file);
|
|
1890
|
+
const fileDataChunks: Buffer[] = [];
|
|
1891
|
+
|
|
1892
|
+
await new Promise((resolve, reject) => {
|
|
1893
|
+
fileStream.on("data", (chunk) => fileDataChunks.push(chunk));
|
|
1894
|
+
fileStream.on("end", () => {
|
|
1895
|
+
updatedDocument.fileInfo.content = Buffer.concat(fileDataChunks); // Return raw Buffer
|
|
1896
|
+
resolve(null);
|
|
1897
|
+
});
|
|
1898
|
+
fileStream.on("error", (err) => reject(err));
|
|
1899
|
+
});
|
|
1900
|
+
} else {
|
|
1901
|
+
throw new Error("Associated file metadata not found in GridFS");
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
// Save the updated document
|
|
1906
|
+
updatedDocument.markModified("approval");
|
|
1724
1907
|
const savedData = await updatedDocument.save();
|
|
1725
1908
|
return savedData;
|
|
1726
|
-
} catch (error) {
|
|
1727
|
-
|
|
1909
|
+
} catch (error: any) {
|
|
1910
|
+
console.log(error)
|
|
1911
|
+
throw new Error(`Failed to update document: ${error.message}`);
|
|
1728
1912
|
}
|
|
1729
1913
|
}
|
|
1730
1914
|
|
|
@@ -1738,7 +1922,7 @@ export async function getPendingApprovalDocument(
|
|
|
1738
1922
|
exchangeType: string | null,
|
|
1739
1923
|
billType: string | null,
|
|
1740
1924
|
approvalLevel: number | null // Add a new parameter for approval level
|
|
1741
|
-
)
|
|
1925
|
+
) {
|
|
1742
1926
|
try {
|
|
1743
1927
|
let infiniteScroll: any = [];
|
|
1744
1928
|
if (sort && skip && limit) {
|
|
@@ -1797,7 +1981,7 @@ export async function getPendingApprovalDocument(
|
|
|
1797
1981
|
}
|
|
1798
1982
|
}
|
|
1799
1983
|
|
|
1800
|
-
export async function updateComment(id: string, data: Partial<IDocument>)
|
|
1984
|
+
export async function updateComment(id: string, data: Partial<IDocument>) : Promise<any>{
|
|
1801
1985
|
try {
|
|
1802
1986
|
const result = await Document.updateOne({ _id: id }, { $set: data });
|
|
1803
1987
|
return result;
|
|
@@ -1806,7 +1990,7 @@ export async function updateComment(id: string, data: Partial<IDocument>) : Pro
|
|
|
1806
1990
|
}
|
|
1807
1991
|
}
|
|
1808
1992
|
|
|
1809
|
-
export async function updateStatus(data: Partial<IDocument>)
|
|
1993
|
+
export async function updateStatus(data: Partial<IDocument>) : Promise<any>{
|
|
1810
1994
|
try {
|
|
1811
1995
|
const result = await Document.updateOne(
|
|
1812
1996
|
{ documentId: data.documentId },
|
|
@@ -1822,7 +2006,7 @@ export async function updateStatus(data: Partial<IDocument>) : Promise<any>{
|
|
|
1822
2006
|
}
|
|
1823
2007
|
}
|
|
1824
2008
|
|
|
1825
|
-
export async function updateFile(id: string, data: any)
|
|
2009
|
+
export async function updateFile(id: string, data: any): Promise<any> {
|
|
1826
2010
|
try {
|
|
1827
2011
|
if (!data || !data.workflow) {
|
|
1828
2012
|
throw new Error("Invalid data provided");
|
|
@@ -1838,7 +2022,7 @@ export async function updateFile(id: string, data: any) : Promise<any> {
|
|
|
1838
2022
|
}
|
|
1839
2023
|
}
|
|
1840
2024
|
|
|
1841
|
-
export async function updateAlternativeDocument(id: string, data: any) : Promise<any>
|
|
2025
|
+
export async function updateAlternativeDocument(id: string, data: any) : Promise<any>{
|
|
1842
2026
|
try {
|
|
1843
2027
|
if (!data || !data.workflow) {
|
|
1844
2028
|
throw new Error("Invalid data provided");
|
|
@@ -1869,7 +2053,7 @@ export async function updateAlternativeDocument(id: string, data: any) : Promise
|
|
|
1869
2053
|
}
|
|
1870
2054
|
}
|
|
1871
2055
|
|
|
1872
|
-
export async function getDocument(id: any)
|
|
2056
|
+
export async function getDocument(id: any) {
|
|
1873
2057
|
try {
|
|
1874
2058
|
const doc: any = await Document.findById(id);
|
|
1875
2059
|
if (doc) {
|
|
@@ -1883,7 +2067,7 @@ export async function getDocument(id: any) : Promise<any> {
|
|
|
1883
2067
|
}
|
|
1884
2068
|
}
|
|
1885
2069
|
|
|
1886
|
-
export const getDocumentByStatus = async (req: any, status: any)
|
|
2070
|
+
export const getDocumentByStatus = async (req: any, status: any) => {
|
|
1887
2071
|
try {
|
|
1888
2072
|
const pipeline = [
|
|
1889
2073
|
{
|
|
@@ -1915,7 +2099,7 @@ export const getDocumentByStatus = async (req: any, status: any) : Promise<any>
|
|
|
1915
2099
|
}
|
|
1916
2100
|
};
|
|
1917
2101
|
|
|
1918
|
-
export async function getPendingDash(req: any)
|
|
2102
|
+
export async function getPendingDash(req: any) {
|
|
1919
2103
|
try {
|
|
1920
2104
|
const matchConditions: any = {
|
|
1921
2105
|
deleted_At: { $exists: false },
|
|
@@ -1944,7 +2128,7 @@ export async function getPendingDash(req: any) : Promise<any>{
|
|
|
1944
2128
|
}
|
|
1945
2129
|
}
|
|
1946
2130
|
|
|
1947
|
-
export const getDashChartdata = async (data: any)
|
|
2131
|
+
export const getDashChartdata = async (data: any) => {
|
|
1948
2132
|
try {
|
|
1949
2133
|
const matchStage: any = {
|
|
1950
2134
|
company: data.user.company,
|
|
@@ -1998,7 +2182,7 @@ export const getDashChartdata = async (data: any) : Promise<any> => {
|
|
|
1998
2182
|
};
|
|
1999
2183
|
|
|
2000
2184
|
//
|
|
2001
|
-
export const deleteSingleDocument = async (data: any)
|
|
2185
|
+
export const deleteSingleDocument = async (data: any) => {
|
|
2002
2186
|
try {
|
|
2003
2187
|
const doc = await Document.findById(data.id);
|
|
2004
2188
|
if (doc) {
|
|
@@ -2021,7 +2205,7 @@ export const deleteSingleDocument = async (data: any) : Promise<any>=> {
|
|
|
2021
2205
|
}
|
|
2022
2206
|
};
|
|
2023
2207
|
|
|
2024
|
-
export const deleteAllDocuments = async ()
|
|
2208
|
+
export const deleteAllDocuments = async () => {
|
|
2025
2209
|
try {
|
|
2026
2210
|
await Document.deleteMany();
|
|
2027
2211
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mongoose, { connection, mongo } from "mongoose";
|
|
2
2
|
import { Readable } from "stream";
|
|
3
|
-
import FileSystemModel from "./schemas/fileSystem.schema";
|
|
4
3
|
|
|
4
|
+
import fileSystemSchema from "~/repository/schemas/fileSystem.schema";
|
|
5
5
|
const { GridFSBucket } = mongo;
|
|
6
6
|
|
|
7
7
|
export async function uploadFile(file: string, name: string, type: string) {
|
|
@@ -24,7 +24,7 @@ export async function uploadFile(file: string, name: string, type: string) {
|
|
|
24
24
|
|
|
25
25
|
uploadStream.on("finish", () => {
|
|
26
26
|
const fileId = uploadStream.id;
|
|
27
|
-
|
|
27
|
+
fileSystemSchema
|
|
28
28
|
.create({
|
|
29
29
|
fileId: fileId,
|
|
30
30
|
})
|
|
@@ -37,10 +37,10 @@ export async function uploadFile(file: string, name: string, type: string) {
|
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
uploadStream.on("error", (error) => {
|
|
40
|
-
reject("Error uploading file: " + error);
|
|
40
|
+
reject("Error uploading file: " + error.message);
|
|
41
41
|
});
|
|
42
42
|
} catch (err) {
|
|
43
|
-
reject("Error uploading the file: " + err);
|
|
43
|
+
reject("Error uploading the file: " + err.message);
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
}
|
|
@@ -112,7 +112,7 @@ export async function getFileData(id: string) {
|
|
|
112
112
|
const buffer = Buffer.concat(chunks, fileSize);
|
|
113
113
|
const downloadData = buffer;
|
|
114
114
|
const array = new Uint8Array(downloadData);
|
|
115
|
-
|
|
115
|
+
|
|
116
116
|
// Return an object containing file metadata and data
|
|
117
117
|
resolve({
|
|
118
118
|
fileId: id, // Include file ID
|
|
@@ -13,7 +13,7 @@ export type FormData = {
|
|
|
13
13
|
|
|
14
14
|
export async function createForm(
|
|
15
15
|
FormData: FormData
|
|
16
|
-
)
|
|
16
|
+
): Promise<Schema.Types.ObjectId | Error> {
|
|
17
17
|
try {
|
|
18
18
|
const form = Form.create(new Form(FormData));
|
|
19
19
|
if (!form) {
|
|
@@ -34,7 +34,7 @@ export async function getallForm(
|
|
|
34
34
|
limit: number,
|
|
35
35
|
searchField: any,
|
|
36
36
|
workflow:any
|
|
37
|
-
)
|
|
37
|
+
) {
|
|
38
38
|
try {
|
|
39
39
|
let matchQuery: any = {};
|
|
40
40
|
if (searchField) {
|
|
@@ -87,7 +87,7 @@ export async function getallForm(
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
export async function getForm(data: any)
|
|
90
|
+
export async function getForm(data: any): Promise<FormData> {
|
|
91
91
|
try {
|
|
92
92
|
const form = await Form.findOne(data);
|
|
93
93
|
return form;
|
|
@@ -96,7 +96,7 @@ export async function getallForm(
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
export async function updateForm(id: string, data: any)
|
|
99
|
+
export async function updateForm(id: string, data: any): Promise<any> {
|
|
100
100
|
try {
|
|
101
101
|
if (!id) {
|
|
102
102
|
throw new Error("Form id is required");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Log from '
|
|
1
|
+
import Log, { ILog } from '~/repository/schemas/log.schema';
|
|
2
2
|
|
|
3
3
|
export type LogsProfile = {
|
|
4
4
|
_id?: string;
|
|
@@ -11,7 +11,7 @@ export type LogsProfile = {
|
|
|
11
11
|
user?: string;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
// Create a log
|
|
14
|
+
// Create a log
|
|
15
15
|
export async function createLog(LogsProfile: LogsProfile): Promise<any> {
|
|
16
16
|
try {
|
|
17
17
|
const newLog = await Log.create(new Log(LogsProfile));
|
|
@@ -21,7 +21,7 @@ export async function createLog(LogsProfile: LogsProfile): Promise<any> {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
// function for getting all logs
|
|
24
|
+
// function for getting all logs
|
|
25
25
|
export async function getLogs(searchValue: string, company: string, userId: string) {
|
|
26
26
|
try {
|
|
27
27
|
const pipeline = [
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { defaultsDeep } from "lodash";
|
|
2
2
|
import mongoose from "mongoose";
|
|
3
3
|
import Notifications from "./schemas/notifications.schema";
|
|
4
|
+
import { resetPasswordUser } from "~/services/authentication";
|
|
4
5
|
|
|
5
6
|
type NotificationsData = {
|
|
6
7
|
|
|
@@ -116,7 +117,7 @@ export async function findNotifications(id: string): Promise<any> {
|
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
|
|
119
|
-
export async function deleteAllNotifications()
|
|
120
|
+
export async function deleteAllNotifications() : Promise<any> {
|
|
120
121
|
try {
|
|
121
122
|
const notifications = await Notifications.deleteMany();
|
|
122
123
|
return notifications;
|
|
@@ -109,7 +109,7 @@ export async function updateorganisation(id: string, data: Partial<OrgProfile>)
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
export async function findOrgDetails(id : string) {
|
|
112
|
+
export async function findOrgDetails(id : string): Promise<any> {
|
|
113
113
|
try
|
|
114
114
|
{
|
|
115
115
|
const result = await Organisation.findById(id).select('customerOrg type name')
|
|
@@ -27,7 +27,7 @@ export async function createProfile(accountDetailsData: profile) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export async function updateProfile(id: string, data: accountDetailsData) {
|
|
30
|
+
export async function updateProfile(id: string, data: accountDetailsData): Promise<any> {
|
|
31
31
|
try {
|
|
32
32
|
const profile = await Profile.updateOne({ _id: id }, { $set: data });
|
|
33
33
|
console.log(profile);
|
|
@@ -8,7 +8,7 @@ import mongoose from 'mongoose';
|
|
|
8
8
|
deletedAt?: Date;
|
|
9
9
|
} */
|
|
10
10
|
export { IRole }
|
|
11
|
-
export async function createRolePermission(data: IRole) {
|
|
11
|
+
export async function createRolePermission(data: IRole): Promise<mongoose.Types.ObjectId | Error> {
|
|
12
12
|
try {
|
|
13
13
|
const rolePermission = Role.create(new Role({
|
|
14
14
|
name: data.name,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mongoose, { Schema, Document } from "mongoose";
|
|
2
2
|
|
|
3
3
|
interface AccountDetails extends Document {
|
|
4
|
-
_id
|
|
4
|
+
_id?: string;
|
|
5
5
|
name?: string;
|
|
6
6
|
address?: string;
|
|
7
7
|
createdAt?: string;
|
|
@@ -75,7 +75,6 @@ const AccountDetailsSchema: Schema = new mongoose.Schema({
|
|
|
75
75
|
},
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
-
|
|
79
78
|
let AccountModal: mongoose.Model<any> | null = null;
|
|
80
79
|
|
|
81
80
|
if (mongoose.models.AccountDetails) {
|
|
@@ -86,6 +85,4 @@ if (mongoose.models.AccountDetails) {
|
|
|
86
85
|
AccountModal = mongoose.model<any>("AccountDetails", AccountDetailsSchema);
|
|
87
86
|
}
|
|
88
87
|
|
|
89
|
-
export default AccountModal;
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
export default AccountModal;
|