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

Finish project #48

Merged
merged 7 commits into from
Jun 30, 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
2 changes: 1 addition & 1 deletion backend/dist/controllers/eventDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ 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, startTime, endTime, location, imageURI, description_short, } = req.body;
console.log("events date: ", date);
try {
(0, validationErrorParser_1.default)(errors);
const eventDetails = yield eventDetails_1.default.create({
Expand Down Expand Up @@ -83,7 +84,6 @@ 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 Down
18 changes: 9 additions & 9 deletions backend/dist/controllers/pageeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ const http_errors_1 = __importDefault(require("http-errors"));
const pageeditor_1 = __importDefault(require("../models/pageeditor"));
const validationErrorParser_1 = __importDefault(require("../util/validationErrorParser"));
const getPage = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
const { page } = req.params;
const { name } = req.params;
try {
const pageText = yield pageeditor_1.default.findOne({ page: page });
if (!pageText) {
const page = yield pageeditor_1.default.findOne({ name: name });
if (!page) {
throw (0, http_errors_1.default)(404, "Page not found.");
}
res.status(200).json(pageText);
res.status(200).json(page);
}
catch (error) {
next(error);
Expand All @@ -33,19 +33,19 @@ const getPage = (req, res, next) => __awaiter(void 0, void 0, void 0, function*
exports.getPage = getPage;
const updatePageEditor = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
const errors = (0, express_validator_1.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 {
(0, validationErrorParser_1.default)(errors);
const pageText = yield pageeditor_1.default.findOneAndUpdate({ page }, req.body);
if (pageText === null) {
const page = yield pageeditor_1.default.findOneAndUpdate({ name: name }, { $set: req.body });
if (page === null) {
// No page found
res.status(404);
}
const updatedPage = yield pageeditor_1.default.findOne({ page });
const updatedPage = yield pageeditor_1.default.findOne({ name: name });
if (updatedPage === null) {
// No page found after updating, something went wrong
res.status(404);
Expand Down
7 changes: 7 additions & 0 deletions backend/dist/controllers/records.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ exports.getRecord = getRecord;
const updateRecord = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
const { card } = req.params;
try {
console.log("req.body: ", req.body);
const record = yield records_1.default.findOneAndUpdate({ card: card }, req.body);
if (record === null) {
res.status(404);
Expand All @@ -39,6 +40,12 @@ const updateRecord = (req, res, next) => __awaiter(void 0, void 0, void 0, funct
if (updatedRecord === null) {
res.status(404);
}
if (card === "home" || card === "about" || card === "involved" || card === "impact") {
const pageRecord = yield records_1.default.findOneAndUpdate({ card: "page-editor" }, { date: req.body.date });
if (pageRecord === null) {
res.status(404);
}
}
res.status(200).json(updatedRecord);
}
catch (error) {
Expand Down
2 changes: 0 additions & 2 deletions backend/dist/controllers/testimonial.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ const createTestimonial = (req, res, next) => __awaiter(void 0, void 0, void 0,
image: image,
type: type,
});
console.log("testimonial: ", testimonial);
res.status(201).json(testimonial);
}
catch (error) {
console.log("erroring here");
next(error);
}
});
Expand Down
11 changes: 9 additions & 2 deletions backend/dist/models/pageeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
Object.defineProperty(exports, "__esModule", { value: true });
const mongoose_1 = require("mongoose");
const pageEditorSchema = new mongoose_1.Schema({
page: { type: String, required: true },
pageSections: [{ type: mongoose_1.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: mongoose_1.Schema.Types.Mixed, required: true },
},
],
});
exports.default = (0, mongoose_1.model)("PageEditor", pageEditorSchema);
4 changes: 2 additions & 2 deletions backend/dist/models/testimonial.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const mongoose_1 = require("mongoose");
const testimonialSchema = new mongoose_1.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 },
});
exports.default = (0, mongoose_1.model)("testimonial", testimonialSchema);
exports.default = (0, mongoose_1.model)("Testimonial", testimonialSchema);
6 changes: 2 additions & 4 deletions backend/dist/routes/pageeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ const express_1 = __importDefault(require("express"));
const PageEditorController = __importStar(require("../controllers/pageeditor"));
const PageEditorValidator = __importStar(require("../validators/pageeditor"));
const router = express_1.default.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);
exports.default = router;
14 changes: 9 additions & 5 deletions backend/dist/services/paypal.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.captureOrder = exports.createOrder = void 0;
const PAYPAL_CLIENT_ID = process.env.PAYPAL_CLIENT_ID;
const PAYPAL_CLIENT_SECRET = process.env.PAYPAL_CLIENT_SECRET;
const base = "https://api-m.sandbox.paypal.com";
const ORIGIN_URL = process.env.FRONTEND_ORIGIN;
const base = "https://api-m.paypal.com";
/**
* Generate an OAuth 2.0 token to authenticate with PayPal REST APIs
* @see https://developer.paypal.com/api/rest/authentication/
Expand All @@ -23,12 +24,16 @@ const generateAccessToken = () => __awaiter(void 0, void 0, void 0, function* ()
throw new Error("MISSING_PAYPAL_API_CREDENTIALS");
}
const auth = Buffer.from(PAYPAL_CLIENT_ID + ":" + PAYPAL_CLIENT_SECRET).toString("base64");
const headersList = {
Accept: "*/*",
"User-Agent": `4 Future Leaders Of Tomorrow Web App (${ORIGIN_URL})`,
"Content-Type": "application/x-www-form-urlencoded",
Authorization: `Basic ${auth}`,
};
const response = yield fetch(`${base}/v1/oauth2/token`, {
method: "POST",
body: "grant_type=client_credentials",
headers: {
Authorization: `Basic ${auth}`,
},
headers: headersList,
});
const data = yield response.json();
return data.access_token;
Expand Down Expand Up @@ -56,7 +61,6 @@ function createOrder(cart) {
return __awaiter(this, void 0, void 0, function* () {
const accessToken = yield generateAccessToken();
const url = `${base}/v2/checkout/orders`;
console.log("shopping cart info", cart);
const payload = {
intent: "CAPTURE",
purchase_units: [
Expand Down
46 changes: 14 additions & 32 deletions backend/dist/validators/pageeditor.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createPageEditor = exports.getPageEditor = void 0;
exports.updatePageEditor = exports.getPageEditor = void 0;
const express_validator_1 = require("express-validator");
const makeIDValidator = () => (0, express_validator_1.body)("_id")
const makeNameValidator = () => (0, express_validator_1.body)("name")
.exists()
.withMessage("_id is required")
.withMessage("name is required")
.bail()
.isString()
.withMessage("_id must be a number");
const makePageValidator = () => (0, express_validator_1.body)("page")
.withMessage("name must be a string");
const makeEditedValidator = () => (0, express_validator_1.body)("isEdited")
.exists()
.withMessage("image is required")
.withMessage("isEdited is required")
.bail()
.isString()
.withMessage("image must be a string");
const makeSubtitleValidator = () => (0, express_validator_1.body)("ph_subtitle")
.exists()
.withMessage("subtitle is required")
.bail()
.isString()
.withMessage("subtitle must be a string");
const makeTitleValidator = () => (0, express_validator_1.body)("s1_title")
.isBoolean()
.withMessage("isEdited must be a boolean");
const makeFieldsValidator = () => (0, express_validator_1.body)("fields")
.exists()
.withMessage("date is required")
.withMessage("fields is required")
.bail()
.isString()
.withMessage("date must be a string");
const makeTextValidator = () => (0, express_validator_1.body)("s1_text")
.exists()
.withMessage("content is required")
.bail()
.isString()
.withMessage("content must be a string");
exports.getPageEditor = [makePageValidator()];
exports.createPageEditor = [
makeIDValidator(),
makePageValidator(),
makeSubtitleValidator(),
makeTitleValidator(),
makeTextValidator(),
];
.isArray()
.withMessage("fields must be an array");
exports.getPageEditor = [makeNameValidator(), makeEditedValidator(), makeFieldsValidator()];
exports.updatePageEditor = [makeNameValidator(), makeEditedValidator(), makeFieldsValidator()];
13 changes: 1 addition & 12 deletions backend/dist/validators/testimonial.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,7 @@ const makeDescriptionValidator = () => (0, express_validator_1.body)("descriptio
.bail()
.notEmpty()
.withMessage("description cannot be empty");
const makeImageValidator = () => (0, express_validator_1.body)("image")
// title must exist, if not this message will be displayed
.exists()
.withMessage("image is required")
// bail prevents the remainder of the validation chain for this field from being executed if
// there was an error
.bail()
.isString()
.withMessage("image must be a string")
.bail()
.notEmpty()
.withMessage("image cannot be empty");
const makeImageValidator = () => (0, express_validator_1.body)("image").optional().isString().withMessage("image must be a string");
exports.createTestimonial = [
makeTitleValidator(),
makeImageValidator(),
Expand Down
5 changes: 2 additions & 3 deletions backend/src/controllers/eventDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ 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,
Expand All @@ -48,6 +47,8 @@ export const createEventDetails: RequestHandler = async (req, res, next) => {
description_short,
} = req.body;

console.log("events date: ", date);

try {
validationErrorParser(errors);

Expand All @@ -63,7 +64,6 @@ export const createEventDetails: RequestHandler = async (req, res, next) => {
description_short,
});

// console.log("added eventDetails: ", eventDetails);
res.status(201).json(eventDetails);
} catch (error) {
next(error);
Expand All @@ -89,7 +89,6 @@ 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);
Expand Down
11 changes: 11 additions & 0 deletions backend/src/controllers/records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const updateRecord: RequestHandler = async (req, res, next) => {
const { card } = req.params;

try {
console.log("req.body: ", req.body);
const record = await RecordModel.findOneAndUpdate({ card: card }, req.body);

if (record === null) {
Expand All @@ -29,6 +30,16 @@ export const updateRecord: RequestHandler = async (req, res, next) => {
res.status(404);
}

if (card === "home" || card === "about" || card === "involved" || card === "impact") {
const pageRecord = await RecordModel.findOneAndUpdate(
{ card: "page-editor" },
{ date: req.body.date },
);
if (pageRecord === null) {
res.status(404);
}
}

res.status(200).json(updatedRecord);
} catch (error) {
next(error);
Expand Down
1 change: 0 additions & 1 deletion backend/src/services/paypal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion frontend/src/api/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export async function post(
headers: Record<string, string> = {},
): Promise<Response> {
const response = await fetchRequest("POST", API_BASE_URL + url, body, headers);
console.log("fetch response: ", response);
await assertOk(response);
return response;
}
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/app/(web app)/donations/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import DonateApp from "../../../components/payment/DonateApp";

export default function App() {
export default function Donations() {
return (
<div
className="w-full h-[100vh] flex justify-center items-center"
className="w-full h-[220vh] flex justify-center items-start"
style={{
backgroundImage:
"url(https://firebasestorage.googleapis.com/v0/b/flot-dev.appspot.com/o/static-uploads%2Fimage.png?alt=media&token=44407612-8c8e-492a-988a-2c211d2926bb)",
backgroundImage: "url(/donations/donationsbackground.png)",
backgroundPosition: "center",
backgroundSize: "cover",
backgroundRepeat: "no-repeat",
paddingTop: "80px",
}}
>
<DonateApp />
Expand Down
1 change: 0 additions & 1 deletion frontend/src/app/(web app)/team/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export default function Team() {
getAllMembers()
.then((result) => {
if (result.success) {
console.log(result.data);
setMembers(result.data);
} else {
alert(result.error);
Expand Down
1 change: 0 additions & 1 deletion frontend/src/app/(web app)/testimonials/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default function Impact() {
const [loading, setLoading] = useState(false);

const loadTestimonials = () => {
console.log("getting from loadTestimonials");
getAllTestimonials()
.then((result) => {
if (result.success) {
Expand Down
Loading
Loading