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/christenjack/storage #46

Merged
merged 19 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
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
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);
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;
55 changes: 18 additions & 37 deletions backend/src/validators/pageeditor.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,28 @@
import { body } from "express-validator";

const makeIDValidator = () =>
body("_id")
const makeNameValidator = () =>
body("name")
.exists()
.withMessage("_id is required")
.withMessage("name is required")
.bail()
.isString()
.withMessage("_id must be a number");
const makePageValidator = () =>
body("page")
.exists()
.withMessage("image is required")
.bail()
.isString()
.withMessage("image must be a string");
const makeSubtitleValidator = () =>
body("ph_subtitle")
.exists()
.withMessage("subtitle is required")
.bail()
.isString()
.withMessage("subtitle must be a string");
const makeTitleValidator = () =>
body("s1_title")
.withMessage("name must be a string");

const makeEditedValidator = () =>
body("isEdited")
.exists()
.withMessage("date is required")
.withMessage("isEdited is required")
.bail()
.isString()
.withMessage("date must be a string");
const makeTextValidator = () =>
body("s1_text")
.isBoolean()
.withMessage("isEdited must be a boolean");

const makeFieldsValidator = () =>
body("fields")
.exists()
.withMessage("content is required")
.withMessage("fields is required")
.bail()
.isString()
.withMessage("content must be a string");

export const getPageEditor = [makePageValidator()];
.isArray()
.withMessage("fields must be an array");

export const createPageEditor = [
makeIDValidator(),
makePageValidator(),
makeSubtitleValidator(),
makeTitleValidator(),
makeTextValidator(),
];
export const getPageEditor = [makeNameValidator(), makeEditedValidator(), makeFieldsValidator()];
export const updatePageEditor = [makeNameValidator(), makeEditedValidator(), makeFieldsValidator()];
13 changes: 1 addition & 12 deletions backend/src/validators/testimonial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,7 @@ const makeDescriptionValidator = () =>
.withMessage("description cannot be empty");

const makeImageValidator = () =>
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");
body("image").optional().isString().withMessage("image must be a string");

export const createTestimonial = [
makeTitleValidator(),
Expand Down
2 changes: 2 additions & 0 deletions frontend/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const nextConfig = {
"i.imgur.com",
"images.unsplash.com",
"plus.unsplash.com",
"firebasestorage.googleapis.com",
"tse.ucsd.edu",
],
},
};
Expand Down
70 changes: 70 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"date-fns": "^3.6.0",
"envalid": "^8.0.0",
"firebase": "^10.11.0",
"framer-motion": "^11.2.6",
"html2canvas": "^1.4.1",
"html2pdf.js": "^0.9.3",
"jspdf": "^2.5.1",
Expand All @@ -32,7 +33,9 @@
"react": "^18",
"react-datepicker": "^6.9.0",
"react-dom": "^18",
"react-dropzone": "^14.2.3",
"react-firebase-hooks": "^5.1.1",
"react-icons": "^5.2.1",
"react-material-symbols": "^4.3.1"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions frontend/public/pastEvents.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 1 addition & 9 deletions frontend/src/api/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,8 @@ export async function updateMember(member: updateMemberRequest): Promise<APIResu
}
}

type cancelMemberRequest = {
_id: string;
name: string;
role: string;
profilePictureURL?: string;
};

export async function deleteMember(member: cancelMemberRequest): Promise<APIResult<Member>> {
export async function deleteMember(id: string): Promise<APIResult<Member>> {
try {
const id = member._id;
const response = await del(`/api/member/${id}`);
const json = (await response.json()) as Member;
return { success: true, data: json };
Expand Down
Loading
Loading