Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions BackEnd/Modulo 1/Case4_Doghero/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# CASE DOGHERO


Este é um projeto de Backend, utilizando Typescript, MySQL, além das bibliotecas knexJs e expressJs, desenvolvido para atender aos modelos das APIs.


## DESCRIÇÃO DO PROJETO

O projeto consiste em simular uma plataforma de Passeio de Dogs, onde o usuário (Tutor) poderá criar e acessar informações dos passeios contratado, nas formas de tempo, quantidade de Dogs, hora inicial e final. Sendo criado endpoints GET e POST para simular as demandas.


## RECURSOS UTILIZADOS

* Nodejs;
* MySQL;
* express;
* typescript;
* uuid;
* knex;
* bcryptjs;
* moment


## LINK DA DOCUMENTAÇÃO NO POSTMAN:
https://documenter.getpostman.com/view/19296981/Uz5NiCp8#2120e0cf-beab-4d9c-ac7c-43ad58005bab


## PARA RODAR A APLICAÇÃO

* npm install
* npm run dev

## DESENVOLVEDOR

Anderson Felix
* Linkedin - https://www.linkedin.com/in/anderson-fl/


1 change: 1 addition & 0 deletions BackEnd/Modulo 1/Case4_Doghero/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"typescript": "^4.7.3"
},
"dependencies": {
"bcrypt": "^5.0.1",
"bcryptjs": "^2.4.3",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
Expand Down
19 changes: 1 addition & 18 deletions BackEnd/Modulo 1/Case4_Doghero/src/business/DogHeroBusiness.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Time, EditWalkDTO, Status } from './../model/DogHeroWalking';
import { WalkInputDTO } from "../model/DogHeroWalking";
import { InputError } from "../error/BaseError";
import moment from "moment";
Expand Down Expand Up @@ -79,21 +78,5 @@ export class DogHeroBusiness {

return result
}

async editStartOrFinishBusiness(input: EditWalkDTO){

const wbd = new DogHeroDatabase();
const result = await wbd.editStartOrFinishData(input);

return result
}


async editStatusBusiness(input: EditWalkDTO){

const wbd = new DogHeroDatabase();
const result = await wbd.editStatusData(input);

return result
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export class UserTutorBusiness {
async createTutor(tutor: TutorInputDTO) {


if (!tutor.email || !tutor.password || !tutor.name) {
if (!tutor.name || !tutor.email || !tutor.password) {
throw new Error("Todos os campos devem ser preenchidos");
}


if (tutor.password.length < 6 || tutor.name.length < 15) {
throw new Error("O password deve ter no mínimo 6 caracteres e o nome deve ter no maximo 15 caracteres");
if (tutor.password.length < 6 || tutor.name.length < 5) {
throw new Error("O password deve ter ate 6 caracteres e o nome deve ser menor que 5 caracteres");
}

const idGenerator = new IdGenerator();
Expand Down
53 changes: 4 additions & 49 deletions BackEnd/Modulo 1/Case4_Doghero/src/controller/DogHeroController.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Status, Walk, EditWalkDTO } from './../model/DogHeroWalking';
import { Walk} from './../model/DogHeroWalking';
import { Request, Response } from "express";
import { DogHeroBusiness } from "../business/DogHeroBusiness";
import { BaseDatabase } from "../data/BaseDatabase";
import { Time, WalkInputDTO } from "../model/DogHeroWalking";
import { WalkInputDTO } from "../model/DogHeroWalking";

export class DogHeroController {
async walkCreate(req: Request, res: Response) {
Expand All @@ -22,7 +22,7 @@ export class DogHeroController {
const dogHeroBusiness = new DogHeroBusiness();
await dogHeroBusiness.createWalk(input);

res.status(200).send("Walk criado com sucesso.");
res.status(200).send("Walkink criado com sucesso.");

} catch (error:any) {
res.status(400).send({ error: error.message });
Expand Down Expand Up @@ -86,51 +86,6 @@ export class DogHeroController {
})
}
}

async editStartWalkOrFinishWalk(req: Request, res: Response) {
try {

const input: EditWalkDTO ={
id: req.params.id,
startWalk: req.body.startWalk,
finishWalk: req.body.finishWalk
};


const dogHeroBusiness = new DogHeroBusiness();
await dogHeroBusiness.editStartOrFinishBusiness(input);


res.status(200).send("Alterado com sucesso")

} catch (error:any) {
res.status(400).send({ error: error.message });
}

await BaseDatabase.destroyConnection();
}

async editStatus(req: Request, res: Response) {
try {

const status = Walk.toStatusEnum(req.body.status as string)

const input: EditWalkDTO ={
id: req.params.id,
status
};

const dogHeroBusiness = new DogHeroBusiness();
await dogHeroBusiness.editStatusBusiness(input);


res.status(200).send("Status alterado com sucesso")

} catch (error:any) {
res.status(400).send({ error: error.message });
}

await BaseDatabase.destroyConnection();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export class UserTutorController {
try {

const input: TutorInputDTO = {
email: req.body.email,
name: req.body.name,
email: req.body.email,
password: req.body.password
}

Expand Down
40 changes: 7 additions & 33 deletions BackEnd/Modulo 1/Case4_Doghero/src/data/DogHeroDatabase.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { UserTutor } from '../model/UserTutor';
import { WalkCalc, WalkOutputDTO, Status, EditWalkDTO } from '../model/DogHeroWalking';
import { WalkCalc, WalkOutputDTO, } from '../model/DogHeroWalking';
import moment from "moment";
import { NotFoundError } from "../error/BaseError";
import { Time} from "../model/DogHeroWalking";
Expand Down Expand Up @@ -113,12 +112,14 @@ export class DogHeroDatabase extends BaseDatabase{
): Promise<WalkOutputDTO[]> {

const walk = await this.getConnection().raw(`
SELECT w.id as id,
SELECT
w.id as id,
t.id as tutorId,
w.date_walk as dateWalk,
w.start_walk as startWalk,
w.finish_walk as finishWalk,
w.quantity_dogs as quantityDogs,
w.price as price,
t.name as name
FROM ${this.TABLE_NAME.WALLKING} w
LEFT JOIN ${this.TABLE_NAME.TUTOR} t ON t.id = w.id_user_tutor
Expand All @@ -136,38 +137,11 @@ export class DogHeroDatabase extends BaseDatabase{
name: data.name,
dateWalk: data.dateWalk,
startWalk: data.startWalk,
quantityDogs: data.quantityDogs
quantityDogs: data.quantityDogs,
finishWalk: data.finishWalk,
price: data.price
}))

}

async editStartOrFinishData(walk: EditWalkDTO): Promise<void>{

try {
await this.getConnection().where("id",walk.id)
.update({
start_walk: walk.startWalk,
finish_walk: walk.finishWalk

}).into(this.TABLE_NAME.WALLKING)

} catch (error:any) {
throw new Error(error.sqlMessage || error.message);
}
}

async editStatusData(input: EditWalkDTO): Promise<void>{

try {
await this.getConnection().where("id",input.id)
.update({
status: input.status

}).into(this.TABLE_NAME.WALLKING)

} catch (error:any) {
throw new Error(error.sqlMessage || error.message);
}
}

}
4 changes: 1 addition & 3 deletions BackEnd/Modulo 1/Case4_Doghero/src/data/UserTutorDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class UserTutorDatabase extends BaseDatabase {
public async getTutorData(offset: number): Promise<TutorOutputDTO[]> {
try {
const result = await this.getConnection()
.select("id", "name", "phone", "email")
.select("id", "name", "email")
.into(this.TABLE_NAME.TUTOR)
.orderBy("name", 'asc')
.limit(5)
Expand All @@ -40,7 +40,5 @@ export class UserTutorDatabase extends BaseDatabase {
}
}



}

6 changes: 0 additions & 6 deletions BackEnd/Modulo 1/Case4_Doghero/src/model/DogHeroWalking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,3 @@ export interface WalkCalc{
}


export interface EditWalkDTO{
id: string,
startWalk?: Time,
finishWalk?: Time,
status?: string
}
9 changes: 8 additions & 1 deletion BackEnd/Modulo 1/Case4_Doghero/src/routes/DogHeroRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ export const dogHeroRouter = express.Router();

const dogHeroController = new DogHeroController();

dogHeroRouter.post("/signup", dogHeroController.walkCreate);
dogHeroRouter.post("/signup", dogHeroController.walkCreate);

dogHeroRouter.get("/WalkDateTodayOrAll", dogHeroController.index);

dogHeroRouter.get("/showWalk/:id", dogHeroController.showWalkId);

dogHeroRouter.get("/walkTutor/:id", dogHeroController.getWalkTutor);

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as bcrypt from 'bcryptjs';
export class HashGenerator {
public async hash(text: string): Promise<string> {

const rounds = 20
const rounds = 12
const salt = await bcrypt.genSalt(rounds);
const result = await bcrypt.hash(text, salt);

Expand Down