Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. class ClientesApi {
  2.  
  3. constructor () {
  4. this.api = new api('/api/pessoas');
  5. this.criterioAnterior = null
  6. }
  7.  
  8. pesquisar (criterio = {}) {
  9. const query = this.api.query()
  10.  
  11. if (equalObjects(criterio, this.criterioAnterior)) {
  12. return
  13. }
  14.  
  15. if (isNull(this.criterioAnterior) || !equalObjects(criterio, this.criterioAnterior)) {
  16. this.criterioAnterior = Object.assign({}, criterio)
  17. }
  18.  
  19. //Pesquisa por nome ou cpf
  20. if (isString(criterio.nome) && !isEmpty(criterio.nome)) {
  21. const cpf = somenteNumeros(criterio.nome)
  22. const campoPesquisa = isNull(cpf) ? 'nome' : 'cod_cpf_cgc'
  23. const valorPesquisa = isNull(cpf) ? criterio.nome : cpf
  24. query.like(campoPesquisa, valorPesquisa + "%")
  25. }
  26.  
  27. if (criterio.titulos) {
  28. query.filter('PessoasByVencimentos', [criterio.titulos])
  29. }
  30.  
  31. if (criterio.ativos) {
  32. query.filter('PessoasByConexao', [1])
  33. }
  34.  
  35. if (criterio.bloqueados) {
  36. query.filter('PessoasByConexao', [0])
  37. }
  38.  
  39. if (criterio.bloqueados && criterio.ativos) {
  40. query.removeFilter('PessoasByConexao')
  41. }
  42.  
  43. if (isNumber(criterio.contas)) {
  44. query.filter('PessoasByConta', [criterio.contas])
  45. }
  46.  
  47. if (isNumber(criterio.cidades)) {
  48. query.equal('ref_cidade', criterio.cidades)
  49. }
  50.  
  51. if (isNumber(criterio.page)) {
  52. query.paginate(criterio.size || PER_PAGE, criterio.page)
  53. }
  54.  
  55. return query.find()
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement