import { DataSource } from 'typeorm';

export async function handler(dataSource: DataSource, { user }) {
  let datas = await dataSource.query(`
  select
	count(1) value,
	qt.name type,
	concat(qt.name,'-',qdl.name) name
from
	question q
left join question_type qt on
	qt.id = q.type
left join question_difficulty_level qdl on
	qdl.id = q.difficulty_level
  where q.del_flag =0 ${
    user.baseRole === 2 ? "and q.creator = '" + user.userId + "'" : ''
  }
group by
	q.type,
	q.difficulty_level
order by q.type

  `);
  datas = datas.map((item) => {
    item.value = parseInt(item.value);
    return item;
  });
  return datas;
}
