Skip to content

Commit

Permalink
refactor: refactor sendDigest
Browse files Browse the repository at this point in the history
  • Loading branch information
swh00tw committed Feb 19, 2024
1 parent 5d92e31 commit 3228422
Showing 1 changed file with 2 additions and 64 deletions.
66 changes: 2 additions & 64 deletions apps/recnet/src/app/api/sendDigest/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import { onSchedule } from "firebase-functions/v2/scheduler";
import { db } from "@/firebase/admin";
import { UserSchema } from "@/types/user";
import { formatDate, getLatestCutOff } from "@/utils/date";
Expand All @@ -9,6 +8,8 @@ import WeeklyDigest from "../../../../emails/WeeklyDigest";
import { render } from "@react-email/render";
import { NextRequest, NextResponse } from "next/server";

const TEST_USER_IDS = ["GoXnHBhgK8QhcZpki0la"];

export async function GET(request: NextRequest) {
if (
request.headers.get("Authorization") !== `Bearer ${process.env.CRON_SECRET}`
Expand Down Expand Up @@ -70,66 +71,3 @@ export async function GET(request: NextRequest) {
return NextResponse.json({ ok: false });
}
}

const TEST_USER_IDS = ["GoXnHBhgK8QhcZpki0la"];

// const sendWeeklyDigestTest = onSchedule(
// "every wednesday 00:01",
// async (event) => {
// try {
// // map over users
// // for each user, get the feeds this cycle
// // and get recsWithUsers, and groupBy title
// // push an email to collection "mails"

// const userDocs = await db.collection("users").get();
// await Promise.all(
// userDocs.docs.map(async (userDoc) => {
// const userData = userDoc.data();

// // parse with UserSchema
// const res = UserSchema.safeParse({
// ...userData,
// id: userDoc.id,
// });
// if (!res.success) {
// logger.error("Error parsing user", res.error);
// return;
// }
// const user = res.data;

// // test within certain user ids
// if (!TEST_USER_IDS.includes(user.id)) {
// return;
// }

// const recs = await getFeedsRecs(
// user?.id,
// getLatestCutOff().getTime()
// );
// const recsWithUsers = await getRecsWithUsers(recs);
// const recsGroupByTitle = groupBy(recsWithUsers, (recWithUser) => {
// const titleLowercase = recWithUser.title.toLowerCase();
// const words = titleLowercase
// .split(" ")
// .filter((w) => w.length > 0)
// .filter(notEmpty);
// return words.join("");
// });

// const digest = {
// to: user.email,
// message: {
// subject: `[Recnet] Your Weekly Digest for ${formatDate(getLatestCutOff())}`,
// html: render(WeeklyDigest({ recsDict: recsGroupByTitle })),
// },
// };

// await db.collection("mails").add(digest);
// })
// );
// } catch (error) {
// logger.error("Error:", error);
// }
// }
// );

0 comments on commit 3228422

Please sign in to comment.