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
3 changes: 3 additions & 0 deletions modulo4/revisao-modulo-4/revisão-modulo-4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build
.env
5,360 changes: 5,360 additions & 0 deletions modulo4/revisao-modulo-4/revisão-modulo-4/package-lock.json

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions modulo4/revisao-modulo-4/revisão-modulo-4/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "revisao-modulo-4",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "tsc && node ./build/index.js",
"dev": "tsnd --transpile-only --ignore-watch node_modules ./src/index.ts",
"build": "tsc",
"migrations": "tsnd ./src/data/migrations.ts"
},
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "4.17.0",
"knex": "^0.21.1",
"mysql": "^2.18.1"
},
"devDependencies": {
"@types/cors": "^2.8.8",
"@types/express": "4.17.0",
"@types/knex": "^0.16.1",
"@types/node": "^13.7.7",
"ts-node-dev": "^1.0.0-pre.44",
"typescript": "^3.8.3"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import connection from "../connection";
import { Request, Response } from "express";


export const AddProduct = async (req:Request, res:Response):Promise<void> =>{

try{
const id = Date.now()
const name = req.body.name
const price = req.body.price
const image_url = req.body.image_url

await connection.raw(`INSERT INTO LBC_Products VALUES (
'${id}',
'${name}',
'${price}',
'${image_url}')`
)

res.status(200).send("Produto criado com sucesso...")


}catch (error){

res.status(500).send("Algo de errado não está certo !!!")

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import connection from "../connection";
import { Request, Response } from "express";


export const AddPurchase = async (req:Request, res:Response):Promise<void> =>{

try{
const id = Date.now()
const user_id = req.body.user_id
const product_id = req.body.product_id
const quantity = req.body.quantity

await connection.raw(`INSERT INTO LBC_Purchases VALUES (
'${id}',
'${user_id}',
'${product_id}',
'${quantity}',
'${id}')`
)

res.status(200).send("Produto Comprado com sucesso...")


}catch (error){

res.status(500).send("Algo de errado não está certo !!!")

}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import connection from "../connection";
import { Request, Response } from "express";


export const AddUser = async (req:Request, res:Response):Promise<void> =>{

try{
const id = Date.now()
const name = req.body.name
const email = req.body.email
const password = req.body.password

await connection.raw(`INSERT INTO LBC_Users VALUES (
'${id}',
'${name}',
'${email}',
'${password}')`
)

res.status(200).send("Usuario Criado com sucesso...")


}catch (error){

res.status(500).send("Algo de errado não está certo !!!")

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import connection from "../connection";
import { Request, Response } from "express";




const AllPuchaseUser = async (req:Request, res:Response):Promise<void> => {
const id = req.params.user_id

const resoltado = await connection.raw
(`SELECT LBC_Users.name, LBC_Users.email, LBC_Products.name, LBC_Purchases.quantity FROM LBC_Users INNER JOIN LBC_Purchases ON LBC_Users.id = LBC_Purchases.user_id INNER JOIN LBC_Products ON LBC_Purchases.product_id = LBC_Products.id where LBC_Users.id = "${id}"`)

res.status(200).send(resoltado[0])
}

export default AllPuchaseUser
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import connection from "../connection";
import { Request, Response } from "express";




export const AllProducts = async (req:Request, res:Response):Promise<void> => {

const resoltado = await connection.raw('SELECT * FROM LBC_Products')

res.status(200).send(resoltado[0])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import connection from "../connection";
import { Request, Response } from "express";




export const AllUsers = async (req:Request, res:Response):Promise<void> => {

const resoltado = await connection.raw('SELECT * FROM LBC_Users')

res.status(200).send(resoltado[0])
}
12 changes: 12 additions & 0 deletions modulo4/revisao-modulo-4/revisão-modulo-4/src/ENDPOINTS/teste.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import connection from "../connection";
import { Request, Response } from "express";




export const teSte = async (req:Request, res:Response):Promise<void> => {

const resoltado = await connection.raw('SELECT * FROM TDL_users')

res.status(200).send(resoltado[0])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import connection from "../connection";
import { Request, Response } from "express";
// import { user } from "../TYPES/types";

export const userRegistration = async (req:Request, res:Response):Promise<void> =>{

try{

const id = Date.now()
const name = req.body.name
const nickname = req.body.nickname
const email = req.body.email

await connection.raw(`INSERT INTO TDL_users VALUES (
'${id}',
'${name}',
'${nickname}',
'${email}')`
)

res.status(200).send("Usuario Criado com sucesso...")


}catch (error){

res.status(500).send("Algo de errado não está certo !!!")

}
}
7 changes: 7 additions & 0 deletions modulo4/revisao-modulo-4/revisão-modulo-4/src/TYPES/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type user = {

id: string
name: string
email: string
password: string
}
18 changes: 18 additions & 0 deletions modulo4/revisao-modulo-4/revisão-modulo-4/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import express from "express"
import cors from "cors"
import { AddressInfo } from "net"

export const app = express()

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

const server = app.listen(process.env.PORT || 3003, () => {
if (server) {
const address = server.address() as AddressInfo;
console.log(`Server is running in http://localhost:${address.port}`);
} else {
console.error(`Failure upon starting server.`);
}
})

18 changes: 18 additions & 0 deletions modulo4/revisao-modulo-4/revisão-modulo-4/src/connection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import knex from 'knex'
import dotenv from 'dotenv'

dotenv.config()

const connection = knex({
client: "mysql",
connection: {
host: process.env.DB_HOST,
port: 3306,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_SCHEMA,
multipleStatements: true
}
})

export default connection
29 changes: 29 additions & 0 deletions modulo4/revisao-modulo-4/revisão-modulo-4/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { app } from "./app";
import { AddProduct } from "./ENDPOINTS/addProduct";
import { AddPurchase } from "./ENDPOINTS/addPurchase";
import { AddUser } from "./ENDPOINTS/addUser";
import { AllProducts } from "./ENDPOINTS/allProducts";
import { AllUsers } from "./ENDPOINTS/allUsers";
import { teSte } from "./ENDPOINTS/teste";
import { userRegistration } from "./ENDPOINTS/userRegistration";
import AllPuchaseUser from "./ENDPOINTS/adicionarCompra"


//------------------------tests--------------------------
app.get('/test', teSte)

app.post('/AddUser', userRegistration)
//-----------------------------------------------------


app.post("/users", AddUser)

app.get("/users", AllUsers)

app.post("/products", AddProduct)

app.get("/products", AllProducts)

app.post("/purchases", AddPurchase)

app.get("/users/:user_id/purchases", AllPuchaseUser)
12 changes: 12 additions & 0 deletions modulo4/revisao-modulo-4/revisão-modulo-4/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"outDir": "./build" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
"strict": true /* Enable all strict type-checking options. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
"resolveJsonModule": true
}
}