import dayjs from "dayjs";
import { prisma } from "../lib/prisma";
import { RankingService } from "./services/ranking.service";
import { NaverRealEstate } from "./services/naver.service";
import { realestateTypes, realtorIds } from "./config";

async function updateRanking() {
  try {
    const checkDate = dayjs().toDate();
    for (let realtorId of realtorIds) {
      const articles = await prisma.realEstateArticle.findMany({
        where: {
          isActive: true,
          realtorId: realtorId,
        },
      });

      const rankingService = new RankingService(
        new NaverRealEstate({
          realtorId: realtorId,
        })
      );
      await rankingService.updateRanking(articles, checkDate);
    }
  } catch (error) {
    console.log(error);
    process.exit();
  }
}

(async () => {
  await updateRanking();
})();
