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

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

12 changes: 12 additions & 0 deletions semana-15/aula-42/exercício-aula/FIRST-SCRIPT/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "FIRST-SCRIPT",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
98 changes: 98 additions & 0 deletions semana-15/aula-42/exercício-aula/FIRST-SCRIPT/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
type User = {
name: string,
age:number
}

console.log("hello World")

//Declarando variáveis em ts

const company: string = "Labenu"
let age: number = 5
let passwordIsCorrect: boolean = false

//Utilizando union type (mais de uma tipagem)

let text: string | undefined = "Mariana"
let message: string | null = null
let nickname: string|boolean = ""

//declarando array

const userIds: number[] = [0,1,2,3] //opção 1
const clientIds: Array<number> = [0,1,2,3] //opção 2

//declarando array com union type

const phrase1: (string|number)[]= ["o","i","!",6] //opção 1
const phrase2: Array<string|number> = ["o","i",1,5] //opção 2

// declarando objetos

const user:{name: string, age: number} = {
name: "Astrodev",
age: 500
}

// declarando objetos usando o type

const user1:User = {
name: "astrodev",
age:12
}


// exercício 1

type Carro = {
marca: string,
volumeDoTanque: number,
temMotorFlex: boolean
}

const mustang: Carro = {
marca: "Ford",
volumeDoTanque: 61,
temMotorFlex: false
}

const gol: Carro = {
marca: "Volkswagen",
volumeDoTanque: 55,
temMotorFlex: true
}

const uno: Carro ={
marca: "Fiat",
volumeDoTanque: 45,
temMotorFlex: false
}

const automoveis: Carro[] = []

automoveis.push(gol)
automoveis.push(uno)
automoveis.push(mustang)
automoveis.push({marca: "Fiat", volumeDoTanque:55, temMotorFlex: true})

console.log(automoveis)

// tipagem função

const buscarCarrosPorMarca = (
frota: Carro[],
marca?:String
): Carro[] => {
if (marca === undefined){
return frota
}

return frota.filter(
(carro)=>{
return carro.marca === marca
}
)
}

console.log(buscarCarrosPorMarca(automoveis,"Volkswagen"))

11 changes: 11 additions & 0 deletions semana-15/aula-42/exercício-aula/FIRST-SCRIPT/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"sourceMap": true,
"outDir":"./build",
"rootDir":"./src",
"removeComments": true,
"noImplicitAny": true,
}
}
4 changes: 2 additions & 2 deletions semana-16/aula-45/Exercício_aula-45.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ VALUES(
"006",
"Pedro Bandeira",
500000,
1979-05-26,
"1979-05-26",
"male"
);

Expand All @@ -74,7 +74,7 @@ VALUES(
"007",
"Carolina Dickman",
400000,
1985-05-06,
"1985-05-06",
"female"
);

Expand Down
Binary file added semana-22/rodadaDeCase-FrontEnd/cuboBack.zip
Binary file not shown.
4 changes: 4 additions & 0 deletions semana-22/rodadaDeCase-FrontEnd/cuboBack/cuboBack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
package-lock.json
build
.env
30 changes: 30 additions & 0 deletions semana-22/rodadaDeCase-FrontEnd/cuboBack/cuboBack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "cuboBack",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "tsc && node ./build/index.js",
"dev": "ts-node-dev ./src/index.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"ts-node-dev": "^1.1.8",
"typescript": "^4.5.4"
},
"dependencies": {
"@types/knex": "^0.16.1",
"@types/uuid": "^8.3.4",
"cors": "^2.8.5",
"dotenv": "^14.2.0",
"express": "^4.17.2",
"knex": "^1.0.1",
"mysql": "^2.18.1",
"uuid": "^8.3.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { UserData } from "../data/UserData";
import { MissingFieldsToComplet } from "../error/MissingFieldsToComplet";
import { UserInputDTO, UserInsertDTO } from "../model/User";
import IdGenerator from "../services/IdGenerator";

export class UserBusinees {

async user(input: UserInputDTO) {


const userData = new UserData()
const result = await userData.insertUser(user)

return result
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Request, Response } from "express";
import { UserBusinees } from "../business/UserBusiness";
import { UserInputDTO } from "../model/User";

export class UserController {

async createUser(req: Request, res: Response) {
try {
const { firstName, lastName, participation } = req.body;

const input: UserInputDTO = {
firstName,
lastName,
participation
}

const userBusiness = new UserBusinees()
const message = await userBusiness.user(input)

res.status(200).send({message})

} catch (error) {
if (error instanceof Error) {
res.status(400).json({ message: error.message })
} else {
res.status(400).send({ message: "Unexpected Error !" })
}
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import express, { Express, Request, Response } from "express";
import cors from "cors";
import { AddressInfo } from "net";


export const app: Express = 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.`);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import knex, { Knex } from 'knex'
import { config } from 'dotenv'

config()

export class BaseDataBase {

protected static connection: Knex | null = null

protected getConnection(): Knex {
if (!BaseDataBase.connection) {
BaseDataBase.connection = knex({
client: "mysql",
connection: {
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
port: 3306,
}
})
}

return BaseDataBase.connection
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { UserInsertDTO } from "../model/User";
import { BaseDataBase } from "./BaseDataBase";

export class UserData extends BaseDataBase {

private static TABLE_NAME = "usuario_cubo"


async insertUser(user: UserInsertDTO): Promise<string> {
try {

const { id, firstName, lastName, participation } = user

await this.getConnection().insert({
id,
firstName,
lastName,
participation
}).into(UserData.TABLE_NAME)

return "Usuario criado com sucesso"
} catch (error) {
if (error instanceof Error) {
throw new Error(error.message)
} else {
throw new Error("Erro do banco !")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class BaseError extends Error{
constructor(message:string){
super(message);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BaseError } from "./BaseError";

export class MissingFieldsToComplet extends BaseError{
constructor(){
super("Missing fields to complet");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { app } from "./controller/app";
import { userRouter } from "./router/userRouter";


app.use("/user",userRouter)


Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface UserInputDTO {
firstName: string,
lastName: string,
participation: number
}

export interface UserInsertDTO extends UserInputDTO {
id:string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Router } from "express";
import { UserController } from "../controller/UserController";


export const userRouter = Router();

const userController = new UserController()

userRouter.post("/create",userController.createUser)

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { v4 } from "uuid";

export class IdGenerator {

generete(): string {
return v4();
}
}


export default new IdGenerator()
Loading