diogenes 2 lat temu
rodzic
commit
9e484278cb

+ 0 - 16
db/migrations/20210818220919_Usuarios.js

@@ -1,16 +0,0 @@
-exports.up = function(knex, Promise) {
-    return knex.schema.createTable('usuario', t => {
-        t.increments('Id')
-        t.string('Nome').notNullable()
-        t.string('Login').notNullable()
-        t.string('Senha').notNullable()
-        t.integer('Ativo').notNullable()
-        t.integer('Nivel').notNullable()
-        t.integer('Setor').notNullable()
-        t.datetime('UltimoLogin')
-    })
-  };
-  
-  exports.down = function(knex, Promise) {
-    return knex.schema.dropTable('usuario')
-  };

+ 0 - 11
db/migrations/20210818225728_setor.js

@@ -1,11 +0,0 @@
-exports.up = function (knex, Promise) {
-    return knex.schema.createTable('setor', t => {
-        t.increments('Id')
-        t.string('Nome').notNullable()
-    })
-};
-
-exports.down = function (knex, Promise) {
-    return knex.schema.dropTable('setor')
-};
-

+ 0 - 16
db/migrations/20210818225740_configuracao.js

@@ -1,16 +0,0 @@
-
-
-exports.up = function (knex, Promise) {
-    return knex.schema.createTable('configuracao', t => {
-        t.increments('Id')
-        t.string('Url')
-        t.integer('Ifbotmaster')
-        t.string('Urlmaster')
-        t.string('Fotoclientes')
-    })
-};
-
-exports.down = function (knex, Promise) {
-    return knex.schema.dropTable('configuracao')
-};
-

+ 0 - 13
db/migrations/20220131143802_tb_backup.js

@@ -1,13 +0,0 @@
-
-exports.up = function(knex, Promise) {
-    return knex.schema.createTable('backup', t => {
-        t.increments('Id')
-        t.string('Nome').notNullable()
-        t.timestamp("Data").notNullable().defaultTo(knex.fn.now());  
-        t.integer('Status').notNullable()
-    })
-  };
-  
-  exports.down = function(knex, Promise) {
-    return knex.schema.dropTable('backup')
-  };

+ 0 - 16
db/migrations/20220718161350_create_indique.js

@@ -1,16 +0,0 @@
-exports.up = function (knex, Promise) {
-    return knex.schema.createTable('indique', t => {
-        t.increments('Id')
-        t.string('NomeTitular').notNullable()
-        t.string('CpfTitular').notNullable()
-        t.string('TelefoneTitular').notNullable()
-        t.string('NomeIndicado').notNullable()
-        t.string('TelefoneIndicado').notNullable()
-        t.timestamp('DataCadastro').notNullable().defaultTo(knex.raw('CURRENT_TIMESTAMP'))
-        t.integer('Status').notNullable()
-    })
-};
-
-exports.down = function (knex, Promise) {
-    return knex.schema.dropTable('indique')
-};

+ 0 - 16
db/migrations/20221119224043_cria_integracao.js

@@ -1,16 +0,0 @@
-exports.up = function(knex, Promise) {
-    return knex.schema.createTable('integracao', t => {
-        t.increments('Id')
-        t.string('Nome')
-        t.integer('Tipo')
-        t.string('Chave')
-        t.string('Url')
-        t.string('Token')
-        t.timestamp('Atualizacao').notNullable().defaultTo(knex.raw('CURRENT_TIMESTAMP'))
-        t.json("Outros")
-    })
-  };
-  
-  exports.down = function(knex, Promise) {
-    return knex.schema.dropTable('integracao')
-  };

+ 0 - 14
db/migrations/20230725203258_pesquisa.js

@@ -1,14 +0,0 @@
-exports.up = function(knex, Promise) {
-  return knex.schema.createTable('pesquisa', t => {
-      t.increments('Id')
-      t.string('Nome').notNullable()
-      t.timestamp('DataCadastro').notNullable().defaultTo(knex.raw('CURRENT_TIMESTAMP'))
-      t.string('Descricao').notNullable()
-      t.string('Cabecalho')
-      t.string('Imagem')
-  })
-};
-
-exports.down = function(knex, Promise) {
-  return knex.schema.dropTable('pesquisa')
-};

+ 0 - 13
db/migrations/20230725203505_avaliacao-basica.js

@@ -1,13 +0,0 @@
-exports.up = function(knex, Promise) {
-  return knex.schema.createTable('avaliacao_basica', t => {
-      t.increments('Id')
-      t.integer('Pesquisa').unsigned().references('Id').inTable('pesquisa').onDelete('CASCADE').index().notNullable()
-      t.string('Cliente').notNullable()
-      t.integer('Nota').notNullable()
-      t.timestamp('DataCadastro').notNullable().defaultTo(knex.raw('CURRENT_TIMESTAMP'))
-  })
-};
-
-exports.down = function(knex, Promise) {
-  return knex.schema.dropTable('avaliacao_basica')
-};

