0

Salem, I have tried to return the number of order per hour, so i need to extract the hour in the property createdAt in my order Model that's why i think to use The getHours() method returns the hour for the specified date. My method:

 @get('/orders/count-perHour/{date}', {
    responses: {
      '200': {
        description: 'Order model count',
        content: { 'application/json': { schema: CountSchema } },
      },
    },
  })
  async countPerHour(
    @param.path.string('date') date: string): Promise<any> {
let dateStart=new Date(date) ;
dateStart.setSeconds(0);
dateStart.setMinutes(0);

let dateEnd=new Date(date) ;
dateEnd.setSeconds(59);
dateEnd.setMinutes(59);

    return await this.orderRepository.count(
      { 
        createdAt: {
          lte: dateEnd
          ,
          gte: dateStart
        }
 }
    );
  }

the property createdAt in mu model order:

@property({type: 'date',})createdAt?: string;

Error: it return false comparison, for example if i have one order at hour:10 it return 6

H_Hmd
  • 25
  • 8
  • Are you trying to filter/count orders within a certain hour? i.e. if `hour=10`, all orders created at 10.00am in each day? – Salitha Jan 01 '20 at 08:43
  • Thank you for your reply Salit.ha, i try to filter all orders according to an input ISO datetime and i compare this date between 2 others dates(dateStart) setSeconds setMinutes to 0 and (dateEnd) setSeconds setMinutes to 59.return await this.orderRepository.count( { createdAt: lt: dateEnd , gte: dateStart } but it return to me false comparison for exmple if i have only one order at 10 it return 6 – H_Hmd Jan 02 '20 at 08:09
  • Salitha i add the whole method as response. Can you please help me – H_Hmd Jan 02 '20 at 08:27

0 Answers0