Skip to content

Instantly share code, notes, and snippets.

View IvsonEmidio's full-sized avatar
🎵
Now the oceans have drained out, can I come up for air?

IvsonEmidio

🎵
Now the oceans have drained out, can I come up for air?
View GitHub Profile
@IvsonEmidio
IvsonEmidio / solid-ocp-violation.ts
Created May 1, 2022 22:11
SOLID - OCP - VIOLATION
//First generic class
class Diablo {
private readonly brand = "Lamborghini";
private readonly color = "black";
}
//Second generic class
class Soul {
readonly brand = "Kia";
readonly color = "Red";
@IvsonEmidio
IvsonEmidio / solid-ocp-interface.ts
Created May 1, 2022 22:39
SOLID - OCP - Interface
export default interface ICar {
readonly brand: string;
readonly color: string;
getMarketPrice(): Promise<number>;
}
@IvsonEmidio
IvsonEmidio / solid-ocp-correct.ts
Last active May 1, 2022 22:42
SOLID - OCP - CORRECT
import ICar from "./ICar";
class Diablo implements ICar {
readonly brand = "Lamborghini";
readonly color = "black";
public getMarketPrice(): Promise<number> {
return new Promise((resolve, reject) => {
let result = 200;
@IvsonEmidio
IvsonEmidio / solid-ocp-violation-two.ts
Created May 1, 2022 23:29
SOLID - OCP - VIOLATION - EXAMPLE 2
class clients {
public function sendEmail (emailType: string){
if (emailType === 'html'){
let email = parseHtml(this.email);
} else if (emailType === 'plainText'){
let email = parsePlainText(this.email);
} else if (emailType === 'numeric') {
let email = parseNumeric(this.email);
}
@IvsonEmidio
IvsonEmidio / solid-ocp-correct-two.ts
Created May 1, 2022 23:37
SOLID - OCP - CORRECT EXAMPLE
interface IEmailSend {
send(): boolean;
}
class htmlEmail implements IEmailSend {
public function send () {
return util.sendEmail(this.email, this.user);
}
}
@IvsonEmidio
IvsonEmidio / codigo-exemplo.js
Created May 5, 2022 00:49
Contéudo da aula meet
function solucao(esquerda, direita){
if (esquerda > direita){
console.log("esquerda ganhando");
} else if (esquerda < direita){
console.log("direita ganhando");
} else if (esquerda + direita === 0){
console.log("nenhum voto");
@IvsonEmidio
IvsonEmidio / UserControllerExample.ts
Last active June 28, 2022 18:40
Zeus Controller Example
import { Request, Response } from "express";
import { pool } from "database";
export class UserController {
public async create(req: Request, res: Response) {
const { name, password, email } = req.body;
if (!name) {
return res.status(400).json({ message: "Field name cannot be empty" });
}
import { Application } from "express";
import { UserController } from "../controllers/UserController";
export default function userRoutes(app: Application) {
const controller = new UserController();
app.post(
"/user",
controller.create.bind(controller)
);
import { body, ValidationChain } from "express-validator";
export function validatePost(): ValidationChain[] {
return [
body("name", "check the field 'name' and try again.")
.isString()
.isLength({ min: 3, max: 35 }),
body("email", "check the field 'email' and try again").isEmail(),
import { Request, Response } from "express";
import { pool } from "database";
import { validationResult } from "express-validator";
export class UserController {
public async create(req: Request, res: Response) {
try {
const errors = validationResult(req);
if (!errors.isEmpty()) {