tango-app-api-infra 3.0.38-dev → 3.0.39-dev

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-infra",
3
- "version": "3.0.38-dev",
3
+ "version": "3.0.39-dev",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -6,9 +6,10 @@ import timezone from 'dayjs/plugin/timezone.js';
6
6
  import 'dayjs/locale/en.js';
7
7
  dayjs.extend( utc );
8
8
  dayjs.extend( timezone );
9
- import { createClient, findClient } from '../services/client.service.js';
9
+ import { createClient, findClient, aggregateClient } from '../services/client.service.js';
10
10
  import { createStore, findStore, updateOneStore } from '../services/store.service.js';
11
11
  import { findTangoTicket, findOneTangoTicket, updateOneTangoTicket } from '../services/tangoTicket.service.js';
12
+ import { findOneGroup } from '../services/group.service.js';
12
13
 
13
14
 
14
15
  export async function migrateClient() {
@@ -175,3 +176,139 @@ export async function closeTicket( req, res ) {
175
176
  res.sendError( error, 500 );
176
177
  }
177
178
  }
179
+ export async function emailUserList( req, res ) {
180
+ try {
181
+ let clientList = await aggregateClient( [
182
+ {
183
+ $match: {
184
+ status: 'active',
185
+ // clientId:{ req.body.clientId},
186
+ },
187
+ },
188
+ {
189
+ $project: {
190
+ 'clientId': 1,
191
+ 'ticketConfigs.infraReport': 1,
192
+ },
193
+ },
194
+ {
195
+ '$lookup': {
196
+ 'from': 'users',
197
+ 'let': { 'clientId': '$clientId' },
198
+ 'pipeline': [
199
+ {
200
+ '$match': {
201
+ '$expr': {
202
+ $and: [
203
+ { '$eq': [ '$clientId', '$$clientId' ] },
204
+ { '$eq': [ '$userType', 'client' ] },
205
+
206
+ ],
207
+ },
208
+ },
209
+ },
210
+ {
211
+ $project: {
212
+ userName: 1,
213
+ email: 1,
214
+ role: 1,
215
+ },
216
+ },
217
+ ],
218
+ 'as': 'user',
219
+ },
220
+ },
221
+ {
222
+ $unwind: {
223
+ path: '$user',
224
+ preserveNullAndEmptyArrays: true,
225
+ },
226
+ },
227
+ {
228
+ '$lookup': {
229
+ 'from': 'userAssignedStore',
230
+ 'let': { 'email': '$user.email' },
231
+ 'pipeline': [
232
+ {
233
+ '$match': {
234
+ '$expr': {
235
+ $and: [
236
+ { '$eq': [ '$userEmail', '$$email' ] },
237
+
238
+ ],
239
+ },
240
+ },
241
+ },
242
+ {
243
+ $project: {
244
+ assignedValue: 1,
245
+ assignedType: 1,
246
+ },
247
+ },
248
+ ],
249
+ 'as': 'assignedstore',
250
+ },
251
+ },
252
+ {
253
+ $unwind: {
254
+ path: '$assignedstore',
255
+ preserveNullAndEmptyArrays: true,
256
+ },
257
+ },
258
+ {
259
+ $project: {
260
+ 'clientId': 1,
261
+ 'ticketConfigs': 1,
262
+ 'email': '$user.email',
263
+ 'role': '$user.role',
264
+ 'assignedValue': '$assignedstore.assignedValue',
265
+ 'assignedType': '$assignedstore.assignedType',
266
+ },
267
+ },
268
+ {
269
+ $group: {
270
+ '_id': '$email',
271
+ 'clientId': { $first: '$clientId' },
272
+ 'ticketConfigs': { $first: '$ticketConfigs' },
273
+ 'email': { $first: '$email' },
274
+ 'role': { $first: '$role' },
275
+ 'assignedValue': { $push: '$assignedValue' },
276
+ 'assignedType': { $first: '$assignedType' },
277
+ },
278
+ },
279
+ ] );
280
+ let response = [];
281
+ for ( let user of clientList ) {
282
+ if ( user.role == 'superadmin' ) {
283
+ let storelist = await findStore( { clientId: user.clientId }, { 'storeId': 1, 'storeProfile.timeZone': 1 } );
284
+ user.storeList = storelist;
285
+ } else if ( user.role != 'superadmin' ) {
286
+ if ( user.assignedType == 'store' ) {
287
+ let storelist = await findStore( { storeId: { $in: user.assignedValue } }, { 'storeId': 1, 'storeProfile.timeZone': 1 } );
288
+ user.storeList = storelist;
289
+ }
290
+ if ( user.assignedType == 'group' ) {
291
+ user.storeList = [];
292
+ for ( let group of user.assignedValue ) {
293
+ let groupdata = await findOneGroup( { groupName: group } );
294
+ let storelist = await findStore( { storeId: { $in: groupdata.storeList } }, { 'storeId': 1, 'storeProfile.timeZone': 1 } );
295
+ user.storeList = [ ...user.storeList, ...storelist ];
296
+ }
297
+ }
298
+ }
299
+ if ( user.storeList&&user.storeList.length>0&&user.ticketConfigs&&user.ticketConfigs.infraReport ) {
300
+ response.push( {
301
+ email: user.email,
302
+ clientId: user.clientId,
303
+ role: user.role,
304
+ storeList: user.storeList,
305
+ ticketConfigs: user.ticketConfigs.infraReport,
306
+ } );
307
+ }
308
+ }
309
+ res.sendSuccess( { count: response.length, response: response } );
310
+ } catch ( error ) {
311
+ logger.error( { error: error, function: 'emailUserList' } );
312
+ res.sendError( error, 500 );
313
+ }
314
+ }
@@ -2,7 +2,7 @@
2
2
  import express from 'express';
3
3
  import {
4
4
  migrateClient, migrateStores, basicList, clientList, setTicketTime, downStoresList,
5
- openTicketList, assigntoUser, updateRefreshTicket, closeTicket,
5
+ openTicketList, assigntoUser, updateRefreshTicket, closeTicket, emailUserList,
6
6
  } from '../controllers/internalInfra.controller.js';
7
7
 
8
8
  export const internalInfraRouter = express.Router();
@@ -17,5 +17,6 @@ internalInfraRouter.get( '/openTicketList', openTicketList );
17
17
  internalInfraRouter.post( '/assigntoUser', assigntoUser );
18
18
  internalInfraRouter.post( '/updateRefreshTicket', updateRefreshTicket );
19
19
  internalInfraRouter.post( '/closeTicket', closeTicket );
20
+ internalInfraRouter.get( '/emailUserList', emailUserList );
20
21
 
21
22