https://github.com/ayoubachak/cron-simulator
https://github.com/ayoubachak/cron-simulator
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ayoubachak/cron-simulator
- Owner: ayoubachak
- Created: 2024-06-19T23:50:44.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-06-20T01:19:09.000Z (over 1 year ago)
- Last Synced: 2024-06-21T15:03:18.984Z (over 1 year ago)
- Language: TypeScript
- Size: 117 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Cron Simulator
This project simulates a CRON service using NestJS and PostgreSQL. The service allows you to create tasks, list all tasks, manually execute tasks, and automatically execute tasks based on their schedule. It also includes user authentication using JWT.
## Technologies Used
- NestJS
- PostgreSQL
- TypeORM
- @nestjs/schedule
- @nestjs/passport
- passport-local
- JWT## Prerequisites
- Node.js
- npm
- PostgreSQL## Getting Started
### Installation
1. **Clone the repository**:
```bash
git clone
cd cron-simulator
```2. **Install dependencies**:
```bash
npm install
```3. **Set up PostgreSQL**:
- Make sure PostgreSQL is installed and running.
- Create a database named `cron_simulator`:
```bash
psql -U postgres -c "CREATE DATABASE cron_simulator;"
```4. **Create `.env` File**:
Create a file named `.env` in the root directory of your project and add the following content:
```
JWT_SECRET=your_secret_key
```5. **Configure the database connection**:
Open `src/app.module.ts` and update the database connection settings:
```typescript
TypeOrmModule.forRoot({
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'your_username', // Replace with your PostgreSQL username
password: 'your_password', // Replace with your PostgreSQL password
database: 'cron_simulator',
autoLoadEntities: true,
synchronize: true,
})
```### Running the Application
1. **Start the NestJS application**:
```bash
npm run start
```The application will start on `http://localhost:3000`.
### API Endpoints
#### Authentication
1. **Login to Get JWT Token**:
```bash
curl -X POST http://localhost:3000/auth/login -H "Content-Type: application/json" -d '{"username": "test", "password": "test"}'
```The response will contain the JWT token:
```json
{
"access_token": "your_jwt_token"
}
```#### Tasks
2. **Create a Task**:
```bash
curl -X POST http://localhost:3000/tasks -H "Authorization: Bearer your_jwt_token" -H "Content-Type: application/json" -d '{"title": "Task 1", "daysOfWeek": [0, 1], "time": "08:00:00", "timezone": "Europe/Paris"}'
```3. **List All Tasks**:
```bash
curl http://localhost:3000/tasks -H "Authorization: Bearer your_jwt_token"
```4. **Execute a Task Manually**:
```bash
curl -X POST http://localhost:3000/tasks/1/execute -H "Authorization: Bearer your_jwt_token"
```### Example Task JSON
```json
{
"taskId": 1,
"title": "Task 1",
"daysOfWeek": [0, 1],
"time": "08:00:00",
"timezone": "Europe/Paris"
}