-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f978621
commit 665ef54
Showing
11 changed files
with
294 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,19 +6,22 @@ | |
"author": "alfredo chivela <[email protected]>", | ||
"license": "MIT", | ||
"scripts": { | ||
"dev": "ts-node-dev --inspect --transpile-only --ignore-watch node_modules --respawn ./src/server.ts", | ||
"dev": "ts-node-dev -r tsconfig-paths/register --inspect --transpile-only --ignore-watch node_modules --respawn ./src/server.ts", | ||
"migration:run": "typeorm migration:run -- -d ./src/database", | ||
"typeorm": "ts-node-dev ./node_modules/typeorm/cli.js" | ||
}, | ||
"dependencies": { | ||
"@types/bcryptjs": "^2.4.6", | ||
"@types/swagger-ui-express": "^4.1.7", | ||
"bcrypt": "^5.1.1", | ||
"bcryptjs": "^2.4.3", | ||
"express": "^4.21.1", | ||
"express-async-errors": "^3.1.1", | ||
"jsonwebtoken": "^9.0.2", | ||
"multer": "^1.4.5-lts.1", | ||
"pg": "^8.13.1", | ||
"reflect-metadata": "^0.2.2", | ||
"swagger-ui-express": "^5.0.1", | ||
"typeorm": "^0.3.20" | ||
}, | ||
"devDependencies": { | ||
|
@@ -33,6 +36,7 @@ | |
"eslint-plugin-import": "^2.31.0", | ||
"globals": "^15.12.0", | ||
"ts-node-dev": "^2.0.0", | ||
"tsconfig-paths": "^4.2.0", | ||
"typescript": "^5.7.2", | ||
"typescript-eslint": "^8.16.0" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,32 @@ | ||
import { AppError } from "../errors/AppError"; | ||
import { TaskRepository } from "../repositories/TaskRepository"; | ||
import {Request, Response} from 'express'; | ||
import { Request, Response } from "express"; | ||
|
||
export class TasksController { | ||
static async getAll(req: Request, res: Response): Promise<Response> { | ||
try { | ||
const tasks = await TaskRepository.find(); | ||
const tasks = await TaskRepository.find(); | ||
if (tasks) { | ||
return res.status(200).json(tasks); | ||
} catch (error) { | ||
return res.status(500).json({ message: "Error fetching tasks", error }); | ||
} | ||
throw new AppError("Error fetching tasks", 401); | ||
} | ||
static async create(req: Request, res: Response): Promise<Response> { | ||
const { title, description, milistone_id, status } = req.body; | ||
|
||
if (!title || !description || !milistone_id || !status) { | ||
return res.status(400).json({ message: "Missing required fields" }); | ||
} | ||
|
||
try { | ||
const task = TaskRepository.create({ | ||
title, | ||
description, | ||
status, | ||
milistone_id | ||
}); | ||
const taskSave = await TaskRepository.save(task); | ||
return res.status(200).json(taskSave); | ||
} catch (error) { | ||
return res.status(500).json({ message: "Error saving tasks", error }); | ||
if (!title || !description || !milistone_id || !status) { | ||
return res.status(400).json({ message: "Missing required fields" }); | ||
} | ||
|
||
const task = TaskRepository.create({ | ||
title, | ||
description, | ||
status, | ||
milistone_id, | ||
}); | ||
const taskSave = await TaskRepository.save(task); | ||
if (!taskSave) throw new AppError("Error saving tasks", 401); | ||
|
||
return res.status(200).json(taskSave); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { Router } from "express"; | ||
import { TasksController } from "../controllers/TasksController"; | ||
import ensureAutheticated from "../middlewares/ensureAuthenticaded"; | ||
|
||
const tasksRouter = Router(); | ||
|
||
tasksRouter.use(ensureAutheticated); | ||
tasksRouter.get("/", TasksController.getAll); | ||
tasksRouter.post("/", TasksController.create); | ||
export { tasksRouter }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
{ | ||
"openapi": "3.0.0", | ||
"info": { | ||
"title": "API Documentation", | ||
"description": "Documentation for the API endpoints.", | ||
"version": "1.0.0" | ||
}, | ||
"paths": { | ||
"/milistones": { | ||
"get": { | ||
"summary": "Get all milestones", | ||
"operationId": "getAllMilestones", | ||
"tags": ["Milestones"], | ||
"responses": { | ||
"200": { | ||
"description": "A list of milestones", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"type": "array", | ||
"items": { | ||
"type": "object" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"401": { | ||
"description": "Error fetching milestones" | ||
} | ||
} | ||
}, | ||
"post": { | ||
"summary": "Create a milestone", | ||
"operationId": "createMilestone", | ||
"tags": ["Milestones"], | ||
"requestBody": { | ||
"required": true, | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"type": "object", | ||
"properties": { | ||
"title": { "type": "string" }, | ||
"date": { "type": "string", "format": "date-time" }, | ||
"user_id": { "type": "string" } | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"responses": { | ||
"201": { | ||
"description": "Milestone created successfully" | ||
}, | ||
"400": { | ||
"description": "Missing required fields" | ||
}, | ||
"401": { | ||
"description": "Error saving milestone" | ||
} | ||
} | ||
} | ||
}, | ||
"/sessions": { | ||
"post": { | ||
"summary": "Authenticate user", | ||
"operationId": "authenticateUser", | ||
"tags": ["Sessions"], | ||
"requestBody": { | ||
"required": true, | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"type": "object", | ||
"properties": { | ||
"email": { "type": "string" }, | ||
"password": { "type": "string" } | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"responses": { | ||
"200": { | ||
"description": "Authentication successful", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"type": "object", | ||
"properties": { | ||
"user": { "type": "object" }, | ||
"token": { "type": "string" } | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"400": { "description": "Missing required fields" }, | ||
"401": { "description": "Incorrect email or password" } | ||
} | ||
} | ||
}, | ||
"/tasks": { | ||
"get": { | ||
"summary": "Get all tasks", | ||
"operationId": "getAllTasks", | ||
"tags": ["Tasks"], | ||
"responses": { | ||
"200": { "description": "A list of tasks" }, | ||
"401": { "description": "Error fetching tasks" } | ||
} | ||
}, | ||
"post": { | ||
"summary": "Create a task", | ||
"operationId": "createTask", | ||
"tags": ["Tasks"], | ||
"requestBody": { | ||
"required": true, | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"type": "object", | ||
"properties": { | ||
"title": { "type": "string" }, | ||
"description": { "type": "string" }, | ||
"milistone_id": { "type": "string" }, | ||
"status": { "type": "string" } | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"responses": { | ||
"201": { "description": "Task created successfully" }, | ||
"400": { "description": "Missing required fields" }, | ||
"401": { "description": "Error saving task" } | ||
} | ||
} | ||
}, | ||
"/users": { | ||
"post": { | ||
"summary": "Create a user", | ||
"operationId": "createUser", | ||
"tags": ["Users"], | ||
"requestBody": { | ||
"required": true, | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"type": "object", | ||
"properties": { | ||
"name": { "type": "string" }, | ||
"email": { "type": "string" }, | ||
"password": { "type": "string" } | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"responses": { | ||
"201": { "description": "User created successfully" }, | ||
"400": { "description": "Missing required fields" }, | ||
"500": { "description": "Error saving user" } | ||
} | ||
} | ||
}, | ||
"/users/upload-avatar": { | ||
"post": { | ||
"summary": "Upload user avatar", | ||
"operationId": "uploadAvatar", | ||
"tags": ["Users"], | ||
"responses": { | ||
"201": { "description": "Avatar uploaded successfully" }, | ||
"401": { | ||
"description": "Only authenticated users can change avatar" | ||
}, | ||
"500": { "description": "Error uploading avatar" } | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.