Skip to content

Commit

Permalink
refactor(problem-generators): Migrate problem generator to separate N…
Browse files Browse the repository at this point in the history
…PM package

- Migrated the problem generator code to a new NPM package named `mpclab`.
- Updated import statements from `require("/problem-generators")` to `require("mpclab")`.
- Adjusted corresponding tests to ensure compatibility with the new package.
- Revised documentation to reflect the new import paths and usage instructions.

Related to issue #4
  • Loading branch information
TKanX committed Oct 14, 2024
1 parent b843de8 commit 2510936
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 1,372 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ The server uses Jest for testing. To run the tests, use the following command.
npm test
```

## Acknowledgements

We would like to thank the following libraries and tools for making this project possible:

- [Express.js](https://expressjs.com/): A fast, unopinionated, minimalist web framework for Node.js.
- [MongoDB](https://www.mongodb.com/): A NoSQL database program that uses JSON-like documents with optional schemas.
- [Jest](https://jestjs.io/): A delightful JavaScript testing framework with a focus on simplicity.
- [Nodemailer](https://nodemailer.com/): A module for Node.js to send emails easily.
- [JWT](https://jwt.io/): A compact, URL-safe means of representing claims to be transferred between two parties.
- [bcrypt](https://www.npmjs.com/package/bcrypt): A library to help you hash passwords.
- [mpclab](https://www.npmjs.com/package/mpclab): A problem generator for mathematics, physics, and chemistry.

## License

This project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details.
4 changes: 3 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2856,7 +2856,9 @@ The API uses JWT (JSON Web Token) for authentication. To access protected routes

- **Query Parameters**:

- `options`: The problem generation options.
- `options`: The problem generation options. (Optional, object (Use JSON string))

> **Note:** The problem generation options are passed as a query parameter. Please use `JSON.stringify` to pass the object.

- **Response**:

Expand Down
17 changes: 13 additions & 4 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"jsonwebtoken": "^9.0.2",
"mathjs": "^13.1.1",
"mongoose": "^8.6.2",
"mpclab": "^0.1.0",
"nodemailer": "^6.9.15"
},
"devDependencies": {
Expand All @@ -15,6 +16,6 @@
},
"scripts": {
"start": "node server.js",
"test": "jest --verbose --silent --coverage --forceExit --config=tests/jest.config.js"
"test": "jest --verbose --silent --coverage --ci --forceExit --config=tests/jest.config.js"
}
}
16 changes: 9 additions & 7 deletions src/controllers/problemController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* @description Controller for problem generation.
*/

const index = require("../problem-generators/index.json");
const ProblemGenerator = require("../problem-generators");
const ProblemGenerator = require("mpclab");
const problemGenerator = new ProblemGenerator();

/**
Expand All @@ -13,7 +12,10 @@ const problemGenerator = new ProblemGenerator();
* @param {Response} res - The response object.
*/
getIndex = (req, res) => {
res.success(index, "Problem generator index retrieved successfully.");
res.success(
problemGenerator.index,
"Problem generator index retrieved successfully."
);
};

/**
Expand All @@ -22,12 +24,12 @@ getIndex = (req, res) => {
* @param {Response} res - The response object.
*/
generateProblem = (req, res) => {
const topicsString = req.params[0];
const { options } = req.query;
try {
const topicsString = req.params[0];
const options = JSON.parse(req.query.options || "{}");

const topics = topicsString.split("/");
const topics = topicsString.split("/");

try {
const problem = problemGenerator.generateOne({
path: topics,
options: options,
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/taskController.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
const taskService = require("../services/taskService");
const classService = require("../services/classService");

const ProblemGenerator = require("../problem-generators");
const ProblemGenerator = require("mpclab");
const problemGenerator = new ProblemGenerator();

const validationUtils = require("../utils/validationUtils");
Expand Down
170 changes: 0 additions & 170 deletions src/problem-generators/index.js

This file was deleted.

Loading

0 comments on commit 2510936

Please sign in to comment.