Skip to content

Commit

Permalink
Merge pull request #30 from kentibs/feat/events-api
Browse files Browse the repository at this point in the history
feat: add  event update api endpoint
  • Loading branch information
Tibz-Dankan authored Jan 7, 2024
2 parents 1fb2666 + 1eea681 commit 53e634e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
41 changes: 38 additions & 3 deletions src/controllers/eventsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ export const uploadEventImages = asyncHandler(
const upload = await new Upload(imagePath, next).add(files[i]);
const url = upload?.url as string;

console.log("url from firebase");
console.log(url);

await EventImage.create({
data: { eventId: eventId, imageUrl: url, imagePath: imagePath },
});
Expand All @@ -95,3 +92,41 @@ export const uploadEventImages = asyncHandler(
});
}
);

export const updateEvent = asyncHandler(
async (req: Request, res: Response, next: NextFunction) => {
const title = req.body.title as string;
const category = req.body.category as EventCategory;
const description = req.body.description as string;
const eventId = req.params.eventId;

if (!eventId) {
return next(new AppError("Please provide eventId", 400));
}
if (!title || !category || !description) {
return next(new AppError("Please fill out all fields", 400));
}
if (!validateEventCategory(category)) {
return next(new AppError("Please provide a valid event category", 400));
}

const updatedEvent = await Event.update({
where: { eventId: eventId },
data: req.body,
select: {
eventId: true,
title: true,
category: true,
description: true,
createdAt: true,
updatedAt: true,
},
});

res.status(200).json({
status: "success",
message: "Event created successfully",
data: { event: updatedEvent },
});
}
);
2 changes: 2 additions & 0 deletions src/routes/event/eventRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { uploadFiles } from "../../utils/upload";
import {
postEvent,
uploadEventImages,
updateEvent,
} from "../../controllers/eventsController";

const router = express.Router();
Expand All @@ -15,5 +16,6 @@ router.post(
postEvent,
uploadEventImages
);
router.patch("/update-event/:eventId", protectSuperAdmin, updateEvent);

export { router as eventRoutes };

0 comments on commit 53e634e

Please sign in to comment.