import DB from "src/system/DB";
import { getLanguage } from "src/Utility";

export const getEssays = async (
  forumID: string,
  language: string,
  page: number,
  viewUnit: number,
) => {
  return DB.ta(async (db) => {
    const forum = await DB.getForum(db, forumID);
    if (forum) {
      return {
        title: getLanguage(language, forum),
        essayCount: Number(await DB.getEssayCount(forumID)),
        essays: await DB.getEssays(forumID, page, viewUnit),
        level: forum.level,
      };
    }
  });
};
