Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teste para a vaga de Desenvolvedor Full Stack Júnior 1 #54

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
57 changes: 57 additions & 0 deletions api/controllers/pets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { db } from "../db.js";

export const getPets = (_, res) => {
const q = "SELECT * FROM pets";

db.query(q, (err, data) => {
if (err) return res.json(err);

return res.status(200).json(data);
});
};

export const addPets = (req, res) => {
const q = "INSERT INTO pets(`nomePet`, `tipo`, `raca`, `idade`, `cpfTutor`) VALUES(?)";

const values = [
req.body.nomePet,
req.body.tipo,
req.body.raca,
req.body.idade,
req.body.cpfTutor,
];

db.query(q, [values], (err) => {
if (err) return res.json(err);

return res.status(200).json("Pet criado com sucesso.");
});
};

export const updatePets = (req, res) => {
const q = "UPDATE pets SET `nomePet` = ?, `tipo` = ?, `raca` = ?, `idade` = ?, `cpfTutor` = ? WHERE `id` = ?";

const values = [
req.body.nomePet,
req.body.tipo,
req.body.raca,
req.body.idade,
req.body.cpfTutor,
];

db.query(q, [...values, req.params.id], (err) => {
if (err) return res.json(err);

return res.status(200).json("Pet atualizado com sucesso.");
});
};

export const deletePets = (req, res) => {
const q = "DELETE FROM pets WHERE `id` = ?";

db.query(q, [req.params.id], (err) => {
if (err) return res.json(err);

return res.status(200).json("Pet deletado com sucesso.");
});
};
56 changes: 56 additions & 0 deletions api/controllers/tutores.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { db } from "../db.js";

export const getTutores = (_, res) => {
const q = "SELECT * FROM tutores"

db.query(q, (err, data) => {
if (err) return res.json(err);

return res.status(200).json(data);
});
};

export const addTutores = (req, res) => {
const q = "INSERT INTO tutores(`nomeTutor`, `contato`, `endereco`, `cpf`) VALUES(?)";

const values = [
req.body.nomeTutor,
req.body.contato,
req.body.endereco,
req.body.cpf,
];

db.query(q, [values], (err) => {
if (err) return res.json(err);

return res.status(200).json("Tutor criado com sucesso.");
});
};

export const updateTutores = (req, res) => {
const q = "UPDATE tutores SET `nomeTutor` = ?, `contato` = ?, `endereco` = ?, `cpf` = ? WHERE `id` = ?";

const values = [
req.body.nomeTutor,
req.body.contato,
req.body.endereco,
req.body.cpf,
];

db.query(q, [...values, req.params.id], (err) => {
if (err) return res.json(err);

return res.status(200).json("Tutor atualizado com sucesso.");
});
};

export const deleteTutores = (req, res) => {
const q = "DELETE FROM tutores WHERE `id` = ?";

db.query(q, [req.params.id], (err) => {
if (err) return res.json(err);

return res.status(200).json("Tutor deletado com sucesso.");
});
};

8 changes: 8 additions & 0 deletions api/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import mysql from "mysql"

export const db = mysql.createConnection({
host: "localhost",
user: "root",
password: "password123",
database: "crud"
});
12 changes: 12 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import express from "express";
import userRoutes from "./routes/users.js";
import cors from "cors";

const app = express();

app.use(express.json());
app.use(cors());

app.use("/", userRoutes);

app.listen(8800);
12 changes: 12 additions & 0 deletions api/node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions api/node_modules/.bin/mime.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions api/node_modules/.bin/mime.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions api/node_modules/.bin/nodemon

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions api/node_modules/.bin/nodemon.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions api/node_modules/.bin/nodemon.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions api/node_modules/.bin/nodetouch

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions api/node_modules/.bin/nodetouch.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions api/node_modules/.bin/nodetouch.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions api/node_modules/.bin/nopt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions api/node_modules/.bin/nopt.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions api/node_modules/.bin/nopt.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions api/node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading