Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dbec41a

Browse files
Merge pull request #121 from MassiGy/code-cleanup
Code cleanup + Optimization + Refactoring.
2 parents 10a4f89 + 0ef3a29 commit dbec41a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1057
-820
lines changed

‎res/emails/confirmEmail.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ <h3 style="text-align:center; padding-bottom:5px;">
1010
Hey <b>${data.username}</b>,
1111
<br />
1212
Please validate your email address on fairfieldprogramming.org by clicking
13+
<!-- <a href="http://localhost:8080/user/confirmEmail/${id_token}">this link</a>. -->
1314
<a href="https://fairfield-programming.herokuapp.com/user/confirmEmail/${id_token}">this link</a>.
1415
<br />
1516
</p>

‎res/emails/eventNotification.html‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<img src="https://raw.githubusercontent.com/fairfield-programming/.github/main/spread.png"
2+
style="width:90%; margin-left:5%;" />
3+
<hr />
4+
<h3 style="text-align:center; padding-bottom:5px;">
5+
Notification From Fairfield Programming Association
6+
</h3>
7+
<hr />
8+
<p>
9+
<br />
10+
Hey <b>${sub.username}</b>,
11+
<br />
12+
The event named <b> ${event.name}</b> will take place soon. Consider <a href="https://fairfieldprogramming.org/login/">login</a> in the platform to stay up to date now !
13+
<br />
14+
</p>
15+
<p>
16+
<br />
17+
Thanks for joining us !
18+
<br />
19+
Kind Regards.
20+
<br />
21+
<address>fairfieldprogramming.org <b> team </b></address>
22+
</p>
23+
<hr />
24+
<footer style="color:grey">
25+
fairfieldprogramming.org is an open-source,
26+
non-profit association dedicated to the education of children in the world of computer science.
27+
We host competitions, events, and websites in order to forward the learning experience of highschool and college
28+
students.
29+
Since we are a non-profit and an open-source organization, we would love it if you contribute or donate,
30+
but that is fully up to you!
31+
</footer>
32+
<hr />

‎src/constants.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
22
MAX_UNCONFIRMED_ACCOUNT_AGE: 30 * 24 * 60 * 60 * 1000, // 30 days
33
EMAIL_CONFIRMATION_REMAINDER_TIMEOUT: 14 * 24 * 60 * 60 * 1000, // 14 days
4+
EVENT_REMAINDER: 1 * 24 * 60 * 60 * 1000, // 1 day
45
};
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const { handleError500 } = require('../../library/errorHandler');
21

