-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33c3911
commit e398ebb
Showing
15 changed files
with
236 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const FormatoInvalido = require('./erros/Formatoinvalido'); | ||
|
||
class Serializar { | ||
json (dados){ | ||
JSON.stringify(dados) | ||
} | ||
transformar(dados){ | ||
if(this.contentType !== 'application/json'){ | ||
throw new FormatoInvalido(this.contentType); | ||
|
||
} | ||
return this.json(this.filtrar(dados)); | ||
} | ||
filtrarCampos (dados){ | ||
const camposFiltrados = {}; | ||
this.camposPermitidos.forEach(campo => { | ||
if(dados.hasOwnProperty(campo)){ | ||
camposFiltrados[campo]= dados[campo]; | ||
} | ||
|
||
}); | ||
} | ||
filtrar(dados){ | ||
let dadosFiltrados = this.filtrarCampos(dados); | ||
|
||
if(Array.isArray(dados)){ | ||
dadosFiltrados.map((dados)=>{ | ||
return this.filtrarCampos(dados); | ||
|
||
}) | ||
} | ||
|
||
return dadosFiltrados; | ||
} | ||
} | ||
|
||
class SerializarAgendamento extends Serializar{ | ||
constructor(contentType, camposPersonalizados){ | ||
super() | ||
this.contentType = contentType; | ||
this.camposPermitidos = ['id', 'nome_cliente', 'data_agendamento'].concat(camposPersonalizados || []) | ||
} | ||
} | ||
module.exports ={ | ||
Serializar: Serializar, | ||
SerializarAgendamento: SerializarAgendamento, | ||
FormatosValidos : ['application/json'] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const { removeAllListeners } = require('nodemon'); | ||
const modeloAgendamento = require('./modelTabelaAgendamento'); | ||
|
||
module.exports = { | ||
async listar() { | ||
try{ | ||
return await modeloAgendamento.findAll({ | ||
raw: true, | ||
}); | ||
|
||
} | ||
catch(error){ | ||
throw error | ||
} | ||
|
||
}, | ||
|
||
async adicionar(agendamento) { | ||
try{ | ||
return await modeloAgendamento.create(agendamento); | ||
} | ||
catch(error){ | ||
throw error | ||
} | ||
|
||
}, | ||
|
||
async buscarPorPK(id) { | ||
try{ | ||
return await modeloAgendamento.findByPk(id); | ||
} | ||
catch(error){ | ||
throw error | ||
} | ||
|
||
}, | ||
|
||
async remover(id) { | ||
try{ | ||
return await modeloAgendamento.destroy({ | ||
where: { | ||
id: id | ||
} | ||
}); | ||
} | ||
catch(error){ | ||
throw error | ||
} | ||
|
||
}, | ||
async atualizar (id, dados){ | ||
try{ | ||
return await modeloAgendamento. update(dados, | ||
{where: { | ||
id:id | ||
}}) | ||
|
||
} | ||
catch(error){ | ||
throw error | ||
} | ||
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
const ModeloTabelaAgendamento = require('../agendamentos/TabelaAgendamentos'); | ||
const ModeloTabelaAgendamento = require('../agendamentos/modelTabelaAgendamento'); | ||
|
||
ModeloTabelaAgendamento.sync() | ||
.then(()=>{ | ||
console.log('Tabela ciada com sucesso') | ||
.then(()=> { | ||
console.log('Tabela criada com sucesso') | ||
}) | ||
.catch( | ||
.catch(() => { | ||
console.log('Erro, tabela não criada') | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CampoQtdMinhima extends Error{ | ||
constructor(campo){ | ||
const mensagem = `O campo ${campo} tem que ter no mínimo 8 carcateres!` | ||
super(mensagem); | ||
this.name ='CampoQtdMinima'; | ||
this.idError = 2; | ||
|
||
} | ||
} | ||
module.exports = CampoQtdMinhima; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CampoQtdMaxima extends Error{ | ||
constructor(campo){ | ||
const mensagem = `O campo ${campo} tem que ter no máximo 64 carcateres!` | ||
super(mensagem); | ||
this.name ='CampoQtdMaxima'; | ||
this.idError = 5; | ||
|
||
} | ||
} | ||
module.exports = CampoQtdMaxima; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CampoInvalido extends Error { | ||
constructor(campo){ | ||
const mensagem = `O campo ${campo} está inválido!` | ||
super(mensagem); | ||
this.name = 'CampoInvalido'; | ||
this.idError =1; | ||
} | ||
} | ||
module.exports = CampoInvalido; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class DadosNaoInformados extends Error { | ||
constructor(){ | ||
super('Dados não informados'); | ||
this.name ='DadosNaoInformados'; | ||
this.idError = 3; | ||
|
||
} | ||
} | ||
module.exports = DadosNaoInformados; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class FormatoInvalido extends Error{ | ||
constructor(contentType){ | ||
const mensagem = `O tipo ${contentType} é inválido! A API aceita somente JSON` | ||
super(mensagem); | ||
this.name = 'FormatoInvalido'; | ||
this.idError = 6; | ||
} | ||
} | ||
module.exports = FormatoInvalido; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class NaoEncontrado extends Error{ | ||
constructor(agendamento){ | ||
super('O agendamento não foi encontrado!'); | ||
this.name = 'NaoEncontrado'; | ||
this.id = 4; | ||
|
||
} | ||
} | ||
module.exports = NaoEncontrado; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.