Skip to content

Commit 1348954

Browse files
committed
Revert "fix: build errors"
This reverts commit 9c01c49.
1 parent ded999a commit 1348954

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/routes/inviteRoutes.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
getEventRsvpSummary,
1111
getEventGuestList,
1212
bulkCreateInvites,
13+
sendWhatsappInvite,
1314
getEventRsvps
1415
} from '../services/inviteService';
1516
import { verifyIdToken } from '../middleware/verifyIdToken';
@@ -511,5 +512,36 @@ router.get('/:eventId/:groupId/status/:phoneNo', async (_req: Request, res: Resp
511512
res.status(403).json({ message: 'RSVP status can be viewed and managed in the app. Please download the app to continue.' });
512513
});
513514

514-
export default router;
515-
515+
router.post(
516+
'/send-invite/:eventId/:groupId',
517+
verifyIdToken,
518+
async (req: Request, res: Response) => {
519+
try {
520+
const { eventId, groupId } = req.params;
521+
const { name, phone_no } = req.body;
522+
const userId = req.userId; // This is the ID of the user sending the invite
523+
if (!userId) {
524+
res.status(401).json({ message: 'Unauthorized' });
525+
return;
526+
}
527+
528+
const isAuthorized = await isEventHostOrCoHost(userId, eventId);
529+
if (!isAuthorized) {
530+
return res.status(403).json({ message: 'Only event hosts can send invites' });
531+
}
532+
533+
// Pass the sender's userId to the service function
534+
const result = await sendWhatsappInvite(userId, eventId, groupId, name, phone_no);
535+
536+
if (!result.success) {
537+
return res.status(400).json({ message: result.error });
538+
}
539+
540+
res.status(200).json({ message: 'Invite link sent successfully' });
541+
} catch (error: any) {
542+
console.error(error);
543+
res.status(500).json({ message: error.message || 'Internal Server Error' });
544+
}
545+
}
546+
);
547+
export default router;

0 commit comments

Comments
 (0)