Skip to content

Commit 278cd77

Browse files
committed
allow file input for subevent routes
1 parent 4744297 commit 278cd77

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/routes/subEventRoutes.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
canManageEventSubEvents
1212
} from '../services/subEventService';
1313
import { verifyIdToken } from '../middleware/verifyIdToken';
14+
import { parseMultipartForm, uploadFilesToSupabase } from '../lib/fileUpload';
1415

1516
const router = express.Router();
1617

@@ -19,23 +20,31 @@ router.post('/', verifyIdToken, async (req: Request, res: Response) => {
1920
try {
2021
const { eventId } = req.params;
2122
const userId = req.userId;
23+
24+
const { fields, files } = await parseMultipartForm(req);
25+
2226
const {
2327
title,
2428
location,
2529
address,
2630
start_date_time,
2731
end_date_time,
2832
invite_message,
29-
image,
3033
guests
31-
} = req.body;
32-
34+
} = fields;
35+
3336
if (!title || !location || !address || !start_date_time || !end_date_time) {
3437
res.status(400).json({ message: 'Title, location, address, start_date_time, and end_date_time are required' });
3538
return;
3639
}
40+
41+
let imageUrls: string[] = [];
42+
if (files && files.length > 0) {
43+
imageUrls = await uploadFilesToSupabase(files, 'subevent-images');
44+
}
45+
46+
const image = imageUrls.length > 0 ? imageUrls[0] : (fields.image || '');
3747

38-
// Check if user can manage sub-events for this event
3948
const canManage = await canManageEventSubEvents(userId, eventId);
4049
if (!canManage) {
4150
res.status(403).json({ message: 'Only event hosts and co-hosts can create sub-events' });
@@ -131,18 +140,26 @@ router.put('/:subEventId', verifyIdToken, async (req: Request, res: Response) =>
131140
try {
132141
const { eventId, subEventId } = req.params;
133142
const userId = req.userId;
143+
144+
const { fields, files } = await parseMultipartForm(req);
145+
134146
const {
135147
title,
136148
location,
137149
address,
138150
start_date_time,
139151
end_date_time,
140152
invite_message,
141-
image,
142153
guests
143-
} = req.body;
154+
} = fields;
155+
156+
let imageUrls: string[] = [];
157+
if (files && files.length > 0) {
158+
imageUrls = await uploadFilesToSupabase(files, 'subevent-images');
159+
}
160+
161+
const image = imageUrls.length > 0 ? imageUrls[0] : (fields.image || '');
144162

145-
// Check if user can manage this sub-event
146163
const canManage = await canManageSubEvent(userId, subEventId);
147164
if (!canManage) {
148165
res.status(403).json({ message: 'Only event hosts and co-hosts can update sub-events' });

0 commit comments

Comments
 (0)