import { DataSource } from 'typeorm';

export async function handler(dataSource: DataSource, { user }) {
  return dataSource.query(`
    select r.type,record.count from (
      select count(1) count,dr.field01 id from report_data dr 
      left join resource r2 
      on r2.id=dr.field01 
      where dr.type = 'RESOURCE_VIEW' and r2.type != 'folder' and r2.creator = '${user.userId}'
      group by r2.type 
    ) record
    left join resource r on r.id=record.id
    order by r.type
  `);
}
