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
Binary file modified .DS_Store
Binary file not shown.
Binary file modified modulo05/.DS_Store
Binary file not shown.
Binary file added modulo05/classes-encapsulamento/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
build/
.env
.DS_Store
package-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "plantao",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "ts-node-dev ./src/index.ts",
"start": "tsc && node ./build/index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/knex": "^0.16.1",
"@types/node": "^17.0.38",
"@types/uuid": "^8.3.4",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"knex": "^2.1.0",
"mysql": "^2.18.1",
"ts-node-dev": "^2.0.0",
"typescript": "^4.7.2",
"uuid": "^8.3.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
GET http://localhost:3003/character

###

POST http://localhost:3003/character
Content-Type: application/json

{
"name": "Rick Sanches",
"team": "Vasco",
"age": 35
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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.`);
}
});;
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// type Character = {
// id: string,
// name: string,
// team: string,
// age: number
// }

export class Character {
private id: string
private name: string
private team: string
private age: number

constructor(id: string, name: string, team: string, age: number) {
this.id = id,
this.name = name,
this.team = team,
this.age = age
}

public getId():string {
return this.id
}

public getName():string {
return this.name
}

public getTeam():string {
return this.team
}

public getAge():number{
return this.age
}
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import knex from "knex";
import dotenv from "dotenv";
import { Character } from "./Character";

dotenv.config();

export class CharacterDataBase {

private connection = knex({
client: "mysql",
connection: {
host: process.env.DB_HOST,
port: 3306,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_SCHEMA
}
});

public getAll = async () => {
try {
const result = await this.connection('Characters')
.select('*')

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

public create = async (character :Character) => {
try {
await this.connection('Characters')
.insert({
id: character.getId(),
name: character.getName(),
team: character.getTeam(),
age: character.getAge()
})
// Ou
// .insert(character)
} catch (error:any) {
throw new Error(error.sqlMessage || error.message);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import knex from "knex";
import dotenv from "dotenv";

dotenv.config();


export const connection = knex({
client: "mysql",
connection: {
host: process.env.DB_HOST,
port: 3306,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_SCHEMA
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// EXERCÍCIO 1

// A. O construtuctor permite para parâmetros a uma classe quando instanciada.

// B. Nunhuma vez foi impressa no terminal, não tem o type transsaction e não foi passado parâmetros
class UserAccount {
private cpf: string;
private name: string;
private age: number;
private balance: number = 0;
private transactions: Transaction[] = [];

constructor(cpf: string, name: string, age: number) {
console.log("Chamando o construtor da classe UserAccount");
this.cpf = cpf;
this.name = name;
this.age = age;
}
// EXERCÍCIO 2
public getNome = (): string => {
return this.name;
};
public getcpf = (): string => {
return this.cpf;
};
public getidade = (): number => {
return this.age;
};
}

// C. Criando métodos públicos
const cadastroCliente = new UserAccount("876980860", "Fulana", 45);
console.log(
cadastroCliente.getNome(),
cadastroCliente.getcpf(),
cadastroCliente.getidade()
);

// EXERCÍCIO 2

type Transaction = {
description: string;
value: number;
date: string;
};

// EXERCÍCIO 3

class Bank {
private accounts: UserAccount[];

constructor(accounts: UserAccount[]) {
this.accounts = accounts;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"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. */
}
}
6 changes: 6 additions & 0 deletions modulo05/classes-encapsulamento/package-lock.json

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