Coder Social home page Coder Social logo

barbershopapi's People

Contributors

phrezende-eng avatar

Watchers

 avatar

barbershopapi's Issues

Definir um escopo de Exceptions

Para cada tipo de exception, terá um tipo de status e message, por isso extender da classe error para criarmos nossas próprias exceptions
Throws, deverão lançar exceptions ao invés de serem retornadas

Example:

throw new Error('database failed to connect')
class InternalErrorextends Error {
  constructor(message) {
    super(message);
    this.name = "InternalError";
  }
 }

Validating type error:

try {
  someFunction();
}
catch (Error) {
  // do something else
}

OR?

try{
// Your code block
}catch(error){
  if (error instanceof Error) {
      // do something else
    } else {
     // do other thing else
    }
}

Cada classe de Error terá um range de status code
Tipos de errors: NotFound, InternalError, InvalidField, RequiredField

Dito isso, posso criar algumas classes de Error interno que implementem Error. Portanto, ao identificar a exception no catch da rota, saberei dizer qual o status code

Não sobrescrever errors

Manter o route retornando res...

Modelagem do Usuário

Esta issue está aberta a fim de melhorar modelagem do usuário com o intuito de separar os dados do Usuário ADM para do Usuário Colaborador.

Desta forma, deverá exisitir uma relação pai

User

com as seguintes colunas:
String id;
String name;
String email;
String? avatar;

Que Herdará essas colunas para seus filhos User ADM e User Employee,
Onde o

User ADM

deverá ter as seguintes colunas:
List? workDays;
List? workHours;

E o

User Employee

deverá ter as seguintes colunas:
int barberShopId;
List workDays;
List workHours;

Trazer todas as funções que manipulam tabelas para dentro de suas respectivas models

Exemplo

Before:

export abstract class UserModel {
    id: number;
    name: string;
    email: string;
    avatar?: string;
    profile: string;
    password: string;

    constructor(id: number, name: string, email: string, profile: string, password: string, avatar?: string) {
        this.id = id;
        this.name = name;
        this.email = email;
        this.avatar = avatar;
        this.profile = profile;
        this.password = password;
    }
}

After:

export abstract class UserModel {
    id: number;
    name: string;
    email: string;
    avatar?: string;
    profile: string;
    password: string;

    constructor(id: number, name: string, email: string, profile: string, password: string, avatar?: string) {
        this.id = id;
        this.name = name;
        this.email = email;
        this.avatar = avatar;
        this.profile = profile;
        this.password = password;
    }

    async insertUserOnDB(userData: any): Promise<User> {
        //TODO: TREAT if not exists
        try {
            const user = await prisma.user.create(
                {
                    data: {
                        name: userData.name,
                        email: userData.email,
                        password: userData.password,
                        avatar: userData.avatar,
                        profile: userData.profile == 'A' ? Profile.A : Profile.E,
                    },
                }
            );
            return user;
        } catch (error) {
            throw error;
        }
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.