- Description
- Endpoints
- Technologies
- Project Setup
- Running the Project
- Database Configuration
- Using this Template
⚠️ Branch Protection Recommendation- Testing
- Project Structure
- Support
- License
- Code Style
- Codecov
This repository is a template for creating microservices for the Class-Connect application. It uses NestJS, Prisma, and TypeScript with a package-layered architecture. The template is intentionally minimal and ready to be customized for each specific microservice.
-
To test the API, you can use tools like Postman or send curl requests.
-
To create a course using curl:
curl -X POST 'https://<host_url>/courses' \
-H 'Content-Type: application/json' \
-d '{
"title": "Course title",
"description": "Course description",
"teacherId": <teacher_id>,
"startDate": <start_date>,
"endDate": <end_date>,
"registrationDeadline": <registration_deadline>,
"totalPlaces": 100
}'- To get all courses:
curl -X GET 'https://<host_url>/courses'- To get course by id:
curl -X GET 'https://<host_url>/courses/{id}'- To patch title, description, startDate, endDate, registrationDeadline, teacherId and totalPlaces course by id (every property mentioned is optional):
curl -X PATCH 'http://<host_url>/courses/{id}' \
-H 'Content-Type: application/json' \
-d '{
"title"?: "Updated title",
"description"?: "Updated description",
"totalPlaces"?: 200,
"userId": <user_id>,
...
}'- To delete a course by id:
curl -X DELETE 'https://<host_url>/courses/{id}'- To create a course enrollment using curl:
curl -X POST 'https://<host_url>/courses/{course_id}/enrollments' \
-H 'Content-Type: application/json' \
-d '{
"userId": <user_id>,
"role": <role>,
}'- To get all enrollments for a specific course:
curl -X GET 'https://<host_url>/courses/{course_id}/enrollments'- To get enrollments matching a specific filter:
curl -X GET 'https://<host_url>/courses/enrollments<filters>'- To get all enrollments:
curl -X GET 'https://<host_url>/courses/enrollments'- To patch a course enrollment favorite status or role (every property mentioned is optional) using curl:
curl -X PATCH 'https://<host_url>/courses/{course_id}/enrollments/{userId}' \
-H 'Content-Type: application/json' \
-d '{
"favorite": true,
"role": <role>,
}'- To delete a course enrollment by the course id and user id:
curl -X DELETE 'https://<host_url>/courses/{course_id}/enrollments/{user_id}'- To get the course activity (the movements done by the head teacher or assistants):
curl 'https://<host_url>/courses/{course_id}/activities'- To create a course module:
curl 'https://<host_url>/courses/{course_id}/modules' \
-H 'Content-Type: application/json' \
-d '{
"title": "Title",
"description": "Description",
"order": <order>,
"userId": <user_id>
}'- To get a module by id:
curl 'https://<host_url>/courses/{course_id}/modules/{module_id}'- To get all modules for a course:
curl 'https://<host_url>/courses/{course_id}/modules'- To update a course module by id (all properties are optional):
curl -X PATCH 'https://<host_url>/courses/{course_id}/modules/{module_id}' \
-H 'Content-Type: application/json' \
-d '{
"title"?: "Updated Title",
"description"?: "Updated Description",
"order"?: <order>,
"userId": <user_id>
}'- To delete a course module by id:
curl -X DELETE 'https://<host_url>/courses/{course_id}/modules/{module_id}'- To create a resource for a course module:
curl -X POST 'https://<host_url>/courses/{course_id}/modules/{module_id}/resources' \
-H 'Content-Type: application/json' \
-d '{
"link": "https://resource-link.com",
"dataType": <data_type>,
"order": <order>,
"userId": <user_id>
}'- To get a module resource by link:
curl 'https://<host_url>/courses/{course_id}/modules/{module_id}/resources/{link}'- To get all resources for a course module:
curl 'https://<host_url>/courses/{course_id}/modules/{module_id}/resources'- To patch a module resource:
curl 'https://<host_url>/courses/{course_id}/modules/{module_id}/resources/{link}' \
-H 'Content-Type: application/json' \
-d '{
"order": <order>,
"userId": <user_id>"
}'- To delete a module resource:
curl -X GET 'https://<host_url>/courses/{course_id}/modules/{module_id}/resources/{link}?userId={user_id}'- To create course feedback:
curl -X POST 'https://<host_url>/courses/{course_id}/enrollments/{user_id}/courseFeedback' \
-H 'Content-Type: application/json' \
-d '{
"courseNote": 5,
"courseFeedback": "Great course!"
}'- To get course feedback by student and course id:
curl 'https://<host_url>/courses/{course_id}/enrollments/{user_id}/courseFeedback'- To get all feedback for a course:
curl 'https://<host_url>/courses/{course_id}/feedbacks'- To create student feedback:
curl -X POST 'https://<host_url>/courses/{course_id}/enrollments/{user_id}/studentFeedback' \
-H 'Content-Type: application/json' \
-d '{
"studentFeedback": "Excellent participation",
"studentNote": 4,
"teacherId": <teacher_id>
}'- To get student feedback by student and course id:
curl 'https://<host_url>/courses/{course_id}/enrollments/{user_id}/studentFeedback'- To get all feedback for a student:
curl 'https://<host_url>/courses/studentFeedbacks/{student_id}'- To create an assessment for a course:
curl -X POST 'https://<host_url>/courses/{course_id}/assessments' \
-H 'Content-Type: application/json' \
-d '{
"title": "Assessment Title",
"description": "Assessment Description",
"type": <assessment_type>,
"startTime": <start_time>,
"deadline": <deadline>,
"toleranceTime": 60,
"userId": <user_id>
"exercises": [
{
"type": "Written",
"question": "What is an API?",
"link"?: "https://example-link.com"
},
{
"type": "Mc",
"question": "Is this an example?",
"choices": ["Yes", "No"],
"correctChoiceIdx": 0,
"link"?: "https://example-link.com"
},
...
]
}'- To get all assessments for a course:
curl 'https://<host_url>/courses/{course_id}/assessments'- To get assessments matching a filter:
curl 'https://<host_url>/assessments/{filter}'- To get an assessment by id:
curl 'https://<host_url>/assessments/{asses_id}'- To update an assessment by id:
curl -X PATCH 'https://<host_url>/courses/{course_id}/assessments/{asses_id}' \
-H 'Content-Type: application/json' \
-d '{
"title"?: "Updated Exam Title",
"description"?: "Updated description",
"userId": "<user_id>",
...
}'- To delete an assessment by ID:
curl -X DELETE 'https://<host_url>/courses/{course_id}/assessments/{asses_id}'- To create a submission for an assessment:
curl -X POST 'https://<host_url>/assessments/{assessment_id}/submissions' \
-H 'Content-Type: application/json' \
-d '{
"userId": <user_id>,
"answers": ["1", "I don’t know", ...]
}'- To get all submissions for an assessment:
curl 'https://<host_url>/assessments/{assessment_id}/submissions'- To get a submission by assessment and user id:
curl 'https://<host_url>/assessments/{assessment_id}/submissions/{user_id}'- to create/update a correction for a specified submission
curl -X POST 'https://<host_url>/assessments/{assessment_id}/submissions/{user_id}/correction' \
-H 'Content-Type: application/json' \
-d '{
"teacherId": <teacher_id>,
"corrections": ["Very Good!", "This exercise was difficult, but you did it well ;)"]},
"feedback": "The exam is well done, congrats",
"note": 7
}'<start_date>, <end_date>, <registration_date>, <start_time> and <deadline> are strings of the dates in ISO 8601 format: YYYY-mm-ddThh:mm:ssZ.
<teacher_id> and <user_id> must match with the uuid used in users service.
<user_id> is required when requesting any endpoint allowed just to authorized users, or when needed to identify any entity (e.x. enrollments).
<role> must be "STUDENT" or "ASSISTANT".
<filters> are query params which can include an enrollment userId and/or role.
<order> is the integer indicating the order of the module/resource in the course/module modules/resources list.
<data_type> must be "IMAGE", "VIDEO", "LINK".
- NestJS: A progressive Node.js framework for building efficient and scalable server-side applications.
- Prisma: A next-generation ORM for database management.
- TypeScript: A strongly typed programming language that builds on JavaScript.
- Package-Layered Architecture: A modular architecture pattern for better scalability and maintainability.
Ensure you have the following installed:
- Node.js (v16 or higher)
- npm (v8 or higher)
- PostgreSQL (default database, can be switched to MongoDB if needed)
Clone the repository and install dependencies:
$ git clone <repository-url>
$ cd classconnect-base-service
$ npm install$ npm run start$ npm run start:dev$ npm run start:prodBy default, this template is configured to use PostgreSQL. You can modify the database configuration in the prisma/schema.prisma file to switch to MongoDB or another database if required.
To migrate the database schema:
$ npx prisma migrate devTo generate Prisma client:
$ npx prisma generateYou can create a new repository from this template by clicking the "Use this template" button on GitHub. After cloning, make sure to:
- Run
npm installto install dependencies. - Update the
.env.examplefile and create your own.env. - Initialize your own Prisma schema.
- Configure GitHub Actions if needed.
After creating a new repository from this template, we recommend you:
- Go to
Settings > Branchesin your GitHub repository. - Add a protection rule for the
mainbranch:- ✅ Require status checks to pass before merging.
- ✅ Require branches to be up to date.
- ❌ Review requirement is optional.
- ✅ Block direct pushes (recommended).
This project uses Jest for unit testing. To run tests:
$ npm run testTo run tests with coverage:
$ npm run test:covTests will automatically run on every push or pull request to main via GitHub Actions.
src/
├── controllers/
├── services/
├── modules/
├── entities/
├── repositories/
├── main.ts
├── app.module.ts
prisma/
├── schema.prisma
.github/
└── workflows/
└── ci.yml
This template is open source and licensed under the MIT license. Contributions and feedback are welcome.
This project is MIT licensed.
We use Prettier and ESLint to maintain consistent code formatting and quality. Use the following commands:
- To check and fix lint issues:
$ npm run lint- To format files using Prettier:
$ npm run format- To check formatting without making changes:
$ npm run format:check