Skip to content

Commit

Permalink
Fix: Created an api function to convert userIDs into their targetIDs …
Browse files Browse the repository at this point in the history
…for bcc emailing.
  • Loading branch information
alexappleget committed Nov 6, 2024
1 parent 1188d47 commit e55c39f
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions app/(admin)/admin/notifications/actions/sendEmailNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<void>}
*/
export async function getUserTargets({
userIDs,
}: {
userIDs: string[];
}): Promise<string[]> {
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;
}
}

0 comments on commit e55c39f

Please sign in to comment.