Skip to content

Commit eda2eb9

Browse files
authored
Merge branch 'development' into 118-create-add-endpoint-for-accreditation
2 parents 9ea9565 + ac06611 commit eda2eb9

File tree

17 files changed

+442
-70
lines changed

17 files changed

+442
-70
lines changed

.github/workflows/test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Testing Services
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- development
8+
9+
10+
env:
11+
TOKEN_SECRET: ${{ secrets.TOKEN_SECRET }}
12+
DB_URL: ${{ secrets.DB_URL }}
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
test:
19+
name: Testing files
20+
timeout-minutes: 30
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v3
25+
- name: Set up Node
26+
uses: actions/setup-node@v3
27+
with:
28+
node-version: '18'
29+
cache: npm
30+
- name: Installation
31+
run: npm ci
32+
- name: Running Tests
33+
run: npm run test

Contribution.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Welcome to TCET Open Source contributing guide
2+
3+
Thank you for investing your time in contributing to our project!
4+
5+
In this guide you will get an overview of the contribution workflow from opening an issue, creating a PR, and merging the PR.
6+
7+
8+
## New contributor guide
9+
10+
To get an overview and installation of the project, read the [README](README.md). Here are some resources to help you get started with open source contributions:
11+
12+
- [Finding ways to contribute to open source on GitHub](https://docs.github.com/en/get-started/exploring-projects-on-github/finding-ways-to-contribute-to-open-source-on-github)
13+
- [Set up Git](https://docs.github.com/en/get-started/quickstart/set-up-git)
14+
- [GitHub flow](https://docs.github.com/en/get-started/quickstart/github-flow)
15+
- [Collaborating with pull requests](https://docs.github.com/en/github/collaborating-with-pull-requests)
16+
17+
18+
## Getting started
19+
20+
To navigate our codebase with confidence, see our [Github Repository](https://github.com/tcet-opensource/erp-backend)
21+
22+
## Issues
23+
24+
25+
#### Asking to work on an issue
26+
27+
Scan through our [existing issues](https://github.com/tcet-opensource/erp-backend/issues) to find one that interests you. You can narrow down the search using `labels` as filters. See [Labels](https://github.com/tcet-opensource/erp-backend/labels) for more information. For contributing comment on that specific issue that you want to work on it and we will assign that specific issue to you. Please remember only start working on the issue after it is assigned to you.
28+
29+
#### Create a new issue
30+
31+
If you find a bug or want to add any sort of feature in the repository , [search if an issue already exists](https://github.com/tcet-opensource/erp-backend/issues). If a related issue doesn't exist, you can open a new issue using a relevant [issue form](https://github.com/tcet-opensource/erp-backend/issues/new). Please note that the name of the issue title should be relevant and should give an idea about what you are working on.
32+
33+
34+
## Make Changes
35+
36+
### Make changes in the UI
37+
38+
Click **Make a contribution** at the bottom of erp-backend to make small changes such as a typo, sentence fix, or a broken link. This takes you to the `.md` file where you can make your changes and [create a pull request](#pull-request) for a review.
39+
40+
41+
### Make changes locally
42+
43+
1. External Contributors , Fork the repository
44+
- Using GitHub Desktop:
45+
- [Getting started with GitHub Desktop](https://docs.github.com/en/desktop/installing-and-configuring-github-desktop/getting-started-with-github-desktop) will guide you through setting up Desktop.
46+
- Once Desktop is set up, you can use it to fork the repo
47+
- Using the command line:
48+
- [Fork the repo](https://github.com/tcet-opensource/erp-backend/fork), so that you can make your changes without affecting the original project until you're ready to merge them.
49+
- After forking clone the forked repository
50+
- Switch from main branch to development branch in your cloned repository
51+
- To switch to development write command `git remote add upstream <link of original repo>` and `git fetch upstream` in the terminal
52+
- To install node modules use command `npm ci`
53+
- Switch to Development Branch and create a working branch for each issue.
54+
- To create a branch use command `git branch <name of the branch>`
55+
- NOTE: The name of the branch should in the format of -> Issue number-name of the issue (eg: 50-create_CRUD_for_infra_model)
56+
- Then from the development branch move to the branch created by using command `git checkout <branch name>`
57+
- All changes on the code should be done on your specific branch
58+
- Test your changes: After making your changes, it is crucial to thoroughly test them to ensure they function as intended and do not introduce any new bugs. Run any relevant tests or simulations and verify that the modified code performs correctly.
59+
- Before pushing the changes sync fork in the forked repo and pull the changes before pushing
60+
- After pushing go to the forked repository and press contribute and make a pull request
61+
62+
2. Internal Contributors, Clone the Repository
63+
&nbsp;
64+
`git clone -b development https://github.com/tcet-opensource/erp-backend.git`
65+
- To install node modules use command `npm ci`
66+
- Switch to Development Branch and create a working branch for each issue.
67+
- To create a branch use command `git branch <name of the branch>`
68+
- NOTE: The name of the branch should in the format of -> Issue number-name of the issue (eg: 50-create_CRUD_for_infra_model)
69+
- Then from the development branch move to the branch created by using command `git checkout <branch name>`
70+
- All changes on the code should be done on your specific branch
71+
- Test your changes: After making your changes, it is crucial to thoroughly test them to ensure they function as intended and do not introduce any new bugs. Run any relevant tests or simulations and verify that the modified code performs correctly.
72+
73+
74+
### Commit your changes
75+
- Stage your changes: Use the git add command to stage the modified files for the commit. This marks the changes as ready to be included in the next commit.
76+
`git add <file1> <file2> ...` or `git add .`
77+
- Commit your changes: Create a commit to record your modifications with a meaningful commit message. This helps in tracking and understanding the purpose of the changes.
78+
`git commit -m "relevant info of the change"`
79+
- Before pushing the changes on the repository always remember to pull the code to avoid any merge conflicts
80+
`git pull origin development`
81+
- try pushing the code on the development branch and not directly to the main branch
82+
83+
### Push your Changes
84+
- After committing your changes, you push them to a remote repository (in this case, your forked repository on GitHub) using the git push command. Pushing your changes uploads them to the remote repository, making them visible to others and allowing you to share your work.
85+
`git push origin <branch name>`
86+
87+
88+
### Pull Request
89+
90+
When you're finished with the changes, create a pull request, also known as a PR.
91+
- Don't forget to link PR to issue by using "#" issue number , if you are solving one.
92+
- Once you submit your PR, a team member will review your proposal. We may ask questions or request additional information.
93+
- We may ask for changes to be made before a PR can be merged, either using suggested changes or pull request comments. You can apply suggested changes directly through the UI. You can make any other changes in your fork, then commit them to your branch.
94+
- As you update your PR and apply changes, mark each conversation as resolved
95+
- If you run into any merge issues, checkout this [git merge conflicts](https://github.com/skills/resolve-merge-conflicts) to help you resolve merge conflicts and other issues.
96+
97+
### Your PR is merged!
98+
99+
Congratulations , The TCET Open Source team thanks you.

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ EXPOSE 3500
1212
CMD ["npm", "run", "start"]
1313

1414

15-

app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import indexRouter from "#routes/index";
99
import usersRouter from "#routes/users";
1010
import authRouter from "#routes/auth";
1111
import accreditationRouter from "#routes/accreditation";
12+
import infrastructureRouter from "#routes/infrastructure";
1213

1314
const app = express();
1415
const currDirName = dirname(fileURLToPath(import.meta.url));
@@ -28,5 +29,6 @@ app.use("/", indexRouter);
2829
app.use("/users", usersRouter);
2930
app.use("/auth", authRouter);
3031
app.use("/accreditation", accreditationRouter);
32+
app.use("/infrastructure", infrastructureRouter);
3133

3234
export default app;

controller/infrastructure.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { createinfrastructure } from "#services/infrastructure";
2+
import { logger } from "#util";
3+
4+
async function addinfrastructure(req, res) {
5+
const {
6+
name, type, wing, floor, capacity,
7+
} = req.body;
8+
try {
9+
const newinfrastructure = await createinfrastructure(name, type, wing, floor, capacity);
10+
res.json({ res: `added user ${newinfrastructure.id}` });
11+
} catch (error) {
12+
logger.error("Error while inserting", error);
13+
res.status(500);
14+
res.json({ err: "Error while inserting in DB" });
15+
}
16+
}
17+
18+
export default { addinfrastructure };

models/assignment.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import connector from '#models/databaseUtil';
2+
3+
const assignmentSchema = {
4+
no: { type: Number, required: true },
5+
title: { type: String, required: true },
6+
type: { type: String, required: true, enum: ['FA', 'RA'] },
7+
marks: { type: Number, required: true },
8+
};
9+
10+
const Assignment = connector.model('Assignment', assignmentSchema);

models/attendance.js

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,63 @@ import connector from "./databaseUtil";
33
connector.set("debug", true);
44

55
const attendanceSchema = {
6-
date: { type: Date, required: true },
7-
time: { type: String, required: true },
8-
absentees: { type: Array },
6+
student: { type: connector.Schema.Types.ObjectId, ref: "Student", required: "true" },
7+
course: { type: connector.Schema.Types.ObjectId, ref: "Course", required: "true" },
8+
monthlyAttended: { type: Number, default: 0 },
9+
monthlyOccured: { type: Number, default: 0 },
10+
cumulativeAttended: { type: Number, default: 0 },
11+
cumulativeOccured: { type: Number, default: 0 },
912
};
1013

1114
const Attendance = connector.model("Attendance", attendanceSchema);
1215

13-
async function create(date, time, absentees) {
14-
const attendance = new Attendance({
15-
date,
16-
time,
17-
absentees,
18-
});
19-
const newAttendence = await attendance.save();
20-
return newAttendence;
16+
async function create(studentId, courseId) {
17+
try {
18+
const attendance = new Attendance({
19+
student: studentId,
20+
course: courseId,
21+
});
22+
const createAttendance = await attendance.save();
23+
return createAttendance;
24+
} catch (error) {
25+
console.error("Error creating attendance:", error);
26+
return null;
27+
}
2128
}
2229

23-
async function remove(filter) {
24-
const res = await Attendance.findOneAndDelete(filter);
25-
return res;
30+
async function read(attendanceId) {
31+
try {
32+
const attendance = await Attendance.findById(attendanceId);
33+
return attendance;
34+
} catch (error) {
35+
console.error("error reading attendance", error);
36+
return null;
37+
}
2638
}
2739

28-
async function grantAttendance(roll, date) {
29-
const res = await Attendance.findOneAndUpdate(
30-
date,
31-
{ $pull: { absentees: roll } },
32-
{ new: true },
33-
);
34-
return res;
40+
async function update(attendanceId, updateData) {
41+
try {
42+
const updatedAttendance = await Attendance.findByIdAndUpdate(
43+
attendanceId,
44+
updateData,
45+
{ new: true },
46+
);
47+
return updatedAttendance;
48+
} catch (error) {
49+
console.error("error updating attendance:", error);
50+
return null;
51+
}
3552
}
3653

54+
async function remove(attendanceId) {
55+
try {
56+
const deletedAttendance = await Attendance.findByIdAndDelete(attendanceId);
57+
return deletedAttendance;
58+
} catch (error) {
59+
console.error("error removing attendance", error);
60+
return null;
61+
}
62+
}
3763
export default {
38-
create, remove, grantAttendance,
64+
create, remove, update, read,
3965
};

models/course.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
const { connector } = require('#models/databaseUtil')
2+
3+
const courseSchema = {
4+
name: { type: String, required: true },
5+
code: { type: String, required: true },
6+
theoryHours: { type: Number, required: true },
7+
tutorialHours: { type: Number, required: true },
8+
practicalHours: { type: Number, required: true },
9+
totalCredit: { type: Number, required: true },
10+
ISAMarks: { type: Number, required: true },
11+
ESEMarks: { type: Number, required: true },
12+
tutorialMarks: { type: Number, required: true },
13+
practicalMarks: { type: Number, required: true },
14+
semester: {
15+
type: connector.Schema.Types.ObjectId,
16+
ref: 'Semester',
17+
required: true,
18+
},
19+
subType: {
20+
type: String,
21+
enum: ['open', 'professional', 'core'],
22+
required: true,
23+
}, // can be open, professional, or core
24+
prerequisites: { type: [String], required: true }, // array of strings
25+
objective: { type: String, required: true },
26+
outcomes: [
27+
{
28+
outcome: { type: String },
29+
RBTLevel: { type: [String] },
30+
},
31+
], // this is the modules from syllabus
32+
modules: [{ type: connector.Schema.Types.ObjectId, ref: 'Module' }],
33+
practicals: [{ type: connector.Schema.Types.ObjectId, ref: 'Practical' }],
34+
tutorials: [{ type: connector.Schema.Types.ObjectId, ref: 'Tutorial' }],
35+
assignments: [{ type: connector.Schema.Types.ObjectId, ref: 'Assignment' }],
36+
reccTextbooks: { type: [String], required: true },
37+
refBooks: { type: [String], required: true },
38+
evalScheme: { type: [Number], required: true },
39+
}
40+
41+
// virtual for total hours
42+
courseSchema.virtual('totalHours').get(function() {
43+
return this.theoryHours + this.tutorialHours + this.practicalHours
44+
})
45+
46+
// virtual for theory marks
47+
courseSchema.virtual('theoryMarks').get(function() {
48+
return this.ISAMarks + this.ESEMarks
49+
})
50+
51+
// virtual for total marks
52+
courseSchema.virtual('totalMarks').get(function() {
53+
return this.theoryMarks + this.tutorialMarks + this.practicalMarks
54+
})
55+
56+
const Course = connector.model('Course', courseSchema)
57+
58+
/// CRUD operations ///
59+
60+
async function create(courseData) {
61+
const course = new Course(courseData)
62+
const createdCourse = await course.save()
63+
return createdCourse
64+
}
65+
66+
async function read(filter, limit = 1) {
67+
const courseData = await Course.find(filter).limit(limit)
68+
return courseData
69+
}
70+
71+
async function update(filter, updateObject) {
72+
const updatedCourse = await Course.findOneAndUpdate(filter, updateObject, {
73+
new: true,
74+
}).exec()
75+
return updatedCourse
76+
}
77+
78+
async function remove(filter) {
79+
const deletedCourse = await Course.findOneAndDelete(filter).exec()
80+
return deletedCourse
81+
}
82+
83+
export default {
84+
create,
85+
read,
86+
update,
87+
remove,
88+
}

models/department.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import connector from '#models/databaseUtil';
2+
3+
const departmentSchema = {
4+
name: { type: Number, required: true },
5+
acronym: { type: String, required: true, immutable: true },
6+
yearOfStarting: { type: Date, immutable: true, required: true },
7+
accreditations: [{
8+
type: connector.Schema.Types.ObjectId,
9+
ref: 'Accreditation',
10+
required: true,
11+
}],
12+
infrastructures: [{
13+
type: connector.Schema.Types.ObjectId,
14+
ref: 'Infrastructure',
15+
required: true,
16+
}],
17+
};
18+
19+
const Department = connector.model('Department', departmentSchema);

0 commit comments

Comments
 (0)