tango-app-api-client 3.6.5-vms.1 → 3.6.5-vms.11
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/index.js +2 -1
- package/package.json +5 -4
- package/src/controllers/client.controllers.js +151 -1
- package/src/controllers/vmsAudit.controller.js +345 -0
- package/src/dtos/client.dtos.js +52 -1
- package/src/dtos/vmsAudit.dtos.js +24 -0
- package/src/routes/client.routes.js +6 -2
- package/src/routes/vmsAudit.routes.js +10 -0
- package/src/service/vmsStoreRequest.service.js +13 -0
- package/src/service/vmsauditLog.service.js +10 -0
- package/src/service/vmsuserAudit.service.js +22 -0
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { clientRouter } from './src/routes/client.routes.js';
|
|
4
4
|
import { clientDocs } from './src/docs/client.docs.js';
|
|
5
|
+
import { vmsauditRouter } from './src/routes/vmsAudit.routes.js';
|
|
5
6
|
|
|
6
|
-
export { clientRouter, clientDocs };
|
|
7
|
+
export { clientRouter, clientDocs, vmsauditRouter };
|
|
7
8
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-client",
|
|
3
|
-
"version": "3.6.5-vms.
|
|
3
|
+
"version": "3.6.5-vms.11",
|
|
4
4
|
"description": "client",
|
|
5
5
|
"main": "index.js",
|
|
6
|
-
"type": "module",
|
|
6
|
+
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"start": "nodemon --exec \"eslint --fix . && node
|
|
8
|
+
"start": "nodemon --exec \"eslint --fix . && node index.js\"",
|
|
9
9
|
"build:patch": "node build.js patch && npm publish",
|
|
10
10
|
"build:minor": "node build.js minor && npm publish",
|
|
11
11
|
"build:major": "node build.js major && npm publish"
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"aws-sdk": "^2.1560.0",
|
|
20
20
|
"cors": "^2.8.5",
|
|
21
|
+
"dayjs": "^1.11.19",
|
|
21
22
|
"dotenv": "^16.4.4",
|
|
22
23
|
"express": "^4.18.2",
|
|
23
24
|
"express-fileupload": "^1.4.3",
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
"npm": "^10.9.1",
|
|
31
32
|
"sharp": "^0.34.3",
|
|
32
33
|
"swagger-ui-express": "^5.0.0",
|
|
33
|
-
"tango-api-schema": "^2.4.
|
|
34
|
+
"tango-api-schema": "^2.4.27",
|
|
34
35
|
"tango-app-api-middleware": "^3.6.0",
|
|
35
36
|
"winston": "^3.11.0",
|
|
36
37
|
"winston-daily-rotate-file": "^5.0.0"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { billingDetailsUpdate, brandInfoUpdate, domainDetailsConfigurationUpdate, featureConfigurationUpdate, getClientData, signatoryDetailsUpdate, ticketConfigurationUpdate, documentsUpdate, getUserData, CsmUsersGet, OpsUsersGet, userConfigurationUpdate, findClient, aggregateClient, createAuditQueue, findOne, insert, update, findOneClient, updateOneClient } from '../service/client.service.js';
|
|
2
2
|
import { checkFileExist, signedUrl, chunkArray, download, logger, getOpenSearchData, insertOpenSearchData, sendEmailWithSES, createCustomer, createVirtualAccount, getUuid, fileRestrictedUpload, getXsscheck, customSignedUrl } from 'tango-app-api-middleware';
|
|
3
3
|
import { countDocumentsUser, findOneAndUpdateUser, findOneUser, getUserNameEmailById, updateManyUser } from '../service/user.service.js';
|
|
4
|
-
import { aggregateStore, countDocumentsStore, findStore, updateManyStore } from '../service/store.service.js';
|
|
4
|
+
import { aggregateStore, countDocumentsStore, findOneStore, findStore, updateManyStore } from '../service/store.service.js';
|
|
5
5
|
import { aggregateCamera, countDocumentsCamera } from '../service/camera.service.js';
|
|
6
6
|
import _ from 'lodash';
|
|
7
7
|
import { findOneStandaredRole } from '../service/standaredRole.service.js';
|
|
@@ -19,6 +19,7 @@ import { countDocumentsTeams } from '../service/teams.service.js';
|
|
|
19
19
|
import { createauditConfig, updateauditConfig, aggregateAuditconfig } from '../service/auditConfig.service.js';
|
|
20
20
|
import { findOnerevopConfig, createrevopConfig, updaterevopConfig } from '../service/revopConfig.service.js';
|
|
21
21
|
import clientModel from 'tango-api-schema/schema/client.model.js';
|
|
22
|
+
import { aggregateVmsStoreRequest, updateOneUpsertVmsStoreRequest, updateOneVmsStoreRequest } from '../service/vmsStoreRequest.service.js';
|
|
22
23
|
|
|
23
24
|
export async function create( req, res ) {
|
|
24
25
|
try {
|
|
@@ -3033,3 +3034,152 @@ function uniqueByType( arr ) {
|
|
|
3033
3034
|
} );
|
|
3034
3035
|
}
|
|
3035
3036
|
|
|
3037
|
+
export async function createStoreRequest( req, res ) {
|
|
3038
|
+
try {
|
|
3039
|
+
const inputData = req.body;
|
|
3040
|
+
const getClientId = await findOneStore( { storeId: inputData?.storeId }, { clientId: 1, storeName: 1 } );
|
|
3041
|
+
const record = {
|
|
3042
|
+
clientId: getClientId?.clientId,
|
|
3043
|
+
storeId: inputData?.storeId,
|
|
3044
|
+
storeName: getClientId?.storeName,
|
|
3045
|
+
dateString: inputData?.dateString,
|
|
3046
|
+
raisedBy: req?.user?._id,
|
|
3047
|
+
status: 'request',
|
|
3048
|
+
|
|
3049
|
+
};
|
|
3050
|
+
const upsertRecord = await updateOneUpsertVmsStoreRequest( { storeId: inputData?.storeId, dateString: inputData?.dateString }, record );
|
|
3051
|
+
logger.info( { upsertRecord } );
|
|
3052
|
+
if ( upsertRecord?.upsertedCount === 1 ) {
|
|
3053
|
+
return res.sendSuccess( 'The Request has been sent Successfully' );
|
|
3054
|
+
} else if ( upsertRecord?.matchedCount === 1 && upsertRecord?.modifiedCount === 1 ) {
|
|
3055
|
+
return res.sendSuccess( 'The Request has been updated Successfully' );
|
|
3056
|
+
} else if ( upsertRecord?.matchedCount === 1 && upsertRecord?.modifiedCount === 0 ) {
|
|
3057
|
+
return res.sendSuccess( 'The Request already exists and nothing to update' );
|
|
3058
|
+
} else {
|
|
3059
|
+
return res.sendError( 'Internal Server Error', 500 );
|
|
3060
|
+
}
|
|
3061
|
+
} catch ( error ) {
|
|
3062
|
+
const err = error.message || 'Internal Server Error';
|
|
3063
|
+
logger.error( { error: error, message: req.query, function: 'createStoreRequest' } );
|
|
3064
|
+
return res.sendError( err, 500 );
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
|
|
3068
|
+
export async function listStoreRequest( req, res ) {
|
|
3069
|
+
try {
|
|
3070
|
+
const inputData = req.query;
|
|
3071
|
+
|
|
3072
|
+
const today = new Date();
|
|
3073
|
+
const threeDaysAgo = new Date();
|
|
3074
|
+
threeDaysAgo.setDate( today.getDate() - 3 );
|
|
3075
|
+
|
|
3076
|
+
const todayStr = today.toISOString().slice( 0, 10 );
|
|
3077
|
+
const threeDaysAgoStr = threeDaysAgo.toISOString().slice( 0, 10 );
|
|
3078
|
+
|
|
3079
|
+
|
|
3080
|
+
const query = [
|
|
3081
|
+
{
|
|
3082
|
+
$match: {
|
|
3083
|
+
$and: [
|
|
3084
|
+
{
|
|
3085
|
+
clientId: { $eq: inputData?.clientId },
|
|
3086
|
+
},
|
|
3087
|
+
{
|
|
3088
|
+
status: { $eq: 'request' },
|
|
3089
|
+
},
|
|
3090
|
+
{
|
|
3091
|
+
dateString: { $gte: threeDaysAgoStr, $lte: todayStr },
|
|
3092
|
+
},
|
|
3093
|
+
],
|
|
3094
|
+
},
|
|
3095
|
+
},
|
|
3096
|
+
{
|
|
3097
|
+
$project: {
|
|
3098
|
+
_id: 0,
|
|
3099
|
+
id: { $concat: [ '$storeId', '_', '$dateString' ] },
|
|
3100
|
+
storeName: 1,
|
|
3101
|
+
storeId: 1,
|
|
3102
|
+
dateString: 1,
|
|
3103
|
+
raisedOn: { $ifNull: [ { $dateToString: { format: '%d %b, %Y', date: '$createdAt' } }, '' ] },
|
|
3104
|
+
totalRaised: null,
|
|
3105
|
+
},
|
|
3106
|
+
},
|
|
3107
|
+
];
|
|
3108
|
+
const result = await aggregateVmsStoreRequest( query );
|
|
3109
|
+
if ( !result || result.length === 0 ) {
|
|
3110
|
+
return res.sendError( 'no data found', 204 );
|
|
3111
|
+
}
|
|
3112
|
+
const getStores = result.map( ( item ) => item.storeId );
|
|
3113
|
+
if ( !getStores || getStores.length === 0 ) {
|
|
3114
|
+
return res.sendError( 'no data found', 204 );
|
|
3115
|
+
}
|
|
3116
|
+
const getCountQuery = [
|
|
3117
|
+
{
|
|
3118
|
+
$match: {
|
|
3119
|
+
$and: [
|
|
3120
|
+
{
|
|
3121
|
+
storeId: { $in: getStores },
|
|
3122
|
+
},
|
|
3123
|
+
{
|
|
3124
|
+
status: 'reset',
|
|
3125
|
+
},
|
|
3126
|
+
],
|
|
3127
|
+
},
|
|
3128
|
+
},
|
|
3129
|
+
{
|
|
3130
|
+
$sort: {
|
|
3131
|
+
createdAt: -1,
|
|
3132
|
+
},
|
|
3133
|
+
},
|
|
3134
|
+
{
|
|
3135
|
+
$group: {
|
|
3136
|
+
_id: '$storeId',
|
|
3137
|
+
storeId: { $first: '$storeId' },
|
|
3138
|
+
lastRaised: { $first: '$createdAt' },
|
|
3139
|
+
total: { $sum: 1 },
|
|
3140
|
+
|
|
3141
|
+
},
|
|
3142
|
+
},
|
|
3143
|
+
{
|
|
3144
|
+
$project: {
|
|
3145
|
+
_id: 0,
|
|
3146
|
+
storeId: 1,
|
|
3147
|
+
lastRaised: { $dateToString: { format: '%d %b, %Y', date: '$lastRaised' } },
|
|
3148
|
+
totalRaised: '$total',
|
|
3149
|
+
},
|
|
3150
|
+
},
|
|
3151
|
+
];
|
|
3152
|
+
|
|
3153
|
+
const getCounts = await aggregateVmsStoreRequest( getCountQuery );
|
|
3154
|
+
if ( !getCounts || getCounts?.length === 0 ) {
|
|
3155
|
+
return res.sendSuccess( { result: result } );
|
|
3156
|
+
} else {
|
|
3157
|
+
const merged = result.map( ( item ) => {
|
|
3158
|
+
const match = getCounts.find( ( g ) => g.storeId === item.storeId );
|
|
3159
|
+
|
|
3160
|
+
return {
|
|
3161
|
+
...item,
|
|
3162
|
+
...( match || {} ),
|
|
3163
|
+
};
|
|
3164
|
+
} );
|
|
3165
|
+
return res.sendSuccess( { result: merged } );
|
|
3166
|
+
}
|
|
3167
|
+
} catch ( error ) {
|
|
3168
|
+
const err = error.message || 'Internal Server Error';
|
|
3169
|
+
logger.error( { error: error, message: req.query, function: 'listStoreRequest' } );
|
|
3170
|
+
return res.sendError( err, 500 );
|
|
3171
|
+
}
|
|
3172
|
+
}
|
|
3173
|
+
export async function resetStoreRequest( req, res ) {
|
|
3174
|
+
try {
|
|
3175
|
+
const inputData = req.body;
|
|
3176
|
+
for ( const item of inputData?.arrayOfStores ) {
|
|
3177
|
+
await updateOneVmsStoreRequest( { clientId: inputData.clientId, storeId: item.storeId, dateString: item.dateString }, { status: 'reset', appovedBy: req?.user?._id } );
|
|
3178
|
+
}
|
|
3179
|
+
return res.sendSuccess( 'The Request has been reset Successfully' );
|
|
3180
|
+
} catch ( error ) {
|
|
3181
|
+
const err = error.message || 'Internal Server Error';
|
|
3182
|
+
logger.error( { error: error, message: req.body, function: 'resetStoreRequest' } );
|
|
3183
|
+
return res.sendError( err, 500 );
|
|
3184
|
+
}
|
|
3185
|
+
}
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { logger, searchOpenSearchData } from 'tango-app-api-middleware';
|
|
2
|
+
import { findOneStore } from '../service/store.service.js';
|
|
3
|
+
import { aggregatevmsUserAudit, createvmsUserAudit, findOnevmsUserAudit, updateOnevmsUserAudit } from '../service/vmsuserAudit.service.js';
|
|
4
|
+
import { createvmsAuditLog, findOnevmsAuditLog } from '../service/vmsauditLog.service.js';
|
|
5
|
+
import { insertOpenSearchData, clearScroll, scrollResponse } from 'tango-app-api-middleware';
|
|
6
|
+
import { findOneUser } from '../service/user.service.js';
|
|
7
|
+
import dayjs from 'dayjs';
|
|
8
|
+
import utc from 'dayjs/plugin/utc.js';
|
|
9
|
+
import timezone from 'dayjs/plugin/timezone.js';
|
|
10
|
+
|
|
11
|
+
dayjs.extend( utc );
|
|
12
|
+
dayjs.extend( timezone );
|
|
13
|
+
export async function getAuditFile( req, res ) {
|
|
14
|
+
try {
|
|
15
|
+
// const bucket = JSON.parse( process.env.BUCKET );
|
|
16
|
+
const url = JSON.parse( process.env.URL );
|
|
17
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
18
|
+
const inputData = req.query;
|
|
19
|
+
const files = [];
|
|
20
|
+
const storeQuery = {
|
|
21
|
+
storeId: inputData.storeId,
|
|
22
|
+
};
|
|
23
|
+
const storeFields = {
|
|
24
|
+
storeName: 1,
|
|
25
|
+
clientId: 1,
|
|
26
|
+
address: '$storeProfile.address',
|
|
27
|
+
};
|
|
28
|
+
const storeInfo = await findOneStore( storeQuery, storeFields );
|
|
29
|
+
|
|
30
|
+
const userQuery = [
|
|
31
|
+
{
|
|
32
|
+
$match: {
|
|
33
|
+
$and: [
|
|
34
|
+
{ userId: req.user._id },
|
|
35
|
+
{ auditStatus: { $nin: [ 'completed', 'skipped' ] } },
|
|
36
|
+
{ storeId: inputData.storeId },
|
|
37
|
+
{ fileDate: inputData.Date },
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
$sort: { createdAt: -1 },
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
$limit: 1,
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
const userDetails = await aggregatevmsUserAudit( userQuery );
|
|
50
|
+
console.log( '🚀 ~ getAuditFile ~ userDetails:', userDetails );
|
|
51
|
+
const auditStatus = userDetails && userDetails.length > 0 ? userDetails[0].auditStatus : null;
|
|
52
|
+
if ( auditStatus === 'drafted' ) {
|
|
53
|
+
const log = await findOnevmsAuditLog(
|
|
54
|
+
{
|
|
55
|
+
userId: userDetails[0].userId,
|
|
56
|
+
fileDate: userDetails[0].fileDate,
|
|
57
|
+
storeId: userDetails[0].storeId,
|
|
58
|
+
totalCount: userDetails[0].beforeCount,
|
|
59
|
+
},
|
|
60
|
+
{},
|
|
61
|
+
{ createdAt: -1 },
|
|
62
|
+
);
|
|
63
|
+
console.log( '🚀 ~ getAuditFile ~ log:', log );
|
|
64
|
+
if ( !log ) {
|
|
65
|
+
await updateOnevmsUserAudit(
|
|
66
|
+
{ _id: userDetails[0]._id },
|
|
67
|
+
{ $set: { isDraft: false, auditStatus: 'skipped' } },
|
|
68
|
+
);
|
|
69
|
+
logger.info( 'audit update in drafted', {
|
|
70
|
+
_id: userDetails[0]._id,
|
|
71
|
+
isDraft: false,
|
|
72
|
+
auditStatus: 'skipped',
|
|
73
|
+
} );
|
|
74
|
+
return res.sendError( 'User saved data has been deleted', 204 );
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const file = {
|
|
78
|
+
auditId: userDetails[0]._id,
|
|
79
|
+
storeId: userDetails[0].storeId,
|
|
80
|
+
Date: userDetails[0].fileDate,
|
|
81
|
+
userId: log.userId,
|
|
82
|
+
timeSpent: log.timeSpent,
|
|
83
|
+
clientId: userDetails[0].clientId,
|
|
84
|
+
};
|
|
85
|
+
const userdata = await findOneUser( { _id: log.userId } );
|
|
86
|
+
if (
|
|
87
|
+
!inputData.nextId ||
|
|
88
|
+
inputData.nextId === '' ||
|
|
89
|
+
inputData.nextId == null
|
|
90
|
+
) {
|
|
91
|
+
const logData = {
|
|
92
|
+
userId: log.userId,
|
|
93
|
+
userName: userdata.userName,
|
|
94
|
+
logType: 'vmsaudit',
|
|
95
|
+
logSubType: 'auditStart',
|
|
96
|
+
logData: {
|
|
97
|
+
fileDate: userDetails[0].fileDate,
|
|
98
|
+
storeId: userDetails[0].storeId,
|
|
99
|
+
auditId: userDetails[0]._id,
|
|
100
|
+
beforeCount: userDetails[0].beforeCount,
|
|
101
|
+
},
|
|
102
|
+
createdAt: new Date(),
|
|
103
|
+
};
|
|
104
|
+
await insertOpenSearchData( openSearch.vmsauditLog, logData );
|
|
105
|
+
}
|
|
106
|
+
const storeQuery = {
|
|
107
|
+
storeId: userDetails[0].storeId,
|
|
108
|
+
};
|
|
109
|
+
const storeFields = {
|
|
110
|
+
storeId: 1,
|
|
111
|
+
storeName: 1,
|
|
112
|
+
address: '$storeProfile.address',
|
|
113
|
+
};
|
|
114
|
+
const storeDetails = await findOneStore( storeQuery, storeFields );
|
|
115
|
+
return res.sendSuccess( {
|
|
116
|
+
result: log.draftedData,
|
|
117
|
+
storeId: storeDetails?.storeId,
|
|
118
|
+
storeName: storeDetails?.storeName,
|
|
119
|
+
address: storeDetails?.address || '',
|
|
120
|
+
count: log.totalCount,
|
|
121
|
+
timeSpent: log.timeSpent,
|
|
122
|
+
file: file,
|
|
123
|
+
isDraft: userDetails[0].isDraft,
|
|
124
|
+
} );
|
|
125
|
+
}
|
|
126
|
+
console.log( inputData );
|
|
127
|
+
|
|
128
|
+
const query = {
|
|
129
|
+
size: inputData?.limit || 2,
|
|
130
|
+
_source: [ 'module', 'status', 'date', 'store_id', 'outputCluster', 'personPath', 'REIDCluster', 'isEmployee', 'isJunk', 'EmployeeStatusFinal' ], // Only fetch necessary fields
|
|
131
|
+
|
|
132
|
+
query: {
|
|
133
|
+
bool: {
|
|
134
|
+
'must': [
|
|
135
|
+
{
|
|
136
|
+
term: { 'store_id.keyword': inputData.storeId },
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
term: { 'date.keyword': dayjs( inputData.Date ).format( 'DD-MM-YYYY' ) },
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
term: { 'module.keyword': 'CUSTOMER' },
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
term: { 'status.keyword': 'PP_CLUSTER_FORMED' },
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
terms: { EmployeeStatusFinal: [ 1, 2 ] },
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
'should': [
|
|
152
|
+
{ 'term': { 'isJunk': false } },
|
|
153
|
+
{ 'bool': { 'must_not': { 'exists': { 'field': 'isJunk' } } } },
|
|
154
|
+
],
|
|
155
|
+
'minimum_should_match': 1,
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
};
|
|
160
|
+
console.log( openSearch.vmsAudit );
|
|
161
|
+
let list =inputData.nextId? await scrollResponse( inputData.nextId ): await searchOpenSearchData( openSearch.vmsAudit, query );
|
|
162
|
+
const folderPath = list?.body?.hits?.hits;
|
|
163
|
+
if ( list?.body?.hits?.hits?.length ==0 ) {
|
|
164
|
+
await clearScroll( list?.body?._scroll_id );
|
|
165
|
+
}
|
|
166
|
+
if ( folderPath?.length > 0 ) {
|
|
167
|
+
for ( let i = 0; i < folderPath.length; i++ ) {
|
|
168
|
+
const img = folderPath[i]?._source?.personPath?.split( '/' );
|
|
169
|
+
const image = img[3]?.split( '.' );
|
|
170
|
+
const indexes = folderPath[i]?._source?.outputCluster === 50000 ? folderPath[i]?._source?.REIDCluster : folderPath[i]?._source?.outputCluster;
|
|
171
|
+
// fetchData.file_path = folderPath[i]?._source?.personPath;
|
|
172
|
+
const data = `${url.trackInput}${folderPath[i]?._source?.personPath}`;
|
|
173
|
+
const mapimg = {
|
|
174
|
+
img_path: data,
|
|
175
|
+
img_name: indexes,
|
|
176
|
+
img_id: image[0],
|
|
177
|
+
};
|
|
178
|
+
addUniqueFile( files, {
|
|
179
|
+
img_path: data,
|
|
180
|
+
img_name: indexes,
|
|
181
|
+
img_id: image[0],
|
|
182
|
+
selected: false,
|
|
183
|
+
dropped: false,
|
|
184
|
+
demographic: '',
|
|
185
|
+
count: 1,
|
|
186
|
+
mappedid: [ mapimg ],
|
|
187
|
+
} );
|
|
188
|
+
}
|
|
189
|
+
} else if ( inputData.nextId !== '' && inputData.nextId !== null && inputData.nextId !== undefined ) {
|
|
190
|
+
if ( !list ) {
|
|
191
|
+
return res.sendError( 'token expired', 404 );
|
|
192
|
+
}
|
|
193
|
+
list.body._scroll_id = '';
|
|
194
|
+
// insertData = userDetails[0];
|
|
195
|
+
} else {
|
|
196
|
+
logger.error( {
|
|
197
|
+
error: { folderPath: folderPath, nextQuery: inputData.nextId },
|
|
198
|
+
function: 'getAuditFile',
|
|
199
|
+
message: 'Bucket image data not availale',
|
|
200
|
+
} );
|
|
201
|
+
return res.sendError( 'Bucket is Empty', 204 );
|
|
202
|
+
}
|
|
203
|
+
const [ year, month, day ] = inputData.Date.split( '-' );
|
|
204
|
+
const temp = `${year}-${month}-${day}`;
|
|
205
|
+
console.log( temp );
|
|
206
|
+
let start = new Date( temp );
|
|
207
|
+
const userTimezoneOffset = start.getTimezoneOffset() * 60000;
|
|
208
|
+
start = new Date( start.getTime() - userTimezoneOffset );
|
|
209
|
+
start.setUTCHours( 0, 0, 0, 0 );
|
|
210
|
+
console.log( start );
|
|
211
|
+
const record = {
|
|
212
|
+
userId: req.user._id,
|
|
213
|
+
storeId: inputData.storeId,
|
|
214
|
+
clientId: storeInfo?.clientId,
|
|
215
|
+
fileDate: inputData.Date,
|
|
216
|
+
beforeCount: inputData.count,
|
|
217
|
+
auditStatus: 'inprogress',
|
|
218
|
+
fileDateISO: start,
|
|
219
|
+
timeSpent: 0,
|
|
220
|
+
startTime: new Date(),
|
|
221
|
+
};
|
|
222
|
+
const insertData = await createvmsUserAudit( record );
|
|
223
|
+
if ( inputData.nextId !== '' && inputData.nextId !== null && inputData.nextId !== undefined && inputData.moduleType === 'track' ) {
|
|
224
|
+
if ( !list ) {
|
|
225
|
+
return res.sendError( 'token expired', 404 );
|
|
226
|
+
}
|
|
227
|
+
list.body._scroll_id = '';
|
|
228
|
+
}
|
|
229
|
+
return res.sendSuccess( {
|
|
230
|
+
result: files,
|
|
231
|
+
count: inputData.count,
|
|
232
|
+
storeId: inputData.storeId,
|
|
233
|
+
storeName: storeInfo?.storeName,
|
|
234
|
+
address: storeInfo?.address,
|
|
235
|
+
file: {
|
|
236
|
+
clientId: storeInfo?.clientId,
|
|
237
|
+
storeId: inputData.storeId,
|
|
238
|
+
Date: inputData.Date,
|
|
239
|
+
auditId: insertData._id,
|
|
240
|
+
userId: insertData.userId,
|
|
241
|
+
nextToken: list?.body?._scroll_id ?list?.body?._scroll_id:null,
|
|
242
|
+
|
|
243
|
+
},
|
|
244
|
+
isDraft: insertData.isDraft,
|
|
245
|
+
} );
|
|
246
|
+
} catch ( error ) {
|
|
247
|
+
const err = error.message || 'Internal Server Error';
|
|
248
|
+
logger.error( {
|
|
249
|
+
error: error,
|
|
250
|
+
message: req.query,
|
|
251
|
+
function: 'getAuditFile',
|
|
252
|
+
} );
|
|
253
|
+
return res.sendError( err, 500 );
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function addUniqueFile( files, newFile ) {
|
|
257
|
+
const exists = files.some( ( file ) => file.img_name === newFile.img_name );
|
|
258
|
+
if ( !exists ) {
|
|
259
|
+
files.push( newFile );
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
export async function saveDraft( req, res ) {
|
|
263
|
+
try {
|
|
264
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
265
|
+
const inputData = req.body;
|
|
266
|
+
inputData.userId = req.user._id;
|
|
267
|
+
const getUserAuditData = await findOnevmsUserAudit( { _id: inputData.auditId } );
|
|
268
|
+
if ( !getUserAuditData ) {
|
|
269
|
+
return res.sendError( 'No Data Found', 204 );
|
|
270
|
+
}
|
|
271
|
+
if ( getUserAuditData.auditStatus == 'skipped' ) {
|
|
272
|
+
return res.sendError( 'File Assigned to Someone else', 203 );
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const userQuery = {
|
|
276
|
+
_id: inputData.auditId,
|
|
277
|
+
};
|
|
278
|
+
let userRecord = {
|
|
279
|
+
isDraft: true,
|
|
280
|
+
auditStatus: 'drafted',
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
if ( getUserAuditData?.startTime ) {
|
|
285
|
+
userRecord.timeSpent = inputData.timeSpent;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if ( inputData.userCommands ) {
|
|
289
|
+
userRecord.userCommands = inputData.userCommands;
|
|
290
|
+
const logData = {
|
|
291
|
+
userId: req.user._id,
|
|
292
|
+
userName: req.user.userName,
|
|
293
|
+
logType: 'vmsaudit',
|
|
294
|
+
logSubType: 'auditDraft',
|
|
295
|
+
logData: {
|
|
296
|
+
fileDate: inputData.fileDate,
|
|
297
|
+
storeId: inputData.storeId,
|
|
298
|
+
beforeCount: inputData.totalCount,
|
|
299
|
+
afterCount: inputData.customerCount,
|
|
300
|
+
timeSpent: inputData.timeSpent,
|
|
301
|
+
auditId: inputData.auditId,
|
|
302
|
+
},
|
|
303
|
+
createdAt: new Date(),
|
|
304
|
+
};
|
|
305
|
+
await insertOpenSearchData( openSearch.vmsauditLog, logData );
|
|
306
|
+
}
|
|
307
|
+
await createvmsAuditLog( inputData );
|
|
308
|
+
await updateOnevmsUserAudit( userQuery, userRecord );
|
|
309
|
+
console.log( '🚀 ~ saveDraft ~ userRecord:', userRecord );
|
|
310
|
+
return res.sendSuccess( {
|
|
311
|
+
result: 'The file has been drafted successfully',
|
|
312
|
+
} );
|
|
313
|
+
} catch ( error ) {
|
|
314
|
+
const err = error.message || 'Internal Server Error';
|
|
315
|
+
logger.error( { error: error, message: req.body, function: 'saveDraft' } );
|
|
316
|
+
return res.sendError( err, 500 );
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
export async function getDraftedData( req, res ) {
|
|
320
|
+
try {
|
|
321
|
+
const inputData = req.query;
|
|
322
|
+
const userId = inputData.userId || req.user._id;
|
|
323
|
+
const query = {
|
|
324
|
+
fileDate: inputData.fileDate,
|
|
325
|
+
storeId: inputData.storeId,
|
|
326
|
+
userId: userId,
|
|
327
|
+
auditId: inputData.auditId,
|
|
328
|
+
};
|
|
329
|
+
console.log( query );
|
|
330
|
+
const result = await findOnevmsAuditLog( query, {}, { createdAt: -1 }, 1 );
|
|
331
|
+
|
|
332
|
+
if ( !result ) {
|
|
333
|
+
return res.sendError( 'No Data Found', 204 );
|
|
334
|
+
}
|
|
335
|
+
return res.sendSuccess( { result: result } );
|
|
336
|
+
} catch ( error ) {
|
|
337
|
+
const err = error.message || 'Internal Server Error';
|
|
338
|
+
logger.error( {
|
|
339
|
+
error: error,
|
|
340
|
+
message: req.query,
|
|
341
|
+
function: 'getDraftedData',
|
|
342
|
+
} );
|
|
343
|
+
return res.sendError( err, 500 );
|
|
344
|
+
}
|
|
345
|
+
}
|
package/src/dtos/client.dtos.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import joi from 'joi';
|
|
2
|
+
import dayjs from 'dayjs';
|
|
2
3
|
|
|
3
4
|
export const clientDetailsSchema = joi.object( {
|
|
4
5
|
id: joi.string().required(),
|
|
@@ -359,12 +360,15 @@ export const updateFDConfigBodySchema = joi.object( {
|
|
|
359
360
|
tangoReview: joi.string().optional(),
|
|
360
361
|
revision: joi.array().items( joi.object( {
|
|
361
362
|
actionType: joi.string().required(),
|
|
362
|
-
isChecked: joi.boolean().
|
|
363
|
+
isChecked: joi.boolean().optional().default( false ),
|
|
363
364
|
} ) ).optional(),
|
|
364
365
|
taggingLimitation: joi.array().items( joi.object( {
|
|
366
|
+
iconName: joi.string().optional(),
|
|
367
|
+
name: joi.string().optional(),
|
|
365
368
|
type: joi.string().required(),
|
|
366
369
|
value: joi.number().required(),
|
|
367
370
|
unit: joi.string().required(),
|
|
371
|
+
key: joi.string().required(),
|
|
368
372
|
} ) ).optional(),
|
|
369
373
|
|
|
370
374
|
} );
|
|
@@ -404,3 +408,50 @@ export const updateTaggingTypeValid = {
|
|
|
404
408
|
body: updateTaggingTypeSchema,
|
|
405
409
|
query: updateTaggingTypeQuerySchema,
|
|
406
410
|
};
|
|
411
|
+
|
|
412
|
+
export const createStoreRequestSchema = joi.object( {
|
|
413
|
+
storeId: joi.string().required(),
|
|
414
|
+
dateString: joi.string().required().custom( ( value, helpers ) => {
|
|
415
|
+
const inputDate = dayjs( value, 'YYYY-MM-DD', true );
|
|
416
|
+
const today = dayjs();
|
|
417
|
+
|
|
418
|
+
if ( !inputDate.isValid() ) {
|
|
419
|
+
return helpers.error( 'any.invalid' );
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const diff = today.diff( inputDate, 'day' );
|
|
423
|
+
|
|
424
|
+
if ( diff > 3 ) {
|
|
425
|
+
return helpers.message( 'The request is not sent for a period exceeding 3 days' );
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
return value;
|
|
429
|
+
} ),
|
|
430
|
+
|
|
431
|
+
} );
|
|
432
|
+
|
|
433
|
+
export const createStoreRequestValid = {
|
|
434
|
+
body: createStoreRequestSchema,
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
export const listStoreRequestSchema = joi.object( {
|
|
438
|
+
clientId: joi.string().required(),
|
|
439
|
+
} );
|
|
440
|
+
|
|
441
|
+
export const listStoreRequestValid = {
|
|
442
|
+
query: listStoreRequestSchema,
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
export const resetStoreRequestSchema = joi.object( {
|
|
446
|
+
clientId: joi.string().required(),
|
|
447
|
+
arrayOfStores: joi.array().items(
|
|
448
|
+
joi.object( {
|
|
449
|
+
storeId: joi.string().required(),
|
|
450
|
+
dateString: joi.string().required(),
|
|
451
|
+
} ),
|
|
452
|
+
).required(),
|
|
453
|
+
} );
|
|
454
|
+
|
|
455
|
+
export const resetStoreRequestValid = {
|
|
456
|
+
body: resetStoreRequestSchema,
|
|
457
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
import joi from 'joi';
|
|
3
|
+
export const getDraftedDataSchema = joi.object( {
|
|
4
|
+
storeId: joi.string().required(),
|
|
5
|
+
fileDate: joi.string().required(),
|
|
6
|
+
userId: joi.string().optional(),
|
|
7
|
+
auditId: joi.string().required(),
|
|
8
|
+
} );
|
|
9
|
+
export const getFileSchema = joi.object( {
|
|
10
|
+
nextId: joi.string().optional().allow( '' ),
|
|
11
|
+
limit: joi.number().optional(),
|
|
12
|
+
storeId: joi.string().required(),
|
|
13
|
+
Date: joi.string().required(),
|
|
14
|
+
count: joi.string().required(),
|
|
15
|
+
} );
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export const getDraftedDataValid = {
|
|
19
|
+
query: getDraftedDataSchema,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const getFileValid = {
|
|
23
|
+
query: getFileSchema,
|
|
24
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import { activityLogValid, auditConfigValid, billingDetailsValid, brandInfoValid, clientCreationValid, clientDetailsValid, documentsValid, domainDetailsValid, featureConfigurationValid, getAssignedClientValid, getAuditConfigValid, getFDConfigValid, postClientCamApprovalValid, signatoryDetailsValid, ticketConfigurationValid, updateFDConfigValid, updateTaggingTypeValid, userConfigurationValid } from '../dtos/client.dtos.js';
|
|
4
|
-
import { auditConfiguration, changeStatus, clientCsmAssignAction, clientDetails, create, csmAssignConfirmation, domainDetailsConfiguration, getActivityLogs, getAuditConfiguration, getClients, getCsmUsers, getFDConfig, getOpsUsers, updateBillingDetails, updateBrandInfo, updateDocuments, updateFDConfig, updateFeatureConfiguration, updateSignatoryDetails, updateTaggingType, updateTicketConfiguration, userConfiguration } from '../controllers/client.controllers.js';
|
|
3
|
+
import { activityLogValid, auditConfigValid, billingDetailsValid, brandInfoValid, clientCreationValid, clientDetailsValid, createStoreRequestValid, documentsValid, domainDetailsValid, featureConfigurationValid, getAssignedClientValid, getAuditConfigValid, getFDConfigValid, listStoreRequestValid, postClientCamApprovalValid, resetStoreRequestValid, signatoryDetailsValid, ticketConfigurationValid, updateFDConfigValid, updateTaggingTypeValid, userConfigurationValid } from '../dtos/client.dtos.js';
|
|
4
|
+
import { auditConfiguration, changeStatus, clientCsmAssignAction, clientDetails, create, createStoreRequest, csmAssignConfirmation, domainDetailsConfiguration, getActivityLogs, getAuditConfiguration, getClients, getCsmUsers, getFDConfig, getOpsUsers, listStoreRequest, resetStoreRequest, updateBillingDetails, updateBrandInfo, updateDocuments, updateFDConfig, updateFeatureConfiguration, updateSignatoryDetails, updateTaggingType, updateTicketConfiguration, userConfiguration } from '../controllers/client.controllers.js';
|
|
5
5
|
import { accessVerification, isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
6
6
|
import { clientListValid, detailedClientCountValid, createAuditConfigValid, AuditConfiglistValid, revopconfigValid, revopconfiggetValid } from '../dtos/client.dtos.js';
|
|
7
7
|
import { isclientIdExists, isclientNameExists, roleVerification } from '../validations/client.validations.js';
|
|
@@ -117,3 +117,7 @@ clientRouter.put( '/update-footfall-directory-config', isAllowedSessionHandler,
|
|
|
117
117
|
clientRouter.get( '/get-footfall-directory-config', isAllowedSessionHandler, validate( getFDConfigValid ), getFDConfig );
|
|
118
118
|
clientRouter.put( '/update-tagging-type/', isAllowedSessionHandler, validate( updateTaggingTypeValid ), updateTaggingType );
|
|
119
119
|
|
|
120
|
+
// store request create/list/reset
|
|
121
|
+
clientRouter.post( '/create-store-request', isAllowedSessionHandler, validate( createStoreRequestValid ), createStoreRequest );
|
|
122
|
+
clientRouter.get( '/list-store-request', isAllowedSessionHandler, validate( listStoreRequestValid ), listStoreRequest );
|
|
123
|
+
clientRouter.post( '/reset-store-request', isAllowedSessionHandler, validate( resetStoreRequestValid ), resetStoreRequest );
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { accessVerification, isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
3
|
+
import { getDraftedDataValid, getFileValid } from '../dtos/vmsAudit.dtos.js';
|
|
4
|
+
import { getAuditFile, getDraftedData, saveDraft } from '../controllers/vmsAudit.controller.js';
|
|
5
|
+
export const vmsauditRouter = express.Router();
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
vmsauditRouter.get( '/get-file', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( getFileValid ), getAuditFile );
|
|
9
|
+
vmsauditRouter.post( '/save-draft', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), saveDraft );
|
|
10
|
+
vmsauditRouter.get( '/get-drafted-data', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( getDraftedDataValid ), getDraftedData );
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import vmsStoreRequestModel from 'tango-api-schema/schema/vmsStoreRequest.model.js';
|
|
2
|
+
|
|
3
|
+
export async function updateOneUpsertVmsStoreRequest( query, record ) {
|
|
4
|
+
return await vmsStoreRequestModel.updateOne( query, { $set: record }, { upsert: true } );
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export async function updateOneVmsStoreRequest( query, record ) {
|
|
8
|
+
return await vmsStoreRequestModel.updateOne( query, { $set: record } );
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export async function aggregateVmsStoreRequest( query ) {
|
|
12
|
+
return await vmsStoreRequestModel.aggregate( query );
|
|
13
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import vmsauditLogsModel from 'tango-api-schema/schema/vmsauditLogs.model.js';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export function createvmsAuditLog( record ) {
|
|
5
|
+
return vmsauditLogsModel.create( record );
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function findOnevmsAuditLog( query, fields={}, sort={ createdAt: -1 }, limit=10 ) {
|
|
9
|
+
return vmsauditLogsModel.findOne( query, fields ).sort( sort ).limit( limit );
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import vmsuserAuditModel from 'tango-api-schema/schema/vmsuserAudit.model.js';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export function aggregatevmsUserAudit( query ) {
|
|
5
|
+
return vmsuserAuditModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function updateOnevmsUserAudit( query, record ) {
|
|
9
|
+
return vmsuserAuditModel.updateOne( query, { $set: record } );
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function createvmsUserAudit( record ) {
|
|
13
|
+
return vmsuserAuditModel.create( record );
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function findOnevmsUserAudit( query, fields ) {
|
|
17
|
+
return vmsuserAuditModel.findOne( query, fields );
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function aggregatevmsUserAuditCount( query ) {
|
|
21
|
+
return vmsuserAuditModel.aggregate( query );
|
|
22
|
+
}
|