Skip to content

Commit cc04449

Browse files
authored
Merge pull request #51 from Lashen1227/development
Development
2 parents 402b549 + ec0736a commit cc04449

Some content is hidden

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

49 files changed

+3114
-262
lines changed

.github/workflows/node.js.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI for Node.js and React (Vite)
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
jobs:
10+
frontend-build:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node-version: [16.x, 18.x, 20.x]
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
25+
- name: Install frontend dependencies
26+
run: npm install
27+
working-directory: ./frontend
28+
29+
- name: Run frontend basic test
30+
run: |
31+
echo "Running frontend basic test..."
32+
echo "Frontend test passed!"
33+
working-directory: ./frontend

backend/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
node_modules
2-
2+
package-lock.json

backend/controllers/organizationController.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ const mongoose = require('mongoose');
44
const getAllOrganizations = async (req, res) => {
55
const organizations = await Organization.find({}).sort({createdAt: -1});
66
setTimeout(() => {
7-
console.log(organizations)
7+
console.log(organizations);
88
res.status(200).json(organizations);
99
}, 2000);
10-
}
10+
};
1111

1212
const getOrganization = async (req, res) => {
1313
const { id } = req.params;
1414

1515
if(!mongoose.Types.ObjectId.isValid(id)){
16-
return res.status(404).json({error: 'No such organization with that id'})
16+
return res.status(404).json({error: 'No such organization with that id'});
1717
}
1818

1919
const organization = await Organization.findById(id);
@@ -23,7 +23,7 @@ const getOrganization = async (req, res) => {
2323
}
2424

2525
res.status(200).json(organization);
26-
}
26+
};
2727

2828
const createOrganization = async (req, res) => {
2929
const {
@@ -35,11 +35,12 @@ const createOrganization = async (req, res) => {
3535
website,
3636
userID,
3737
profilePic,
38+
seminarLocations
3839
} = req.body;
39-
let empltyFields = [];
40+
let emptyFields = [];
4041

4142
if (!name) {
42-
empltyFields.push('name');
43+
emptyFields.push('name');
4344
}
4445

4546
try{
@@ -51,13 +52,14 @@ const createOrganization = async (req, res) => {
5152
email,
5253
website,
5354
userID,
54-
profilePic
55-
})
56-
res.status(200).json(organization)
55+
profilePic,
56+
seminarLocations
57+
});
58+
res.status(200).json(organization);
5759
}catch(error){
5860
res.status(400).json({error: error.message});
5961
}
60-
}
62+
};
6163

6264
const deleteOrganization = async (req, res) => {
6365
const { id } = req.params;
@@ -106,4 +108,4 @@ module.exports = {
106108
createOrganization,
107109
deleteOrganization,
108110
updateOrganization
109-
}
111+
};
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
const Post = require('../models/postModel');
2+
const mongoose = require('mongoose');
3+
4+
// Create Post with Base64 Image
5+
exports.createPost = async (req, res, next) => {
6+
try {
7+
const { title, content, image } = req.body;
8+
9+
const post = await Post.create({
10+
title,
11+
content,
12+
image,
13+
});
14+
15+
res.status(201).json({ success: true, post });
16+
} catch (error) {
17+
console.error("Error creating post:", error);
18+
next(error);
19+
}
20+
};
21+
22+
// Get All Posts
23+
exports.showPost = async (req, res, next) => {
24+
try {
25+
const posts = await Post.find().sort({ createdAt: -1 });
26+
res.status(200).json({ success: true, posts });
27+
} catch (error) {
28+
console.error("Error fetching posts:", error);
29+
next(error);
30+
}
31+
};
32+
33+
// Get Single Post
34+
exports.showSinglePost = async (req, res, next) => {
35+
try {
36+
const post = await Post.findById(req.params.id);
37+
res.status(200).json({ success: true, post });
38+
} catch (error) {
39+
next(error);
40+
}
41+
};
42+
43+
// Delete Post
44+
exports.deletePost = async (req, res, next) => {
45+
try {
46+
const postId = req.params.id;
47+
48+
if (!mongoose.Types.ObjectId.isValid(postId)) {
49+
return res.status(400).json({ success: false, message: "Invalid post ID" });
50+
}
51+
52+
const post = await Post.findById(postId);
53+
if (!post) {
54+
return res.status(404).json({ success: false, message: "Post not found" });
55+
}
56+
57+
await Post.findByIdAndDelete(postId);
58+
res.status(200).json({ success: true, message: "Post deleted" });
59+
} catch (error) {
60+
console.error("Error deleting post:", error);
61+
next(error);
62+
}
63+
};
64+
65+
66+
// Update Post
67+
exports.updatePost = async (req, res, next) => {
68+
try {
69+
const { title, content, image } = req.body;
70+
const post = await Post.findById(req.params.id);
71+
if (!post) return res.status(404).json({ success: false, message: "Post not found" });
72+
73+
const updatedPost = await Post.findByIdAndUpdate(
74+
req.params.id,
75+
{ title: title || post.title, content: content || post.content, image: image || post.image },
76+
{ new: true }
77+
);
78+
79+
res.status(200).json({ success: true, updatedPost });
80+
} catch (error) {
81+
next(error);
82+
}
83+
};

0 commit comments

Comments
 (0)