+ 0 - 13
db/migrations/20230725203515_avaliacao-completa.js

@@ -1,13 +0,0 @@
-exports.up = function(knex, Promise) {
-  return knex.schema.createTable('avaliacao_completa', t => {
-      t.increments('Id')
-      t.integer('Pesquisa').unsigned().references('Id').inTable('pesquisa').onDelete('CASCADE').index().notNullable()
-      t.string('Cliente').notNullable()
-      t.timestamp('DataCadastro').notNullable().defaultTo(knex.raw('CURRENT_TIMESTAMP'))
-      t.integer('Dados').notNullable()
-  })
-};
-
-exports.down = function(knex, Promise) {
-  return knex.schema.dropTable('avaliacao_completa')
-};

+ 0 - 13
db/migrations/20230725203522_campos-pesquisa.js

@@ -1,13 +0,0 @@
-exports.up = function(knex, Promise) {
-  return knex.schema.createTable('campos_pesquisa', t => {
-      t.increments('Id')
-      t.integer('Pesquisa').unsigned().references('Id').inTable('pesquisa').onDelete('CASCADE').index().notNullable()
-      t.string('Descricao').notNullable()
-      t.string('Nome').notNullable()
-      t.string('TipoValor').notNullable()
-  })
-};
-
-exports.down = function(knex, Promise) {
-  return knex.schema.dropTable('campos_pesquisa')
-};

+ 0 - 11
db/migrations/20230727182754_update_avaliacao_completa.js

@@ -1,11 +0,0 @@
-exports.up = function(knex, Promise) {
-  return knex.schema.alterTable('avaliacao_completa', t => {
-    t.json('Dados').notNullable().alter();
-  });
-};
-
-exports.down = function(knex, Promise) {
-  return knex.schema.alterTable('avaliacao_completa', t => {
-    t.integer('Dados').notNullable().alter();
-  });
-};

+ 0 - 11
db/migrations/20230731132926_update_pesquisa.js

@@ -1,11 +0,0 @@
-exports.up = function(knex, Promise) {
-  return knex.schema.alterTable('pesquisa', t => {
-    t.integer('IconePesquisa').notNullable()
-  });
-};
-
-exports.down = function(knex, Promise) {
-  return knex.schema.alterTable('pesquisa', t => {
-    t.dropColumn('IconePesquisa')
-  });
-};

+ 0 - 11
db/migrations/20230803183953_ajuste_pesquisa.js

@@ -1,11 +0,0 @@
-exports.up = function(knex, Promise) {
-  return knex.schema.alterTable('pesquisa', t => {
-    t.string('Cor').notNullable()
-  });
-};
-
-exports.down = function(knex, Promise) {
-  return knex.schema.alterTable('pesquisa', t => {
-    t.dropColumn('Cor')
-  });
-};

+ 0 - 13
db/migrations/20230804174546_ajuste2_pesquisa.js

@@ -1,13 +0,0 @@
-exports.up = function(knex, Promise) {
-  return knex.schema.alterTable('pesquisa', t => {
-    t.string('CorTexto').notNullable()
-    t.integer('Status').notNullable()
-  });
-};
-
-exports.down = function(knex, Promise) {
-  return knex.schema.alterTable('pesquisa', t => {
-    t.dropColumn('CorTexto')
-    t.dropColumn('Status')
-  });
-};

+ 0 - 12
db/seeds/001setor.js

@@ -1,12 +0,0 @@
-
-exports.seed = function(knex) {
-  // Deletes ALL existing entries
-  return knex('setor').del()
-    .then(function () {
-      // Inserts seed entries
-      return knex('setor').insert([
-        {Id: 1, Nome: 'ENTRADA'}
-        
-      ]);
-    });
-};

+ 0 - 17
db/seeds/configuracao.js

@@ -1,17 +0,0 @@
-
-exports.seed = function(knex) {
-  // Deletes ALL existing entries
-  return knex('configuracao').del()
-    .then(function () {
-      // Inserts seed entries
-      return knex('configuracao').insert([
-        {
-          Id: 1, 
-          Url: 'https://api.star.tv.br',
-          Ifbotmaster: 1,
-          Urlmaster: 'https://starcorp.star.psi.br/web/',
-          Fotoclientes: 'http://starcorp.star.psi.br/web/img/foto.png'
-        }
-      ]);
-    });
-};

+ 0 - 19
db/seeds/usuario.js

@@ -1,19 +0,0 @@
-
-exports.seed = function(knex) {
-  // Deletes ALL existing entries
-  return knex('usuario').del()
-    .then(function () {
-      // Inserts seed entries
-      return knex('usuario').insert([
-        {
-          "Id": 2,
-          "Nome": "SysDev",
-          "Login": "sysdev",
-          "Senha": "$2b$08$OckwNAnmdnIyjiDtCRpXN./1h2pphmTFdKpQz.U3ZLHt63Rq7NmHC",
-          "Ativo": 1,
-          "Nivel": 1,          
-          "Setor": 1
-        }
-      ]);
-    });
-};

