formatação
This commit is contained in:
parent
e705901982
commit
785588b37e
31 changed files with 178 additions and 167 deletions
|
|
@ -1,7 +1,7 @@
|
|||
const alfabeto = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");
|
||||
const alfabeto = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("")
|
||||
|
||||
export const aleatorio = (tamanho?: number) =>
|
||||
Array.from(
|
||||
{ length: tamanho || 8 },
|
||||
() => `ale-${alfabeto[Math.floor(Math.random() * 1000) % alfabeto.length]}`,
|
||||
).join("");
|
||||
).join("")
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { z } from "zod";
|
||||
import { z } from "zod"
|
||||
|
||||
export const InterfaceAuntenticacao = z.object({
|
||||
// usuários
|
||||
|
|
@ -23,4 +23,4 @@ export const InterfaceAuntenticacao = z.object({
|
|||
url_usuarios: z.string().url(),
|
||||
url_empreendedores: z.string().url(),
|
||||
url_empreendimentos: z.string().url(),
|
||||
});
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
/** Sistemas vão conversar por meio de autorizações tipar eles aqui */
|
||||
|
||||
export * from "./auntenticacaoResiduos";
|
||||
export * from "./auntenticacaoResiduos"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
export const uuid_null = "00000000-0000-0000-0000-000000000000";
|
||||
export const uuid_null = "00000000-0000-0000-0000-000000000000"
|
||||
|
||||
/** Colunas Presentes n maioria das tabelas */
|
||||
export enum camposComuns {
|
||||
|
|
|
|||
|
|
@ -10,19 +10,19 @@ export enum operadores {
|
|||
}
|
||||
|
||||
export type tipoFiltro = {
|
||||
coluna: string;
|
||||
valor: any;
|
||||
operador: keyof typeof operadores | operadores;
|
||||
ou?: boolean;
|
||||
};
|
||||
coluna: string
|
||||
valor: any
|
||||
operador: keyof typeof operadores | operadores
|
||||
ou?: boolean
|
||||
}
|
||||
|
||||
export type interfaceConsulta = {
|
||||
offset?: number;
|
||||
limit?: number;
|
||||
filtros?: tipoFiltro[];
|
||||
ordem?: string;
|
||||
ordemTipo?: "asc" | "desc";
|
||||
colunas?: string[];
|
||||
apenasConsulta?: boolean;
|
||||
apenasContagem?: boolean;
|
||||
};
|
||||
offset?: number
|
||||
limit?: number
|
||||
filtros?: tipoFiltro[]
|
||||
ordem?: string
|
||||
ordemTipo?: "asc" | "desc"
|
||||
colunas?: string[]
|
||||
apenasConsulta?: boolean
|
||||
apenasContagem?: boolean
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
export * from "./urls";
|
||||
export * from "./urls"
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
export const cdn_carro_de_boi = "https://carro-de-boi-idz-one.b-cdn.net";
|
||||
export const cdn_carro_de_boi = "https://carro-de-boi-idz-one.b-cdn.net"
|
||||
|
|
|
|||
20
src/index.ts
20
src/index.ts
|
|
@ -1,10 +1,10 @@
|
|||
export * from "./respostas";
|
||||
export * from "./autorizacoes";
|
||||
export * from "./constantes";
|
||||
export * from "./consulta";
|
||||
export * from "./aleatorio";
|
||||
export * from "./texto_busca";
|
||||
export * from "./unidades_medida";
|
||||
export * from "./uuid";
|
||||
export * from "./provedores";
|
||||
export * from "./ecosistema";
|
||||
export * from "./respostas"
|
||||
export * from "./autorizacoes"
|
||||
export * from "./constantes"
|
||||
export * from "./consulta"
|
||||
export * from "./aleatorio"
|
||||
export * from "./texto_busca"
|
||||
export * from "./unidades_medida"
|
||||
export * from "./uuid"
|
||||
export * from "./provedores"
|
||||
export * from "./ecosistema"
|
||||
|
|
|
|||
|
|
@ -1,42 +1,42 @@
|
|||
import { esperar } from "./variaveisComuns";
|
||||
import { esperar } from "./variaveisComuns"
|
||||
|
||||
export const codigosErros = {
|
||||
400: "Erro de requisição",
|
||||
403: "Não autenticado",
|
||||
500: "Erro interno",
|
||||
504: "Tempo de resposta excedido",
|
||||
};
|
||||
}
|
||||
|
||||
export interface tipoRespostaSucesso<T> {
|
||||
codigo: 200;
|
||||
eErro: false;
|
||||
valor: T;
|
||||
erro: undefined;
|
||||
detalhes?: any[];
|
||||
codigo: 200
|
||||
eErro: false
|
||||
valor: T
|
||||
erro: undefined
|
||||
detalhes?: any[]
|
||||
}
|
||||
|
||||
export interface tipoRespostaErro {
|
||||
codigo: keyof typeof codigosErros;
|
||||
eErro: true;
|
||||
erro: string;
|
||||
valor: undefined;
|
||||
detalhes?: any[];
|
||||
codigo: keyof typeof codigosErros
|
||||
eErro: true
|
||||
erro: string
|
||||
valor: undefined
|
||||
detalhes?: any[]
|
||||
}
|
||||
|
||||
export type tipoResposta<T> = tipoRespostaSucesso<T> | tipoRespostaErro;
|
||||
export type tipoResposta<T> = tipoRespostaSucesso<T> | tipoRespostaErro
|
||||
|
||||
export class Resposta<opcoesErroInterno extends any[]> {
|
||||
funcaoErroInterno: (...opcoes: opcoesErroInterno) => void | Promise<void>;
|
||||
detalhesErroInterno: boolean;
|
||||
funcaoErroInterno: (...opcoes: opcoesErroInterno) => void | Promise<void>
|
||||
detalhesErroInterno: boolean
|
||||
|
||||
constructor(
|
||||
funcaoErroInterno: (...arg1: opcoesErroInterno) => void | Promise<void>,
|
||||
opcoes?: {
|
||||
detalhesErroInterno?: boolean;
|
||||
detalhesErroInterno?: boolean
|
||||
},
|
||||
) {
|
||||
this.funcaoErroInterno = funcaoErroInterno;
|
||||
this.detalhesErroInterno = opcoes?.detalhesErroInterno || false;
|
||||
this.funcaoErroInterno = funcaoErroInterno
|
||||
this.detalhesErroInterno = opcoes?.detalhesErroInterno || false
|
||||
}
|
||||
|
||||
addResultado<T>(resultado: T): tipoResposta<T> {
|
||||
|
|
@ -45,15 +45,15 @@ export class Resposta<opcoesErroInterno extends any[]> {
|
|||
eErro: false,
|
||||
valor: resultado,
|
||||
erro: undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
addSucesso(resultado: string): tipoResposta<string> {
|
||||
return this.addResultado<string>(resultado);
|
||||
return this.addResultado<string>(resultado)
|
||||
}
|
||||
|
||||
addTrue(): tipoResposta<true> {
|
||||
return this.addResultado<true>(true);
|
||||
return this.addResultado<true>(true)
|
||||
}
|
||||
|
||||
addErro(erro: string, codigo?: keyof typeof codigosErros): tipoRespostaErro {
|
||||
|
|
@ -62,7 +62,7 @@ export class Resposta<opcoesErroInterno extends any[]> {
|
|||
eErro: true,
|
||||
erro: erro,
|
||||
valor: undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
addErroEspera(erro?: string): tipoRespostaErro {
|
||||
|
|
@ -71,19 +71,19 @@ export class Resposta<opcoesErroInterno extends any[]> {
|
|||
eErro: true,
|
||||
erro: erro || codigosErros[504],
|
||||
valor: undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
addErroInterno(...opcoes: opcoesErroInterno): tipoRespostaErro {
|
||||
//comunica o suporte sobre o erro
|
||||
this.funcaoErroInterno(...opcoes);
|
||||
this.funcaoErroInterno(...opcoes)
|
||||
return {
|
||||
codigo: 500,
|
||||
eErro: true,
|
||||
erro: "Erro interno: Contate o suporte técnico.",
|
||||
valor: undefined,
|
||||
detalhes: this.detalhesErroInterno ? opcoes : undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async addPromise<T>(
|
||||
|
|
@ -98,14 +98,14 @@ export class Resposta<opcoesErroInterno extends any[]> {
|
|||
...(limiteEspera
|
||||
? [esperar(limiteEspera).then(() => this.addErroEspera())]
|
||||
: []),
|
||||
]);
|
||||
return resultado;
|
||||
])
|
||||
return resultado
|
||||
} catch (error) {
|
||||
return this.addErro("Erro na resolução da Promessa.");
|
||||
return this.addErro("Erro na resolução da Promessa.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const respostaCM = new Resposta(() => {
|
||||
//
|
||||
});
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,24 +1,24 @@
|
|||
export type tipoRespostaSucesso<T> = {
|
||||
cod: 200;
|
||||
valor: T;
|
||||
mensagem: undefined;
|
||||
eErro: false;
|
||||
eCerto: true;
|
||||
detalhe?: undefined;
|
||||
};
|
||||
cod: 200
|
||||
valor: T
|
||||
mensagem: undefined
|
||||
eErro: false
|
||||
eCerto: true
|
||||
detalhe?: undefined
|
||||
}
|
||||
|
||||
export type tipoRespostaErro = {
|
||||
//400 é um erro conhecido,
|
||||
//500 é um erro desconhecido, geralmente tem origem de um exception
|
||||
cod: 400 | 403 | 500;
|
||||
valor: undefined;
|
||||
mensagem: string;
|
||||
eErro: true;
|
||||
eCerto: false;
|
||||
detalhes?: string[];
|
||||
};
|
||||
cod: 400 | 403 | 500
|
||||
valor: undefined
|
||||
mensagem: string
|
||||
eErro: true
|
||||
eCerto: false
|
||||
detalhes?: string[]
|
||||
}
|
||||
|
||||
export type tipoResposta<T> = tipoRespostaSucesso<T> | tipoRespostaErro;
|
||||
export type tipoResposta<T> = tipoRespostaSucesso<T> | tipoRespostaErro
|
||||
|
||||
export const gerarRespostas = <T>(
|
||||
registrarErroInterno: (erro: T) => Partial<tipoRespostaErro>,
|
||||
|
|
@ -33,8 +33,8 @@ export const gerarRespostas = <T>(
|
|||
mensagem: undefined,
|
||||
eErro: false,
|
||||
eCerto: true,
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gera uma resposta de sucesso com valor true
|
||||
|
|
@ -46,8 +46,8 @@ export const gerarRespostas = <T>(
|
|||
mensagem: undefined,
|
||||
eErro: false,
|
||||
eCerto: true,
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gera uma resposta de erro conhecido
|
||||
|
|
@ -60,8 +60,8 @@ export const gerarRespostas = <T>(
|
|||
eErro: true,
|
||||
eCerto: false,
|
||||
detalhes,
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gera uma resposta de erro de permissão,será necessário fazer o login novamente
|
||||
|
|
@ -77,16 +77,16 @@ export const gerarRespostas = <T>(
|
|||
eErro: true,
|
||||
eCerto: false,
|
||||
detalhes,
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gera uma resposta de erro desconhecido, geralmente tem origem de um exception
|
||||
*/
|
||||
const erroInterno = (parametros: T, mensagem?: string): tipoRespostaErro => {
|
||||
const resRegistro = registrarErroInterno(parametros);
|
||||
const resRegistro = registrarErroInterno(parametros)
|
||||
|
||||
const mensagemFim = `${mensagem || "Erro interno"}`;
|
||||
const mensagemFim = `${mensagem || "Erro interno"}`
|
||||
|
||||
return {
|
||||
cod: 500,
|
||||
|
|
@ -95,8 +95,8 @@ export const gerarRespostas = <T>(
|
|||
eErro: true,
|
||||
eCerto: false,
|
||||
...resRegistro,
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
valor,
|
||||
|
|
@ -104,10 +104,10 @@ export const gerarRespostas = <T>(
|
|||
erro,
|
||||
erroPermissao,
|
||||
erroInterno,
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uso de respostas em comuns
|
||||
*/
|
||||
export const respostaComuns = gerarRespostas(() => ({}));
|
||||
export const respostaComuns = gerarRespostas(() => ({}))
|
||||
|
|
|
|||
|
|
@ -12,4 +12,4 @@ export const texto_busca = (...texto: any[]): string =>
|
|||
.replace(/\s+/g, " ")
|
||||
.toLowerCase(),
|
||||
)
|
||||
.join(" ");
|
||||
.join(" ")
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
export const unidades_medida: {
|
||||
unidade: string;
|
||||
nome: string;
|
||||
unidade_normalizada: string;
|
||||
normalizar: (valor: number) => number;
|
||||
tipo: "massa" | "volume" | "comprimento";
|
||||
unidade: string
|
||||
nome: string
|
||||
unidade_normalizada: string
|
||||
normalizar: (valor: number) => number
|
||||
tipo: "massa" | "volume" | "comprimento"
|
||||
}[] = [
|
||||
{
|
||||
unidade: "kg",
|
||||
|
|
@ -75,4 +75,4 @@ export const unidades_medida: {
|
|||
normalizar: (valor: number) => valor * 1000,
|
||||
tipo: "comprimento",
|
||||
},
|
||||
];
|
||||
]
|
||||
|
|
|
|||
12
src/uuid.ts
12
src/uuid.ts
|
|
@ -1,15 +1,15 @@
|
|||
//Gerar uma uuid V4
|
||||
const letras = "0123456789abcdef".split("");
|
||||
const letras = "0123456789abcdef".split("")
|
||||
export const uuid = () => {
|
||||
letras.sort(() => Math.random() - 0.5);
|
||||
const modelo = "xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx".split("");
|
||||
letras.sort(() => Math.random() - 0.5)
|
||||
const modelo = "xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx".split("")
|
||||
const retorno = modelo
|
||||
.map((letra) =>
|
||||
letra === "x"
|
||||
? letras[((1000 * Math.random()) | 0) % letras.length]
|
||||
: letra,
|
||||
)
|
||||
.join("");
|
||||
.join("")
|
||||
|
||||
return retorno;
|
||||
};
|
||||
return retorno
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
export const esperar = (ms: number): Promise<true> =>
|
||||
new Promise((resolve: (r: true) => void) =>
|
||||
setTimeout(() => resolve(true), ms),
|
||||
);
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue