tango-app-api-client 3.6.5-vms.0 → 3.6.5-vms.2
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-client",
|
|
3
|
-
"version": "3.6.5-vms.
|
|
3
|
+
"version": "3.6.5-vms.2",
|
|
4
4
|
"description": "client",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -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",
|
|
@@ -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';
|
|
@@ -18,6 +18,8 @@ import { countDocumentsClusters, createclusterModel } from '../service/cluster.s
|
|
|
18
18
|
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
|
+
import clientModel from 'tango-api-schema/schema/client.model.js';
|
|
22
|
+
import { aggregateVmsStoreRequest, updateOneUpsertVmsStoreRequest, updateOneVmsStoreRequest } from '../service/vmsStoreRequest.service.js';
|
|
21
23
|
|
|
22
24
|
export async function create( req, res ) {
|
|
23
25
|
try {
|
|
@@ -2977,3 +2979,206 @@ export async function getFDConfig( req, res ) {
|
|
|
2977
2979
|
}
|
|
2978
2980
|
}
|
|
2979
2981
|
|
|
2982
|
+
|
|
2983
|
+
export async function updateTaggingType( req, res ) {
|
|
2984
|
+
try {
|
|
2985
|
+
const inputData = req.body;
|
|
2986
|
+
|
|
2987
|
+
const inputQuery = req.query; // up
|
|
2988
|
+
const types = inputData?.taggingLimitation?.map( ( x ) => x.type );
|
|
2989
|
+
// Step 1: remove existing items with same "type"
|
|
2990
|
+
await clientModel.updateOne(
|
|
2991
|
+
{ clientId: inputQuery.clientId },
|
|
2992
|
+
{
|
|
2993
|
+
$pull: {
|
|
2994
|
+
'footfallDirectoryConfigs.taggingLimitation': {
|
|
2995
|
+
type: { $in: types },
|
|
2996
|
+
},
|
|
2997
|
+
},
|
|
2998
|
+
},
|
|
2999
|
+
);
|
|
3000
|
+
|
|
3001
|
+
// Remove duplicate entries by type
|
|
3002
|
+
const uniqueData = uniqueByType( inputData.taggingLimitation );
|
|
3003
|
+
|
|
3004
|
+
// Step 2: insert fresh new items
|
|
3005
|
+
let result =await clientModel.updateOne(
|
|
3006
|
+
{ clientId: inputQuery.clientId },
|
|
3007
|
+
{
|
|
3008
|
+
$addToSet: {
|
|
3009
|
+
'footfallDirectoryConfigs.taggingLimitation': {
|
|
3010
|
+
$each: uniqueData,
|
|
3011
|
+
},
|
|
3012
|
+
},
|
|
3013
|
+
},
|
|
3014
|
+
);
|
|
3015
|
+
|
|
3016
|
+
if ( result?.acknowledged === true ) {
|
|
3017
|
+
return res.sendSuccess( result );
|
|
3018
|
+
} else {
|
|
3019
|
+
return res.sendError( 'no data', 204 );
|
|
3020
|
+
}
|
|
3021
|
+
} catch ( error ) {
|
|
3022
|
+
const err = error.message || 'Internal Server Error';
|
|
3023
|
+
logger.error( { error: error, message: req.query, function: 'updateTaggingType' } );
|
|
3024
|
+
return res.sendError( err, 500 );
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
|
|
3028
|
+
function uniqueByType( arr ) {
|
|
3029
|
+
const seen = new Set();
|
|
3030
|
+
return arr.filter( ( item ) => {
|
|
3031
|
+
if ( seen.has( item.type ) ) return false;
|
|
3032
|
+
seen.add( item.type );
|
|
3033
|
+
return true;
|
|
3034
|
+
} );
|
|
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
|
+
storeName: 1,
|
|
3100
|
+
storeId: 1,
|
|
3101
|
+
dateString: 1,
|
|
3102
|
+
raisedOn: { $ifNull: [ { $dateToString: { format: '%d %b, %Y', date: '$createdAt' } }, '' ] },
|
|
3103
|
+
totalRaised: null,
|
|
3104
|
+
},
|
|
3105
|
+
},
|
|
3106
|
+
];
|
|
3107
|
+
const result = await aggregateVmsStoreRequest( query );
|
|
3108
|
+
if ( !result || result.length === 0 ) {
|
|
3109
|
+
return res.sendError( 'no data found', 204 );
|
|
3110
|
+
}
|
|
3111
|
+
const getStores = result.map( ( item ) => item.storeId );
|
|
3112
|
+
if ( !getStores || getStores.length === 0 ) {
|
|
3113
|
+
return res.sendError( 'no data found', 204 );
|
|
3114
|
+
}
|
|
3115
|
+
const getCountQuery = [
|
|
3116
|
+
{
|
|
3117
|
+
$match: {
|
|
3118
|
+
$and: [
|
|
3119
|
+
{
|
|
3120
|
+
storeId: { $in: getStores },
|
|
3121
|
+
},
|
|
3122
|
+
{
|
|
3123
|
+
status: 'reset',
|
|
3124
|
+
},
|
|
3125
|
+
],
|
|
3126
|
+
},
|
|
3127
|
+
},
|
|
3128
|
+
{
|
|
3129
|
+
$sort: {
|
|
3130
|
+
createdAt: -1,
|
|
3131
|
+
},
|
|
3132
|
+
},
|
|
3133
|
+
{
|
|
3134
|
+
$group: {
|
|
3135
|
+
_id: '$storeId',
|
|
3136
|
+
storeId: { $first: '$storeId' },
|
|
3137
|
+
lastRaised: { $first: '$createdAt' },
|
|
3138
|
+
total: { $sum: 1 },
|
|
3139
|
+
|
|
3140
|
+
},
|
|
3141
|
+
},
|
|
3142
|
+
{
|
|
3143
|
+
$project: {
|
|
3144
|
+
_id: 0,
|
|
3145
|
+
storeId: 1,
|
|
3146
|
+
lastRaised: { $dateToString: { format: '%d %b, %Y', date: '$lastRaised' } },
|
|
3147
|
+
totalRaised: '$total',
|
|
3148
|
+
},
|
|
3149
|
+
},
|
|
3150
|
+
];
|
|
3151
|
+
|
|
3152
|
+
const getCounts = await aggregateVmsStoreRequest( getCountQuery );
|
|
3153
|
+
if ( !getCounts || getCounts?.length === 0 ) {
|
|
3154
|
+
return res.sendSuccess( { result: result } );
|
|
3155
|
+
} else {
|
|
3156
|
+
const merged = result.map( ( item ) => {
|
|
3157
|
+
const match = getCounts.find( ( g ) => g.storeId === item.storeId );
|
|
3158
|
+
|
|
3159
|
+
return {
|
|
3160
|
+
...item,
|
|
3161
|
+
...( match || {} ),
|
|
3162
|
+
};
|
|
3163
|
+
} );
|
|
3164
|
+
return res.sendSuccess( { result: merged } );
|
|
3165
|
+
}
|
|
3166
|
+
} catch ( error ) {
|
|
3167
|
+
const err = error.message || 'Internal Server Error';
|
|
3168
|
+
logger.error( { error: error, message: req.query, function: 'listStoreRequest' } );
|
|
3169
|
+
return res.sendError( err, 500 );
|
|
3170
|
+
}
|
|
3171
|
+
}
|
|
3172
|
+
export async function resetStoreRequest( req, res ) {
|
|
3173
|
+
try {
|
|
3174
|
+
const inputData = req.body;
|
|
3175
|
+
for ( const item of inputData?.arrayOfStores ) {
|
|
3176
|
+
await updateOneVmsStoreRequest( { clientId: inputData.clientId, storeId: item.storeId, dateString: item.dateString }, { status: 'reset', appovedBy: req?.user?._id } );
|
|
3177
|
+
}
|
|
3178
|
+
return res.sendSuccess( 'The Request has been reset Successfully' );
|
|
3179
|
+
} catch ( error ) {
|
|
3180
|
+
const err = error.message || 'Internal Server Error';
|
|
3181
|
+
logger.error( { error: error, message: req.body, function: 'resetStoreRequest' } );
|
|
3182
|
+
return res.sendError( err, 500 );
|
|
3183
|
+
}
|
|
3184
|
+
}
|
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(),
|
|
@@ -384,3 +385,70 @@ export const updateFDConfigValid = {
|
|
|
384
385
|
export const getFDConfigValid = {
|
|
385
386
|
query: getFDConfigSchema,
|
|
386
387
|
};
|
|
388
|
+
|
|
389
|
+
export const updateTaggingTypeSchema = joi.object( {
|
|
390
|
+
clientId: joi.string().required(),
|
|
391
|
+
taggingLimitation: joi.array().items( joi.object( {
|
|
392
|
+
type: joi.string().required(),
|
|
393
|
+
value: joi.number().required(),
|
|
394
|
+
unit: joi.string().required(),
|
|
395
|
+
} ) ).required(),
|
|
396
|
+
|
|
397
|
+
} );
|
|
398
|
+
|
|
399
|
+
export const updateTaggingTypeQuerySchema = joi.object( {
|
|
400
|
+
clientId: joi.string().required(),
|
|
401
|
+
} );
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
export const updateTaggingTypeValid = {
|
|
405
|
+
body: updateTaggingTypeSchema,
|
|
406
|
+
query: updateTaggingTypeQuerySchema,
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
export const createStoreRequestSchema = joi.object( {
|
|
410
|
+
storeId: joi.string().required(),
|
|
411
|
+
dateString: joi.string().required().custom( ( value, helpers ) => {
|
|
412
|
+
const inputDate = dayjs( value, 'YYYY-MM-DD', true );
|
|
413
|
+
const today = dayjs();
|
|
414
|
+
|
|
415
|
+
if ( !inputDate.isValid() ) {
|
|
416
|
+
return helpers.error( 'any.invalid' );
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const diff = today.diff( inputDate, 'day' );
|
|
420
|
+
|
|
421
|
+
if ( diff > 3 ) {
|
|
422
|
+
return helpers.message( 'The request is not sent for a period exceeding 3 days' );
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return value;
|
|
426
|
+
} ),
|
|
427
|
+
|
|
428
|
+
} );
|
|
429
|
+
|
|
430
|
+
export const createStoreRequestValid = {
|
|
431
|
+
body: createStoreRequestSchema,
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
export const listStoreRequestSchema = joi.object( {
|
|
435
|
+
clientId: joi.string().required(),
|
|
436
|
+
} );
|
|
437
|
+
|
|
438
|
+
export const listStoreRequestValid = {
|
|
439
|
+
query: listStoreRequestSchema,
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
export const resetStoreRequestSchema = joi.object( {
|
|
443
|
+
clientId: joi.string().required(),
|
|
444
|
+
arrayOfStores: joi.array().items(
|
|
445
|
+
joi.object( {
|
|
446
|
+
storeId: joi.string().required(),
|
|
447
|
+
dateString: joi.string().required(),
|
|
448
|
+
} ),
|
|
449
|
+
).required(),
|
|
450
|
+
} );
|
|
451
|
+
|
|
452
|
+
export const resetStoreRequestValid = {
|
|
453
|
+
body: resetStoreRequestSchema,
|
|
454
|
+
};
|
|
@@ -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, 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, 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';
|
|
@@ -115,4 +115,9 @@ clientRouter.get( '/revopconfig', isAllowedSessionHandler,
|
|
|
115
115
|
// footfall directory configurations
|
|
116
116
|
clientRouter.put( '/update-footfall-directory-config', isAllowedSessionHandler, validate( updateFDConfigValid ), updateFDConfig );
|
|
117
117
|
clientRouter.get( '/get-footfall-directory-config', isAllowedSessionHandler, validate( getFDConfigValid ), getFDConfig );
|
|
118
|
+
clientRouter.put( '/update-tagging-type/', isAllowedSessionHandler, validate( updateTaggingTypeValid ), updateTaggingType );
|
|
118
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,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
|
+
};
|