tango-app-api-client 3.0.26-dev → 3.0.28-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-client",
3
- "version": "3.0.26-dev",
3
+ "version": "3.0.28-dev",
4
4
  "description": "client",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -25,8 +25,8 @@
25
25
  "mongodb": "^6.3.0",
26
26
  "nodemon": "^3.0.3",
27
27
  "swagger-ui-express": "^5.0.0",
28
- "tango-api-schema": "^2.0.67",
29
- "tango-app-api-middleware": "^1.0.53-dev",
28
+ "tango-api-schema": "^2.0.78",
29
+ "tango-app-api-middleware": "^1.0.54-dev",
30
30
  "winston": "^3.11.0",
31
31
  "winston-daily-rotate-file": "^5.0.0"
32
32
  },
@@ -812,9 +812,20 @@ export async function clientList( req, res ) {
812
812
  }
813
813
 
814
814
  if ( inputData.sortColumName ) {
815
- clientQuery.push( {
816
- $sort: { [inputData.sortColumName]: inputData.sortBy || -1 },
817
- } );
815
+ clientQuery.push(
816
+ {
817
+ $addFields: {
818
+ lowerCaseSortField: { $toLower: `$${inputData.sortColumName}` },
819
+ },
820
+ },
821
+ {
822
+ $sort: { lowerCaseSortField: inputData.sortBy || -1 },
823
+ },
824
+ {
825
+ $project: {
826
+ lowerCaseSortField: 0,
827
+ },
828
+ } );
818
829
  }
819
830
  if ( inputData.isExport ) {
820
831
  clientQuery.push( {
@@ -954,7 +965,6 @@ export async function clientList( req, res ) {
954
965
  },
955
966
  },
956
967
  ];
957
-
958
968
  const activeStoreCount = await aggregateStore( storeQuery );
959
969
  const activeCameraCount = await aggregateCamera( cameraQuery );
960
970
  const result = _.values(
@@ -964,6 +974,19 @@ export async function clientList( req, res ) {
964
974
  _.keyBy( activeCameraCount, 'clientId' ),
965
975
  ),
966
976
  );
977
+
978
+ let sortedResult = _.sortBy( result, [ ( obj ) => new Date( obj.createdAt ) ] ).reverse();
979
+ if ( inputData.sortColumName ) {
980
+ if ( inputData.sortBy === 1 ) {
981
+ sortedResult = _.sortBy( result, [ ( obj ) => obj[inputData.sortColumName ? inputData.sortColumName : 'clientName']?.toLowerCase() ] );
982
+ }
983
+
984
+ if ( inputData.sortBy === -1 ) {
985
+ sortedResult.reverse();
986
+ }
987
+ }
988
+
989
+
967
990
  if ( inputData.isExport ) {
968
991
  const resultChunk = await chunkArray( result, 10 );
969
992
  const promises = resultChunk.map( async ( chunk ) => {
@@ -986,7 +1009,7 @@ export async function clientList( req, res ) {
986
1009
  await download( exportResult, res );
987
1010
  return;
988
1011
  }
989
- return res.sendSuccess( { result: result, count: clientCount.length } );
1012
+ return res.sendSuccess( { result: sortedResult, count: clientCount.length } );
990
1013
  } catch ( error ) {
991
1014
  logger.error( { error: error, function: 'clientList' } );
992
1015
  return res.sendError( error, 500 );
@@ -33,7 +33,7 @@ export const billingDetailsSchemaBody = joi.object( {
33
33
  tradeName: joi.string().optional(),
34
34
  gstNumber: joi.string().optional(),
35
35
  authorityName: joi.string().optional(),
36
- authorityEmail: joi.string().email().optional(),
36
+ authorityEmail: joi.string().email().message( 'Enter a valid email' ).optional(),
37
37
  billingAddress: joi.string().optional(),
38
38
  gstCertificate: joi.string().optional().allow( '' ),
39
39
  } );
@@ -49,7 +49,7 @@ export const billingDetailsValid = {
49
49
 
50
50
  export const signatoryDetailsSchemaBody = joi.object( {
51
51
  name: joi.string().optional(),
52
- email: joi.string().email().optional(),
52
+ email: joi.string().email().message( 'Enter a valid email' ).optional(),
53
53
  number: joi.string()
54
54
  .pattern( /^\d{4,12}$/ )
55
55
  .message( 'Enter a valid mobile number' )