import { DataSource } from 'typeorm';

export async function handler(dataSource: DataSource, { query }) {
  const { studentId = '' } = query;
  const type =
    query.type ||
    "ONLINE_COURSE', 'LIVE_TEACHING', 'MOCK_EXAMINATION','ERROR_CONSOLIDATION', 'CLASS_NOTE', 'ONLINE_FAQ', 'RESOURCE_VIEW";
  return dataSource.query(`
    select
      floor(hour(create_time)/4) period, type, count(1) value
    from report_data rd
    where type in('${type}')
    ${studentId && `and creator='${studentId}'`}
    group by period
    order by period
  `);
}