+ 1 - 21
src/config/db.config.js

@@ -15,27 +15,7 @@ var knex = require('knex')({
   }
 });
 
-var knexlocal = require('knex')({
-  client: 'mysql',
-  connection: {
-    host: process.env.DB_HOST,
-    port: process.env.DB_PORT,
-    user: process.env.DB_USER,
-    password: process.env.DB_PASS,
-    database: process.env.DB_SCHEMA,
-    charset: "utf8mb4",
-    collation: "utf8mb4_bin",
-  },
-  migrations: {
-    tableName: 'knex_migrations',
-    directory: './db/migrations'
-  },
-  seeds: {
-    tableName: 'knex_seeds',
-    directory: './db/seeds'
-  }
-});
 
 
 module.exports.knex = knex;
-module.exports.knexlocal = knexlocal;
+//module.exports.knexlocal = knexlocal;

+ 20 - 5
src/controllers/Telefonia.Controller.js

@@ -1,6 +1,7 @@
 const { BuscaFatura } = require("../Modules/saperx/circuitos");
 const IxcFactory = require("../core/ixc/Ixc.factory");
 const SaperxFactory = require("../core/saperx/Saperx.factory");
+const { Cdr } = require("../models/Cdr.model");
 const { Ramais } = require("../models/Ramais.model");
 
 module.exports = {
@@ -19,10 +20,7 @@ module.exports = {
       .withGraphFetched("plano_franquia");
 
     // Use .orWhere para adicionar as condições "like" nas colunas id, circuito e numero da tabela did
-    query
-      .joinRelated("did")
-      .whereIn("ramais.id", busca);
-      
+    query.joinRelated("did").whereIn("ramais.id", busca);
 
     // Execute a consulta e envie a resposta quando terminar
     try {
@@ -69,7 +67,7 @@ module.exports = {
     // Use .orWhere para adicionar as condições "like" nas colunas id, circuito e numero da tabela did
     query
       .joinRelated("did")
-      .orWhere("ramais.id",  busca)
+      .orWhere("ramais.id", busca)
       .orWhere("ramais.nome", busca)
       .orWhere("ramais.ramal", busca)
       .orWhere("did.numero", busca);
@@ -105,4 +103,21 @@ module.exports = {
     var dados = await BuscaFatura(id_sip, month_bill);
     res.json({ ok: "ok", dados: dados });
   },
+  Cdr: async function (req, res) {
+    const { month_bill, id_sip } = req.body;
+    var dados = Cdr.query()
+    .where("channel","like","%8009007%")
+    //.where("sentido", "S")
+    .orderBy("id", "desc")
+      .limit(100)
+      .then((cdr) => {
+        cdr.map((cdrss) => {
+          
+          cdrss.src = cdrss.src.toString("utf8")
+          cdrss.log = cdrss.log.toString("utf8")
+        });
+        return res.send(cdr);
+      });
+    //res.json({ ok: "ok", dados: dados });
+  },
 };

+ 37 - 0
src/models/Cdr.model.js

@@ -0,0 +1,37 @@
+const {knex} = require('../config/db.config');
+
+
+const { Model } = require('objection');
+Model.knex(knex);
+
+
+const unique = require("objection-unique")({
+  fields: ["id"],
+  identifiers: ["id"],
+});
+
+class Cdr extends unique(Model) {
+  static get tableName() {
+    return "cdr";
+  }
+
+  static get idColumn() {
+    return "";
+  }
+
+  /*static get relationMappings() {
+    const { Ramais } = require("./Ramais.model");
+    return {
+      ramal: {
+        relation: Model.HasOneRelation,
+        modelClass: Ramais,
+        join: {
+          from: "did.id_ramal",
+          to: "ramais.id",
+        },
+      },
+    };
+  }*/
+}
+
+module.exports.Cdr = Cdr;

+ 2 - 2
src/models/Usuario.js

@@ -1,7 +1,7 @@
-const { knexlocal } = require('../config/db.config');
+const { knex } = require('../config/db.config');
 const { Model } = require('objection');
 
-Model.knex(knexlocal);
+Model.knex(knex);
 const unique = require('objection-unique')({
     fields: ['Login'],
     identifiers: ['Id']

+ 1 - 0
src/routes/Telefonia.Rotas.js

@@ -9,5 +9,6 @@ router.post("/busca", verifyJWT, controller.BuscaCircuitos);
 router.post("/get", verifyJWT, controller.VerCircuitos);
 router.get("/atualiza", verifyJWT, controller.Token);
 router.post("/fatura", verifyJWT, controller.Fatura);
+router.post("/cdr", controller.Cdr);
 
 module.exports = router;