@@ -8,6 +8,7 @@ const config = require('config')
8
8
const HttpStatus = require ( 'http-status-codes' )
9
9
const { Op } = require ( 'sequelize' )
10
10
const uuid = require ( 'uuid' )
11
+ const moment = require ( 'moment' )
11
12
const helper = require ( '../common/helper' )
12
13
const logger = require ( '../common/logger' )
13
14
const errors = require ( '../common/errors' )
@@ -377,8 +378,25 @@ searchWorkPeriodPayments.schema = Joi.object().keys({
377
378
* @returns {Object } the process result
378
379
*/
379
380
async function createQueryWorkPeriodPayments ( currentUser , criteria ) {
381
+ console . log ( criteria . query [ 'workPeriods.startDate' ] )
380
382
// check permission
381
383
_checkUserPermissionForCRUWorkPeriodPayment ( currentUser )
384
+ // Joi validation normalizes the dates back to ISO format
385
+ // so, we need to change the date format back to YYYY-MM-DD
386
+ if ( criteria . query . startDate ) {
387
+ criteria . query . startDate = moment ( criteria . query . startDate ) . format ( 'YYYY-MM-DD' )
388
+ }
389
+ if ( criteria . query . endDate ) {
390
+ criteria . query . endDate = moment ( criteria . query . endDate ) . format ( 'YYYY-MM-DD' )
391
+ }
392
+ if ( criteria . query [ 'workPeriods.startDate' ] ) {
393
+ criteria . query [ 'workPeriods.startDate' ] = moment ( criteria . query [ 'workPeriods.startDate' ] ) . format ( 'YYYY-MM-DD' )
394
+ }
395
+ if ( criteria . query [ 'workPeriods.endDate' ] ) {
396
+ criteria . query [ 'workPeriods.endDate' ] = moment ( criteria . query [ 'workPeriods.endDate' ] ) . format ( 'YYYY-MM-DD' )
397
+ }
398
+ // save query to return back
399
+ const rawQuery = _ . cloneDeep ( criteria . query )
382
400
const createdBy = await helper . getUserId ( currentUser . userId )
383
401
const query = criteria . query
384
402
if ( ( typeof query [ 'workPeriods.paymentStatus' ] ) === 'string' ) {
@@ -392,7 +410,7 @@ async function createQueryWorkPeriodPayments (currentUser, criteria) {
392
410
393
411
const wpArray = _ . flatMap ( searchResult . result , 'workPeriods' )
394
412
const resourceBookingMap = _ . fromPairs ( _ . map ( searchResult . result , rb => [ rb . id , rb ] ) )
395
- const result = { total : wpArray . length , query, totalSuccess : 0 , totalError : 0 }
413
+ const result = { total : wpArray . length , query : rawQuery , totalSuccess : 0 , totalError : 0 }
396
414
397
415
for ( const wp of wpArray ) {
398
416
try {
0 commit comments