32
function missingParameters(req) {
43
const { title, description, body } = req.body;
@@ -7,6 +6,7 @@ function missingParameters(req) {
76

87
/**
98
* @module Create Article Controller
9+
*
1010
* @param {Request} req - HTTP Request from the client
1111
* @param {Response} res - HTTP Response for the client
1212
*
@@ -16,17 +16,25 @@ function missingParameters(req) {
1616
* @todo
1717
* Nothing for now.
1818
*/
19-
module.exports.createArticle = async(req, res) => {
20-
if (missingParameters(req)) res.status(400).send("Not All Parameters Provided.");
21-
try {
19+
20+
module.exports.createArticle = async (req, res) => {
21+
22+
if (missingParameters(req)) {
23+
return res.status(400).send({ msg: "Not All Parameters Provided." });
24+
}
25+
26+
try {
27+
2228
const article = await Article.create({
2329
title: req.body.title,
2430
description: req.body.description,
2531
body: req.body.body,
2632
});
2733

28-
return res.json({ article });
29-
} catch (e) {
30-
handleError500(req, res, e);
34+
return res.status(200).json(article);
35+
36+
} catch (err) {
37+
console.log(err.message);
38+
return res.status(500).send({ msg: 'Error on creating an article.' });
3139
}
3240
};
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* @module Get All Articles Controller
3+
*
34
* @param {Request} req - HTTP Request from the client
45
* @param {Response} res - HTTP Response for the client
56
*
@@ -9,16 +10,20 @@
910
* @todo
1011
* Nothing for now.
1112
*/
13+
1214
module.exports.getAllArticles = async (req, res) => {
15+
1316
try {
1417
const articles = await Article.findAll({});
1518

1619
if (!articles?.length) {
1720
return res.status(404).send({ msg: 'No articles found' });
1821
}
1922

20-
return res.json({ articles });
21-
} catch (e) {
22-
return res.status(500).send({ msg: 'Server error' });
23+
return res.status(200).json(articles);
24+
25+
} catch (err) {
26+
console.log(err.message);
27+
return res.status(500).send({ msg: 'Error on searching for all articles.' });
2328
}
2429
};
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* @module Query Article Controller
3+
*
34
* @param {Request} req - HTTP Request from the client
45
* @param {Response} res - HTTP Response for the client
56
*
@@ -12,23 +13,27 @@
1213
*/
1314

1415
module.exports.queryArticle = async (req, res) => {
16+
1517
if (!req.params.id) {
1618
return res.status(400).send({ msg: 'Missing parameters' });
1719
}
1820

1921
try {
20-
const articles = await Article.findOne({
22+
23+
const article = await Article.findOne({
2124
where: {
2225
id: req.params.id,
2326
},
2427
});
2528

26-
if (!articles?.length) {
27-
return res.status(404).send({ msg: 'No articles found' });
29+
if (!article) {
30+
return res.status(404).send({ msg: 'Article not found' });
2831
}
2932

30-
return res.json({ articles });
31-
} catch (e) {
32-
return res.status(500).send({ msg: 'Server error' });
33+
return res.status(200).json(article);
34+
35+
} catch (err) {
36+
console.log(err.message);
37+
return res.status(500).send({ msg: 'Error on querying an article.' });
3338
}
3439
};

‎src/controllers/Duck/getDuck.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const duckGenerator = require('duckgen');
22

33
/**
44
* @module Get Duck Controller
5+
*
56
* @param {Request} req - HTTP Request from the client
67
* @param {Response} res - HTTP Response for the client
78
*
@@ -14,5 +15,5 @@ const duckGenerator = require('duckgen');
1415

1516
module.exports.getDuck = (req, res) => {
1617
res.set('Content-Type', 'image/svg+xml');
17-
return res.send(duckGenerator.formatSVG(duckGenerator.generateDuck({})));
18+
return res.status(200).send(duckGenerator.formatSVG(duckGenerator.generateDuck({})));
1819
};

‎src/controllers/Duck/getDuckById.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const duckGenerator = require('duckgen');
22

33
/**
44
* @module Get Duck By ID Controller
5+
*
56
* @param {Request} req - HTTP Request from the client
67
* @param {Response} res - HTTP Response for the client
78
*
@@ -20,5 +21,5 @@ module.exports.getDuckById = (req, res) => {
2021

2122
res.set('Content-Type', 'image/svg+xml');
2223

23-
return res.send(duckGenerator.formatSVG(duckGenerator.generateDuck(duckData)));
24+
return res.status(200).send(duckGenerator.formatSVG(duckGenerator.generateDuck(duckData)));
2425
};

‎src/controllers/Duck/getZoomedDuck.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const duckGenerator = require('duckgen');
22

33
/**
44
* @module Get Duck Controller
5+
*
56
* @param {Request} req - HTTP Request from the client
67
* @param {Response} res - HTTP Response for the client
78
*
@@ -14,12 +15,14 @@ const duckGenerator = require('duckgen');
1415

1516

1617
module.exports.getZoomedDuck = (req, res) => {
18+
1719
const duckData = duckGenerator.parseV1String(req.params.id);
20+
1821
if (!duckData) {
1922
return res.status(400).send({ msg: 'Invalid duck ID' });
2023
}
2124

2225
const zoomInt = parseInt(req.params.zoom, 10);
2326
res.set('Content-Type', 'image/svg+xml');
24-
return res.send(duckGenerator.formatSVG(duckGenerator.generateDuck(duckData), zoomInt));
27+
return res.status(200).send(duckGenerator.formatSVG(duckGenerator.generateDuck(duckData), zoomInt));
2528
};

‎src/controllers/Events/createEvent.js‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { missingParameters } = require('../../library/eventsUtils');
33

44
/**
55
* @module Create Event Controller
6+
*
67
* @param {Request} req - HTTP Request from the client
78
* @param {Response} res - HTTP Response for the client
89
*
@@ -13,9 +14,10 @@ const { missingParameters } = require('../../library/eventsUtils');
1314
* Nothing for now.
1415
*/
1516

16-
module.exports.createEvent = async(req, res) => {
17+
module.exports.createEvent = async (req, res) => {
18+
1719
if (!req.user) {
18-
return res.status(400).send({ msg: 'You must be logged in to create an event' });
20+
return res.status(400).send({ msg: 'Not logged in.' });
1921
}
2022

2123

@@ -24,7 +26,8 @@ module.exports.createEvent = async(req, res) => {
2426
}
2527

2628
try {
27-
const eventData = await Events.create({
29+
30+
const event = await Events.create({
2831
name: req.body.name,
2932
location: req.body.location,
3033
description: req.body.description,
@@ -36,18 +39,22 @@ module.exports.createEvent = async(req, res) => {
3639

3740
const user = await User.findOne({ where: { id: req.user.id } });
3841

39-
await user.addEvents(eventData);
42+
if (!user) return res.status(404).send({ msg: 'Current user not found.' });
43+
44+
user.addEvents(event);
4045

4146
return res.json({
42-
name: eventData.name,
43-
location: eventData.location,
44-
description: eventData.description,
45-
host: eventData.host,
46-
eventImage: eventData.eventImage,
47-
status: eventData.status,
48-
date: eventData.date,
47+
name: event.name,
48+
location: event.location,
49+
description: event.description,
50+
host: event.host,
51+
eventImage: event.eventImage,
52+
status: event.status,
53+
date: event.date,
4954
});
50-
} catch (e) {
51-
return res.status(400).send({ msg: 'Error creating event' });
55+
56+
} catch (err) {
57+
console.log(err.message);
58+
return res.status(400).send({ msg: 'Error on creating event.' });
5259
}
5360
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /