import { DataSource, Repository } from 'typeorm';
export async function handler(dataSource: DataSource, { user }) {
  let data = await dataSource.query(`
  SELECT
  MIN(course_list.course_hours) AS minHour,
  AVG(course_list.course_hours) AS avgHour, 
MAX(course_list.course_hours) AS maxHour
FROM
	course_list
WHERE
	course_list.creator = '${user.userId}'
      `);
  const keys = Object.keys(data[0]);
  data = keys.map((key) => {
    data[0][key] = +data[0][key];
    return {
      type: {
        minHour: '最低学时时长',
        avgHour: '平均学时时长',
        maxHour: '最高学时时长',
      }[key],
      value: Math.round(parseFloat(data[0][key]) * 100) / 100,
    };
  });
  return data;
}
