From e55c39fe9c1d7cbbd5ae2167a827e91c9720e748 Mon Sep 17 00:00:00 2001 From: Alex Appleget Date: Wed, 6 Nov 2024 11:53:33 -0600 Subject: [PATCH] Fix: Created an api function to convert userIDs into their targetIDs for bcc emailing. --- .../actions/sendEmailNotification.ts | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/app/(admin)/admin/notifications/actions/sendEmailNotification.ts b/app/(admin)/admin/notifications/actions/sendEmailNotification.ts index 98c66dc7..718798d3 100644 --- a/app/(admin)/admin/notifications/actions/sendEmailNotification.ts +++ b/app/(admin)/admin/notifications/actions/sendEmailNotification.ts @@ -3,7 +3,7 @@ 'use server'; import { ID } from 'appwrite'; -import { messaging } from '@/api/serverConfig'; +import { messaging, users } from '@/api/serverConfig'; /** * Function to send email. @@ -27,12 +27,36 @@ export const sendEmailNotifications = async ({ subject, content, [], - groupUsers, - [], + ['672a3534000502297d88'], [], [], + groupUsers, ); } catch (error) { - throw new Error('Error Sending Email'); + throw error; } }; + +/** + * Function to take the userIDs and grab their targetIDs for emailing. + * @param props - userIDs + * @param props.userIDs - All the passed in userIDs. + * @returns {Promise} + */ +export async function getUserTargets({ + userIDs, +}: { + userIDs: string[]; +}): Promise { + try { + const userTargets = await Promise.all( + userIDs.map(async (userID) => { + const userTarget = await users.get(userID); + return userTarget.targets.map((target) => target.$id); + }), + ); + return userTargets.flat(); + } catch (error) { + throw error; + } +}