Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/kevinsophia/event creator #44

Merged
merged 18 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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;
5 changes: 5 additions & 0 deletions backend/src/services/paypal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const PAYPAL_CLIENT_ID = process.env.PAYPAL_CLIENT_ID;
const PAYPAL_CLIENT_SECRET = process.env.PAYPAL_CLIENT_SECRET;

console.log("CLIENT ID: ", PAYPAL_CLIENT_ID, " SECRET: ", PAYPAL_CLIENT_SECRET);

const base = "https://api-m.sandbox.paypal.com";

/**
Expand All @@ -24,6 +26,7 @@ const generateAccessToken = async () => {
throw new Error("MISSING_PAYPAL_API_CREDENTIALS");
}
const auth = Buffer.from(PAYPAL_CLIENT_ID + ":" + PAYPAL_CLIENT_SECRET).toString("base64");
console.log("auth: ", auth);
const response = await fetch(`${base}/v1/oauth2/token`, {
method: "POST",
body: "grant_type=client_credentials",
Expand All @@ -33,6 +36,7 @@ const generateAccessToken = async () => {
});

const data = await response.json();
console.log("ACCESS TOKEN RESPONSE: ", data);
return data.access_token;
} catch (error) {
console.error("Failed to generate PayPal Access Token: ", error);
Expand All @@ -54,6 +58,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`;
console.log("shopping cart info", cart);

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
Loading