Skip to content

Commit 13c40cf

Browse files
Merge pull request #24 from IEEECS-VIT/report
feat: report event api
2 parents 302c93e + 9b6bcb1 commit 13c40cf

File tree

3 files changed

+107
-7
lines changed

3 files changed

+107
-7
lines changed

prisma/schema.prisma

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ model User {
7070
dob DateTime
7171
mobile_number String @unique
7272
email String? @unique
73-
gender Gender?
73+
gender Gender?
7474
profile_pic String?
7575
preferred_language Language @default(English)
7676
verification_status VerificationStatus @default(unverified)
@@ -84,6 +84,7 @@ model User {
8484
guestGroupMemberships GuestGroupUsers[] @relation("GroupMember")
8585
addedToGroups GuestGroupUsers[] @relation("AddedBy")
8686
createdInviteLinks InviteLink[]
87+
reportedEvents ReportedEvent[] @relation("UserReportedEvents")
8788
}
8889

8990
model Event {
@@ -116,6 +117,7 @@ model Event {
116117
messages Message[]
117118
invites Invite[]
118119
guestGroups EventGuestGroup[]
120+
reportedBy ReportedEvent[] @relation("EventReportedEvents")
119121
}
120122

121123
model WeddingEvent {
@@ -207,7 +209,7 @@ model SubEvent {
207209
208210
guests String[]
209211
messages String[]
210-
212+
211213
// Add this relation
212214
guestGroups SubEventGuestGroup[]
213215
}
@@ -361,3 +363,16 @@ model VerifiedPhone {
361363
phone String @id
362364
created_at DateTime @default(now())
363365
}
366+
367+
model ReportedEvent {
368+
id String @id @default(uuid())
369+
reason String
370+
user_id String
371+
event_id String
372+
created_at DateTime @default(now())
373+
374+
user User @relation("UserReportedEvents", fields: [user_id], references: [id], onDelete: Cascade)
375+
event Event @relation("EventReportedEvents", fields: [event_id], references: [id], onDelete: Cascade)
376+
377+
@@unique([user_id, event_id])
378+
}

src/routes/eventRoutes.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
addOtherDetails,
1818
getAllUserEvents,
1919
getHostedEvents,
20-
getInvitedEvents
20+
getInvitedEvents,
21+
reportEvent
2122
} from '../services/eventService';
2223
import { verifyIdToken } from '../middleware/verifyIdToken';
2324
import { parseMultipartForm, uploadFilesToSupabase } from '../lib/fileUpload';
@@ -706,4 +707,32 @@ router.delete('/:eventId', verifyIdToken, async (req: Request, res: Response) =>
706707
}
707708
});
708709

710+
// Report Event
711+
router.post('/report', verifyIdToken, async (req: Request, res: Response) => {
712+
try {
713+
const userId = req.userId;
714+
if (!userId) {
715+
res.status(401).json({ message: 'Unauthorized' });
716+
return;
717+
}
718+
const { eventId, reason } = req.body;
719+
720+
if (!eventId || typeof reason !== 'string' || reason.trim() === '') {
721+
res.status(400).json({ message: 'Event ID and reason are required' });
722+
return;
723+
}
724+
725+
const { success, error } = await reportEvent(userId, eventId, reason);
726+
727+
if (success) {
728+
res.status(200).json({ message: 'Event reported successfully' });
729+
} else {
730+
res.status(500).json({ message: error ?? 'Internal Server Error' });
731+
}
732+
} catch (error) {
733+
console.error(error);
734+
res.status(500).json({ message: 'Internal Server Error' });
735+
}
736+
});
737+
709738
export default router

src/services/eventService.ts

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ export const getAllUserEvents = async (userId: string, filter?: 'hosted' | 'invi
243243
where: {
244244
co_hosts: {
245245
some: { id: userId }
246+
},
247+
reportedBy: {
248+
none: {
249+
user_id: userId
250+
}
246251
}
247252
},
248253
include: {
@@ -263,6 +268,11 @@ export const getAllUserEvents = async (userId: string, filter?: 'hosted' | 'invi
263268
where: {
264269
guests: {
265270
some: { user_id: userId }
271+
},
272+
reportedBy: {
273+
none: {
274+
user_id: userId
275+
}
266276
}
267277
},
268278
include: {
@@ -342,7 +352,14 @@ export const getHostedEvents = async (userId: string) => {
342352
try {
343353
// Get events where user is host
344354
const hostedEvents = await prisma.event.findMany({
345-
where: { hostId: userId },
355+
where: {
356+
hostId: userId,
357+
reportedBy: {
358+
none: {
359+
user_id: userId
360+
}
361+
}
362+
},
346363
include: {
347364
host: true,
348365
co_hosts: true,
@@ -361,6 +378,11 @@ export const getHostedEvents = async (userId: string) => {
361378
where: {
362379
co_hosts: {
363380
some: { id: userId }
381+
},
382+
reportedBy: {
383+
none: {
384+
user_id: userId
385+
}
364386
}
365387
},
366388
include: {
@@ -436,6 +458,11 @@ export const getInvitedEvents = async (userId: string) => {
436458
// Exclude events where user is co-host
437459
co_hosts: {
438460
none: { id: userId }
461+
},
462+
reportedBy: {
463+
none: {
464+
user_id: userId
465+
}
439466
}
440467
},
441468
include: {
@@ -943,9 +970,38 @@ export const addOtherDetails = async (eventId: string, data: {
943970
error: error.message
944971
};
945972
} else {
946-
return {
947-
success: false,
948-
error: "Failed to add other details"
973+
return {
974+
success: false,
975+
error: "Failed to add other details",
976+
};
977+
}
978+
}
979+
};
980+
981+
export const reportEvent = async (userId: string, eventId: string, reason: string) => {
982+
try {
983+
const report = await prisma.reportedEvent.create({
984+
data: {
985+
user_id: userId,
986+
event_id: eventId,
987+
reason,
988+
}
989+
});
990+
991+
return {
992+
success: true,
993+
report
994+
};
995+
} catch (error: unknown) {
996+
if (error instanceof Error) {
997+
return {
998+
success: false,
999+
error: error.message,
1000+
};
1001+
} else {
1002+
return {
1003+
success: false,
1004+
error: "Failed to report event",
9491005
};
9501006
}
9511007
}

0 commit comments

Comments
 (0)