Skip to content

Commit

Permalink
Debug the cron apis
Browse files Browse the repository at this point in the history
  • Loading branch information
sidiDev committed Dec 18, 2023
1 parent 784f9c3 commit 3ccf7bd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 43 deletions.
36 changes: 15 additions & 21 deletions app/api/comment-notification/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,37 +79,31 @@ async function sendNotification(email: string, slug: string, product_name: strin
}

export async function GET(request: NextRequest) {
if (!process.env.CRON_SECRET) {
return new Response('Unauthorized', {
status: 401,
});
}

const getToken = (await getAuthToken()).data.Token;

const commentService = new CommentService(createServerClient());
const initCommentLogsService = await commentLogsService();
// const initCommentLogsService = await commentLogsService();

const dayAgo = moment().add(-1, 'day').toDate();

const groups = await commentService.getCommentsGroupedByProducts(dayAgo);

if ((await initCommentLogsService.getTodayLog()).length == 0) {
const sentEmails = new Set();
groups.forEach(item => {
const commentItem = item as Icomment;
const email = commentItem.product.profiles.email;
const userProfile = commentItem.comments[0].profiles;
if (!sentEmails.has(email) && commentItem.product.profiles.id != userProfile.id) {
const { name, slug } = item.product;
// if ((await initCommentLogsService.getTodayLog()).length == 0) {
const sentEmails = new Set();
groups.forEach(item => {
const commentItem = item as Icomment;
const email = commentItem.product.profiles.email;
const userProfile = commentItem.comments[0].profiles;
if (!sentEmails.has(email) && commentItem.product.profiles.id != userProfile.id) {
const { name, slug } = item.product;

sendNotification(email, slug as string, name as string, userProfile.full_name, commentItem.comments[0].content, getToken);
sentEmails.add(email);
}
});
// sendNotification(email, slug as string, name as string, userProfile.full_name, commentItem.comments[0].content, getToken);
sentEmails.add(email);
}
});

await initCommentLogsService.insertCommentLogs({ comments_number: groups.length, emails_sent: sentEmails.size });
}
// await initCommentLogsService.insertCommentLogs({ comments_number: groups.length, emails_sent: sentEmails.size });
// }

return NextResponse.json({ success: true });
}
38 changes: 16 additions & 22 deletions app/api/upvote-notification/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,37 +74,31 @@ async function sendNotification(email: string, slug: string, product_name: strin
}

export async function GET(request: NextRequest) {
if (!process.env.CRON_SECRET) {
return new Response('Unauthorized', {
status: 401,
});
}

const getToken = (await getAuthToken()).data.Token;
// const getToken = (await getAuthToken()).data.Token;

const productsService = new ProductsService(createServerClient());
const initUpvoteLogsService = await upvoteLogsService();
// const initUpvoteLogsService = await upvoteLogsService();

const dayAgo = moment().add(-1, 'day').toDate();

const groups = await productsService.getUpvotesGroupedByProducts(dayAgo);

if ((await initUpvoteLogsService.getTodayLog()).length == 0) {
const sentEmails = new Set();
groups.forEach(item => {
const voteItem = item as IVote;
const email = voteItem.product.profiles.email;
const userProfile = voteItem.voter_data;
if (!sentEmails.has(email) && voteItem.product.profiles.id != userProfile.id) {
const { name, slug } = item.product;
// if ((await initUpvoteLogsService.getTodayLog()).length == 0) {
const sentEmails = new Set();
groups.forEach(item => {
const voteItem = item as IVote;
const email = voteItem.product.profiles.email;
const userProfile = voteItem.voter_data;
if (!sentEmails.has(email) && voteItem.product.profiles.id != userProfile.id) {
const { name, slug } = item.product;

sendNotification(email, slug as string, name as string, userProfile.full_name, getToken);
sentEmails.add(email);
}
});
// sendNotification(email, slug as string, name as string, userProfile.full_name, getToken);
sentEmails.add(email);
}
});

await initUpvoteLogsService.insertUpvoteLogs({ upvotes_number: groups.length, emails_sent: sentEmails.size });
}
// await initUpvoteLogsService.insertUpvoteLogs({ upvotes_number: groups.length, emails_sent: sentEmails.size });
// }

return NextResponse.json({ success: true });
}

0 comments on commit 3ccf7bd

Please sign in to comment.