Skip to content

Commit

Permalink
feat: edit hackathon data (#604)
Browse files Browse the repository at this point in the history
  • Loading branch information
suzy-g38 authored Aug 13, 2023
1 parent bcb9278 commit 4f7ac88
Show file tree
Hide file tree
Showing 7 changed files with 827 additions and 6 deletions.
2 changes: 1 addition & 1 deletion server/schema/hackathon/hackathonSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const HackathonSchema = new Schema(
// require: true,
// },
rewards: {
type: { title: String, prize: String },
type: [{ title: String, prize: String }],
required: false,
},
size: {
Expand Down
17 changes: 15 additions & 2 deletions server/src/hackathons/hackathon.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ hackathonRouter.get(
});
}
const { id } = req.params;

const hackathon = await HackathonService.getHackathonsById(id);
res.status(200).send({ success: true, hackathon: hackathon });
} catch (error) {
Expand Down Expand Up @@ -103,7 +102,21 @@ hackathonRouter.post(
});
}
const { id } = req.params;
const data = req.body;
let data = {};
data.name = req.body.name;
data.organizer = req.body.organizer;
data.description = req.body.description;
data.mode = JSON.parse(req.body.mode);
data.deadline = new Date(req.body.deadline);
data.date = new Date(req.body.date);
data.duration = parseInt(req.body.duration);
data.tags = JSON.parse(req.body.tags);
data.link = req.body.link;
data.image = req.body.image;
data.logo = req.body.logo;
data.rewards = JSON.parse(req.body.rewards);
data.eligibility = req.body.eligibility;
data.size = parseInt(req.body.size);

const hackathon = await HackathonService.updateHackathon(id, data);
res.status(200).send({ success: true, hackathon: hackathon });
Expand Down
2 changes: 1 addition & 1 deletion src/components/NewsLetter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,4 @@ const NewsLetter = () => {
);
};

export default NewsLetter;
export default NewsLetter;
4 changes: 2 additions & 2 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export type SingleHackathonType = {
slug: string;
organizer: string;
description: string;
address: { isOnline: boolean; location: string };
mode: { isOnline: boolean; location: string };
date: Date;
deadline: Date;
mode: string;
// mode: string;
rewards?: { title: string; prize: string };
size?: number;
elligibility: boolean;
Expand Down
37 changes: 37 additions & 0 deletions src/pages/api/hackathons/editHackathon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { NextApiRequest, NextApiResponse } from 'next';

export const config = {
api: {
bodyParser: true,
},
};
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
try {
const data = req.body;
const id = data.id;
const object = data.data;
const response = await fetch(
`${
process.env.NEXT_PUBLIC_API_ENDPOINT as string
}/api/hackathons/update/${id}`,
{
method: 'post',
body: JSON.stringify(object),
headers: {
'Content-type': 'application/json',
},
}
).then((r) => {
if (r.status === 500) {
throw 'Some error occurrend';
}
return r.json();
});
res.status(200).json(response);
} catch (error) {
res.status(500).json({ success: false, error: error });
}
}
27 changes: 27 additions & 0 deletions src/pages/api/hackathons/getHackathon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { NextApiRequest, NextApiResponse } from 'next';

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
try {
const id = req.body.id;
const response = await fetch(
`${process.env.NEXT_PUBLIC_API_ENDPOINT}/api/hackathons/id/${id}`,
{
method: 'get',
headers: {
'Content-type': 'application/json',
},
}
).then((resp) => {
if (resp.status === 500) {
throw 'Some error occurrend';
}
return resp.json();
});
res.status(200).json(response);
} catch (error) {
res.status(500).json({ success: false, error: error });
}
}
Loading

0 comments on commit 4f7ac88

Please sign in to comment.