Skip to content

Commit

Permalink
Teste deploy na vercel - 8 - Back-end.
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielSS187 committed Feb 15, 2023
1 parent 883f7e2 commit 6a02188
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 33 deletions.
2 changes: 1 addition & 1 deletion back-end/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ typings/

# Nuxt.js build / generate output
.nuxt
dist
# dist

# Gatsby files
.cache/
Expand Down
4 changes: 1 addition & 3 deletions back-end/.vercelignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ bin
package-lock.json
yarn.lock
yarn-error.log
.env
.env**
**.env
.env
8 changes: 1 addition & 7 deletions back-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"tsup": {
"entry": ["src/index.ts", "src/errors"],
"splitting": false,
"sourcemap": true,
"clean": true
},
"scripts": {
"start": "tsup && node dist/index.js",
"start": "npx tsup src && node dist/index.js",
"dev": "tsx watch src/index.ts",
"build": "tsup",
"test": "echo \"Error: no test specified\" && exit 1",
Expand Down
4 changes: 2 additions & 2 deletions back-end/src/Errors/TodoErrors.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CustomError } from "./CustomError";

export class ErrorTodo extends CustomError {
export class TodoErrors extends CustomError {
constructor(
public error: Record<string, string> | any,
public error: Record<string, string>,
public statusCode: number
){
super(error, statusCode);
Expand Down
4 changes: 2 additions & 2 deletions back-end/src/Errors/userErrors.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CustomError } from "./CustomError";

export class ErrorUser extends CustomError {
export class UserErrors extends CustomError {
constructor(
public error: Record<string, string> | any,
public error: Record<string, string>,
public statusCode: number
){
super(error, statusCode);
Expand Down
2 changes: 1 addition & 1 deletion back-end/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Request, Response, NextFunction } from "express";
import { app } from "./server";
import "express-async-errors";

import { CustomError } from "./errors/CustomError";
import { userRoutes } from "./routes/userRoutes";
import { todoRoutes } from "./routes/todoRoutes";
import { authMiddleware } from "./middlewares/authMiddleware";
import { CustomError } from "./errors/CustomError";

app.use("/user", userRoutes);
app.use("/todo", authMiddleware, todoRoutes);
Expand Down
16 changes: 8 additions & 8 deletions back-end/src/useCases/todoCases/TodoCases.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { z } from "zod";

import { ITodoRepository } from "../../models/todoModel/interfaces";
import { TodoErrors } from "../../errors/TodoErrors";
import {
TCreateRequest,
createRequestSchema,
TUpdateStatusRequest,
TDeleteRequest,
TGetAllTodos
} from "./validations";
import { ErrorTodo } from "../../errors/TodoErrors";

export class TodoCases {
constructor(
Expand All @@ -30,7 +30,7 @@ export class TodoCases {
validationErrors[error.path[0]] = error.message
});

throw new ErrorTodo(validationErrors, 400);
throw new TodoErrors(validationErrors, 400);
};

const { todo } = await validationRequest;
Expand All @@ -47,7 +47,7 @@ export class TodoCases {
const { idUser, idTodo, selectTypeDeleteAll } = request;

if ( !idTodo && !selectTypeDeleteAll ) {
throw new ErrorTodo(
throw new TodoErrors(
{ error: "choose one of these options query: idTodo or selectType" },
406
);
Expand All @@ -56,7 +56,7 @@ export class TodoCases {
if ( idTodo ) {
const todo = await this.todoRepository.findTodo(idTodo);
if ( !todo || todo.id_user !== idUser ) {
throw new ErrorTodo({error: "Todo not found."}, 404);
throw new TodoErrors({error: "Todo not found."}, 404);
};
};

Expand All @@ -65,7 +65,7 @@ export class TodoCases {
selectTypeDeleteAll !== "deleteAllComplete"
&& selectTypeDeleteAll !== "deleteAllIncomplete"
if ( verifyTypeSelectDeleteAll ) {
throw new ErrorTodo(
throw new TodoErrors(
{error: "To delete all todos choose one of the types: deleteAllComplete or deleteAllIncomplete"},
406
);
Expand All @@ -87,11 +87,11 @@ export class TodoCases {
.findTodo(idTodo);

if (!todo || todo.id_user !== idUser) {
throw new ErrorTodo({error: "Todo not found."}, 404);
throw new TodoErrors({error: "Todo not found."}, 404);
};

if (String(status) !== "true" && String(status) !== "false") {
throw new ErrorTodo({error: "Status is only allowed: true or false."}, 406);
throw new TodoErrors({error: "Status is only allowed: true or false."}, 406);
};

const transformBoolean =
Expand All @@ -109,7 +109,7 @@ export class TodoCases {
const { idUser, typeList } = request;

if ( typeList !== "complete" && typeList !== "incomplete" ){
throw new ErrorTodo(
throw new TodoErrors(
{error: "Type of valid lists: complete or incomplete."},
406
);
Expand Down
17 changes: 8 additions & 9 deletions back-end/src/useCases/userCases/UserCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import { IUserRepository } from "../../models/userModel/interfaces";
import { IBCryptAdapter } from "../../adapters/IBcryptAdapter";
import { IJwtAdapter } from "../../adapters/IJwtAdapter";

import { UserErrors } from "../../errors/UserErrors";
import {
TRegisterRequest,
registerRequestSchema,
TSignInRequest,
signInRequestSchema
} from "./validations";

import { ErrorUser } from "../../errors/UserErrors";

export class UserCases {
constructor(
private userRepository: IUserRepository,
Expand All @@ -35,15 +34,15 @@ export class UserCases {
validationErrors[error.path[0]] = error.message
});

throw new ErrorUser(validationErrors, 400);
throw new UserErrors(validationErrors, 400);
};

const {userName, password} = await validationRequest;

const user = await this.userRepository.findUser({userName});

if(user) {
throw new ErrorUser({error: "A user with that name already exists."}, 409);
throw new UserErrors({error: "A user with that name already exists."}, 409);
};

const passwordHash = await this.bcryptAdapter.hashEncrypt({password});
Expand Down Expand Up @@ -74,15 +73,15 @@ export class UserCases {
validationErrors[error.path[0]] = error.message
});

throw new ErrorUser(validationErrors, 400);
throw new UserErrors(validationErrors, 400);
};

const {userName, password} = await validationRequest;

const user = await this.userRepository.findUser({userName});

if (!user) {
throw new ErrorUser({error: "Username does not exist."}, 404);
throw new UserErrors({error: "Username does not exist."}, 404);
};

const decryptPassword = await this.bcryptAdapter.compareHash({
Expand All @@ -91,7 +90,7 @@ export class UserCases {
});

if ( !decryptPassword ) {
throw new ErrorUser({error: "Invalid password."}, 406);
throw new UserErrors({error: "Invalid password."}, 406);
};

const generateToken = this.jwtAdapter.generateToken({
Expand All @@ -106,7 +105,7 @@ export class UserCases {

async getUserByToken (token: string) {
if ( !token ) {
throw new ErrorUser({error: "The token is required."}, 406);
throw new UserErrors({error: "The token is required."}, 406);
};

const decryptJwt = this.jwtAdapter.getTokenData({
Expand All @@ -118,7 +117,7 @@ export class UserCases {
});

if (!user) {
throw new ErrorUser({error: "Invalid token."}, 401);
throw new UserErrors({error: "Invalid token."}, 401);
};

return user;
Expand Down

2 comments on commit 6a02188

@vercel
Copy link

@vercel vercel bot commented on 6a02188 Feb 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

modern-to-do-list – ./front-end

modern-to-do-list.vercel.app
modern-to-do-list-git-main-gabrielss187.vercel.app
modern-to-do-list-gabrielss187.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 6a02188 Feb 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.