Skip to content

Commit

Permalink
Merge branch 'main' into hotfix/jack/paypal-credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
jennymar committed Jun 30, 2024
2 parents f2da8b6 + fbe2054 commit 28811ab
Show file tree
Hide file tree
Showing 142 changed files with 6,167 additions and 3,045 deletions.
1 change: 0 additions & 1 deletion backend/dist/controllers/emails.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const createEmail = (req, res, next) => __awaiter(void 0, void 0, void 0, functi
questionType = "Other message";
}
else {
console.log("question: " + question);
questionType = question.split(" ").slice(3).join(" ");
questionType = questionType[0].toUpperCase() + questionType.slice(1);
}
Expand Down
23 changes: 20 additions & 3 deletions backend/dist/controllers/eventDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateEventDetails = exports.createEventDetails = exports.getEventDetails = exports.getAllEventDetails = void 0;
exports.deleteEventDetails = exports.updateEventDetails = exports.createEventDetails = exports.getEventDetails = exports.getAllEventDetails = void 0;
const express_validator_1 = require("express-validator");
const http_errors_1 = __importDefault(require("http-errors"));
const eventDetails_1 = __importDefault(require("../models/eventDetails"));
Expand Down Expand Up @@ -46,16 +46,19 @@ const getEventDetails = (req, res, next) => __awaiter(void 0, void 0, void 0, fu
exports.getEventDetails = getEventDetails;
const createEventDetails = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
const errors = (0, express_validator_1.validationResult)(req);
const { name, description, guidelines, date, location, imageURI } = req.body;
const { name, description, guidelines, date, startTime, endTime, location, imageURI, description_short, } = req.body;
try {
(0, validationErrorParser_1.default)(errors);
const eventDetails = yield eventDetails_1.default.create({
name,
description,
guidelines,
date,
startTime,
endTime,
location,
imageURI,
description_short,
});
res.status(201).json(eventDetails);
}
Expand All @@ -68,7 +71,6 @@ const updateEventDetails = (req, res, next) => __awaiter(void 0, void 0, void 0,
const errors = (0, express_validator_1.validationResult)(req);
const { id } = req.params;
if (id !== req.body._id) {
// If the _id in the URL does not match the _id in the body, bad request
res.status(400);
}
try {
Expand All @@ -81,6 +83,7 @@ const updateEventDetails = (req, res, next) => __awaiter(void 0, void 0, void 0,
const updatedEventDetails = yield eventDetails_1.default.findById(id);
if (updatedEventDetails === null) {
// No event found, something went wrong
console.log("updatedEventDetails is null");
res.status(404);
}
res.status(200).json(updatedEventDetails);
Expand All @@ -90,3 +93,17 @@ const updateEventDetails = (req, res, next) => __awaiter(void 0, void 0, void 0,
}
});
exports.updateEventDetails = updateEventDetails;
const deleteEventDetails = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
const { id } = req.params;
try {
const eventDetails = yield eventDetails_1.default.findByIdAndDelete(id);
if (!eventDetails) {
throw (0, http_errors_1.default)(404, "event not found");
}
res.status(200).json(eventDetails);
}
catch (error) {
next(error);
}
});
exports.deleteEventDetails = deleteEventDetails;
1 change: 0 additions & 1 deletion backend/dist/controllers/newsletter.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const createNewsletter = (req, res, next) => __awaiter(void 0, void 0, void 0, f
date,
content,
});
console.log("newsletter: ", newsletter);
res.status(201).json(newsletter);
}
catch (error) {
Expand Down
3 changes: 3 additions & 0 deletions backend/dist/models/eventDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const eventDetailsSchema = new mongoose_1.Schema({
description: { type: String, required: true },
guidelines: { type: String, required: true },
date: { type: String, required: true },
startTime: { type: String, required: true },
endTime: { type: String, required: true },
location: { type: String, required: true },
imageURI: { type: String, required: true },
description_short: { type: String, required: true },
});
exports.default = (0, mongoose_1.model)("EventDetails", eventDetailsSchema);
1 change: 1 addition & 0 deletions backend/dist/routes/eventDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ router.get("/:id", EventDetailsValidator.getEventDetails, EventDetailsController
router.put("/:id", // getEventDetails validator works to just check ID
EventDetailsValidator.getEventDetails, EventDetailsController.updateEventDetails);
router.post("/", EventDetailsValidator.createEventDetails, EventDetailsController.createEventDetails);
router.delete("/:id", EventDetailsValidator.deleteEventDetails, EventDetailsController.deleteEventDetails);
exports.default = router;
10 changes: 9 additions & 1 deletion backend/dist/validators/eventDetails.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEventDetails = exports.createEventDetails = void 0;
exports.deleteEventDetails = exports.getEventDetails = exports.createEventDetails = void 0;
const express_validator_1 = require("express-validator");
const makeIDValidator = () => (0, express_validator_1.body)("_id")
.exists()
Expand Down Expand Up @@ -47,12 +47,20 @@ const makeImageURIValidator = () => (0, express_validator_1.body)("imageURI")
.bail()
.isURL()
.withMessage("imageURI must be a URL");
const makeDescriptionShortValidator = () => (0, express_validator_1.body)("description_short")
.exists()
.withMessage("description_short is required")
.bail()
.isString()
.withMessage("description_short must be a string");
exports.createEventDetails = [
makeNameValidator(),
makeDescriptionValidator(),
makeGuidlinesValidator(),
makeDateValidator(),
makeLocationValidator(),
makeImageURIValidator(),
makeDescriptionShortValidator(),
];
exports.getEventDetails = [makeIDValidator()];
exports.deleteEventDetails = [makeIDValidator()];
1 change: 0 additions & 1 deletion backend/src/controllers/emails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const createEmail: RequestHandler = async (req, res, next) => {
if (question === "Other") {
questionType = "Other message";
} else {
console.log("question: " + question);
questionType = question.split(" ").slice(3).join(" ");
questionType = questionType[0].toUpperCase() + questionType.slice(1);
}
Expand Down
34 changes: 32 additions & 2 deletions backend/src/controllers/eventDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,19 @@ export const getEventDetails: RequestHandler = async (req, res, next) => {
};

export const createEventDetails: RequestHandler = async (req, res, next) => {
console.log("backend createEventDetails. req.body: ", req.body);
const errors = validationResult(req);
const { name, description, guidelines, date, location, imageURI } = req.body;
const {
name,
description,
guidelines,
date,
startTime,
endTime,
location,
imageURI,
description_short,
} = req.body;

try {
validationErrorParser(errors);
Expand All @@ -45,10 +56,14 @@ export const createEventDetails: RequestHandler = async (req, res, next) => {
description,
guidelines,
date,
startTime,
endTime,
location,
imageURI,
description_short,
});

// console.log("added eventDetails: ", eventDetails);
res.status(201).json(eventDetails);
} catch (error) {
next(error);
Expand All @@ -60,7 +75,6 @@ export const updateEventDetails: RequestHandler = async (req, res, next) => {
const { id } = req.params;

if (id !== req.body._id) {
// If the _id in the URL does not match the _id in the body, bad request
res.status(400);
}

Expand All @@ -75,10 +89,26 @@ export const updateEventDetails: RequestHandler = async (req, res, next) => {
const updatedEventDetails = await EventDetails.findById(id);
if (updatedEventDetails === null) {
// No event found, something went wrong
console.log("updatedEventDetails is null");
res.status(404);
}
res.status(200).json(updatedEventDetails);
} catch (error) {
next(error);
}
};
export const deleteEventDetails: RequestHandler = async (req, res, next) => {
const { id } = req.params;

try {
const eventDetails = await EventDetails.findByIdAndDelete(id);

if (!eventDetails) {
throw createHttpError(404, "event not found");
}

res.status(200).json(eventDetails);
} catch (error) {
next(error);
}
};
1 change: 0 additions & 1 deletion backend/src/controllers/newsletter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export const createNewsletter: RequestHandler = async (req, res, next) => {
content,
});

console.log("newsletter: ", newsletter);
res.status(201).json(newsletter);
} catch (error) {
console.error("Error creating newsletter:", error);
Expand Down
20 changes: 9 additions & 11 deletions backend/src/controllers/pageeditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,37 @@ import PageEditor from "src/models/pageeditor";
import validationErrorParser from "src/util/validationErrorParser";

export const getPage: RequestHandler = async (req, res, next) => {
const { page } = req.params;
const { name } = req.params;

try {
const pageText = await PageEditor.findOne({ page: page });
const page = await PageEditor.findOne({ name: name });

if (!pageText) {
if (!page) {
throw createHttpError(404, "Page not found.");
}

res.status(200).json(pageText);
res.status(200).json(page);
} catch (error) {
next(error);
}
};

export const updatePageEditor: RequestHandler = async (req, res, next) => {
const errors = validationResult(req);
const { page } = req.params;

if (page !== req.body.page) {
const { name } = req.params;
if (name !== req.body.name) {
// If the page in the URL does not match the page in the body, bad request
res.status(400);
}

try {
validationErrorParser(errors);

const pageText = await PageEditor.findOneAndUpdate({ page }, req.body);
if (pageText === null) {
const page = await PageEditor.findOneAndUpdate({ name: name }, { $set: req.body });
if (page === null) {
// No page found
res.status(404);
}
const updatedPage = await PageEditor.findOne({ page });
const updatedPage = await PageEditor.findOne({ name: name });
if (updatedPage === null) {
// No page found after updating, something went wrong
res.status(404);
Expand Down
3 changes: 0 additions & 3 deletions backend/src/controllers/testimonial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ import validationErrorParser from "src/util/validationErrorParser";

export const createTestimonial: RequestHandler = async (req, res, next) => {
const { title, description, image, type } = req.body;

try {
const testimonial = await TestimonialModel.create({
title: title,
description: description,
image: image,
type: type,
});
console.log("testimonial: ", testimonial);

res.status(201).json(testimonial);
} catch (error) {
console.log("erroring here");
next(error);
}
};
Expand Down
3 changes: 3 additions & 0 deletions backend/src/models/eventDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ const eventDetailsSchema = new Schema({
description: { type: String, required: true },
guidelines: { type: String, required: true },
date: { type: String, required: true },
startTime: { type: String, required: true },
endTime: { type: String, required: true },
location: { type: String, required: true },
imageURI: { type: String, required: true },
description_short: { type: String, required: true },
});

type EventDetails = InferSchemaType<typeof eventDetailsSchema>;
Expand Down
11 changes: 9 additions & 2 deletions backend/src/models/pageeditor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { InferSchemaType, Schema, model } from "mongoose";

const pageEditorSchema = new Schema({
page: { type: String, required: true },
pageSections: [{ type: Schema.Types.Mixed, required: true }],
name: { type: String, required: true },
isEdited: { type: Boolean, required: true },
fields: [
{
name: { type: String, required: true },
type: { type: String, required: true },
data: { type: Schema.Types.Mixed, required: true },
},
],
});

type PageEditor = InferSchemaType<typeof pageEditorSchema>;
Expand Down
6 changes: 3 additions & 3 deletions backend/src/models/testimonial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { InferSchemaType, Schema, model } from "mongoose";
const testimonialSchema = new Schema({
title: { type: String, required: true },
description: { type: String, required: true },
image: { type: String, required: true },
image: { type: String, required: false },
type: { type: String, required: true },
});

type testimonial = InferSchemaType<typeof testimonialSchema>;
type Testimonial = InferSchemaType<typeof testimonialSchema>;

export default model<testimonial>("testimonial", testimonialSchema);
export default model<Testimonial>("Testimonial", testimonialSchema);
5 changes: 5 additions & 0 deletions backend/src/routes/eventDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ router.post(
EventDetailsValidator.createEventDetails,
EventDetailsController.createEventDetails,
);
router.delete(
"/:id",
EventDetailsValidator.deleteEventDetails,
EventDetailsController.deleteEventDetails,
);

export default router;
8 changes: 2 additions & 6 deletions backend/src/routes/pageeditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import * as PageEditorValidator from "src/validators/pageeditor";

const router = express.Router();

router.get("/:page", PageEditorValidator.getPageEditor, PageEditorController.getPage);
router.put(
"/:page", // getPageEditor validator works to just check page
// PageEditorValidator.getPageEditor,
PageEditorController.updatePageEditor,
);
router.get("/:name", PageEditorValidator.getPageEditor, PageEditorController.getPage);
router.put("/:name", PageEditorValidator.updatePageEditor, PageEditorController.updatePageEditor);

export default router;
2 changes: 1 addition & 1 deletion backend/src/services/paypal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const generateAccessToken = async () => {
});

const data = await response.json();

return data.access_token;
} catch (error) {
console.error("Failed to generate PayPal Access Token: ", error);
Expand All @@ -62,6 +61,7 @@ async function handleResponse(response: Response) {

export async function createOrder(cart: Cart) {
const accessToken = await generateAccessToken();
console.log("creating order with ", accessToken);
const url = `${base}/v2/checkout/orders`;

const payload = {
Expand Down
9 changes: 9 additions & 0 deletions backend/src/validators/eventDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ const makeImageURIValidator = () =>
.bail()
.isURL()
.withMessage("imageURI must be a URL");
const makeDescriptionShortValidator = () =>
body("description_short")
.exists()
.withMessage("description_short is required")
.bail()
.isString()
.withMessage("description_short must be a string");

export const createEventDetails = [
makeNameValidator(),
Expand All @@ -60,6 +67,8 @@ export const createEventDetails = [
makeDateValidator(),
makeLocationValidator(),
makeImageURIValidator(),
makeDescriptionShortValidator(),
];

export const getEventDetails = [makeIDValidator()];
export const deleteEventDetails = [makeIDValidator()];
Loading

0 comments on commit 28811ab

Please sign in to comment.