Created
September 5, 2019 18:47
-
-
Save lpj145/7defb102d236d9c6eaf2ac18df4dcb4c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class ClientesApi { | |
| constructor () { | |
| this.api = new api('/api/pessoas'); | |
| this.criterioAnterior = null | |
| } | |
| pesquisar (criterio = {}) { | |
| const query = this.api.query() | |
| if (equalObjects(criterio, this.criterioAnterior)) { | |
| return | |
| } | |
| if (isNull(this.criterioAnterior) || !equalObjects(criterio, this.criterioAnterior)) { | |
| this.criterioAnterior = Object.assign({}, criterio) | |
| } | |
| //Pesquisa por nome ou cpf | |
| if (isString(criterio.nome) && !isEmpty(criterio.nome)) { | |
| const cpf = somenteNumeros(criterio.nome) | |
| const campoPesquisa = isNull(cpf) ? 'nome' : 'cod_cpf_cgc' | |
| const valorPesquisa = isNull(cpf) ? criterio.nome : cpf | |
| query.like(campoPesquisa, valorPesquisa + "%") | |
| } | |
| if (criterio.titulos) { | |
| query.filter('PessoasByVencimentos', [criterio.titulos]) | |
| } | |
| if (criterio.ativos) { | |
| query.filter('PessoasByConexao', [1]) | |
| } | |
| if (criterio.bloqueados) { | |
| query.filter('PessoasByConexao', [0]) | |
| } | |
| if (criterio.bloqueados && criterio.ativos) { | |
| query.removeFilter('PessoasByConexao') | |
| } | |
| if (isNumber(criterio.contas)) { | |
| query.filter('PessoasByConta', [criterio.contas]) | |
| } | |
| if (isNumber(criterio.cidades)) { | |
| query.equal('ref_cidade', criterio.cidades) | |
| } | |
| if (isNumber(criterio.page)) { | |
| query.paginate(criterio.size || PER_PAGE, criterio.page) | |
| } | |
| return query.find() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment