41 lines
No EOL
1.5 KiB
JavaScript
41 lines
No EOL
1.5 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const express_1 = require("express");
|
|
const zod_1 = require("zod");
|
|
const Event_1 = require("../models/Event");
|
|
const auth_1 = require("../middleware/auth");
|
|
const router = (0, express_1.Router)();
|
|
const eventSchema = zod_1.z.object({
|
|
date: zod_1.z.string().min(1),
|
|
title: zod_1.z.string().min(1),
|
|
description: zod_1.z.string().min(1),
|
|
startTime: zod_1.z.string().min(1),
|
|
endTime: zod_1.z.string().min(1),
|
|
pointOfContact: zod_1.z.string().min(1),
|
|
email: zod_1.z.string().email(),
|
|
address: zod_1.z.string().min(1),
|
|
});
|
|
router.get('/', async (_req, res) => {
|
|
const events = await Event_1.Event.find().sort({ date: 1 });
|
|
res.json(events);
|
|
});
|
|
router.post('/', auth_1.requireAuth, async (req, res) => {
|
|
const data = eventSchema.parse(req.body);
|
|
const event = await Event_1.Event.create(data);
|
|
res.status(201).json(event);
|
|
});
|
|
router.put('/:id', auth_1.requireAuth, async (req, res) => {
|
|
const data = eventSchema.partial().parse(req.body);
|
|
const event = await Event_1.Event.findByIdAndUpdate(req.params.id, data, { new: true });
|
|
if (!event) {
|
|
res.status(404).json({ error: 'Not found' });
|
|
return;
|
|
}
|
|
res.json(event);
|
|
});
|
|
router.delete('/:id', auth_1.requireAuth, async (req, res) => {
|
|
await Event_1.Event.findByIdAndDelete(req.params.id);
|
|
res.status(204).send();
|
|
});
|
|
exports.default = router;
|
|
//# sourceMappingURL=events.js.map
|