2

created_at is the value I Want to compare with the beginDate and the endDate.

var newARRA = chain(this.props.transferts.transfertAccount)
.filter({ 'officeSender':
      this.props.users.user.office,officeReceiver:this.state.selectedOffice,
  'created_at':(this.state.beginDate,this.state.endDate)})
    
.groupBy("currency")
.map((v, k) => ({
     currency: k,
  amount: sumBy(v, 'fee')
 }))
.value();
ksav
  • 20,015
  • 6
  • 46
  • 66

3 Answers3

3

You'll need to use the filter's predicate function. Example (not tested):

var newARRA = chain(this.props.transferts.transfertAccount)
  .filter(({ officeSender, officeReceiver, created_at }) => {
    return _.eq(officeSender, this.props.users.user.office) &&
           _.eq(officeReceiver, this.state.selectedOffice) &&
           _.gte(created_at, this.state.beginDate) &&
           _.lte(created_at, this.state.endDate) &&
  })
  .groupBy("currency")
  .map((v, k) => ({
    currency: k,
    amount: sumBy(v, 'fee')
  }))
  .value();
Ori Drori
  • 183,571
  • 29
  • 224
  • 209
0

You could use the moment library to achieve this for you, assuming that the two values are moment like dates:

'created_at': moment().isBetween(this.state.beginDate, this.state.endDate)

This does assume that the dates are moment-like and don't require any pre-processing by the moment library.

rrd
  • 5,789
  • 3
  • 28
  • 36
0

I would prefer using a date library. > date-fns could do this for you

var isWithinRange = require('date-fns/is_within_range')
isWithinRange(
   new Date(2014, 0, 3), new Date(2014, 0, 1), new Date(2014, 0, 7)
)//=> true
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
PRogalla
  • 216
  • 2
  • 12