From a1cc7cad13558866d32b72c264e0feeb13178e51 Mon Sep 17 00:00:00 2001 From: Liordino Neto Date: Wed, 28 Oct 2020 00:09:21 -0300 Subject: [PATCH] fix: removed unnecessary support log code from server --- lib/new-admin/graphql/schema.js | 11 ---- lib/new-admin/server-logs.js | 9 +-- lib/support_logs.js | 58 ------------------- .../1603853985238-remove-support-log.js | 14 +++++ 4 files changed, 15 insertions(+), 77 deletions(-) delete mode 100644 lib/support_logs.js create mode 100644 migrations/1603853985238-remove-support-log.js diff --git a/lib/new-admin/graphql/schema.js b/lib/new-admin/graphql/schema.js index 0af308e9..a98276c8 100644 --- a/lib/new-admin/graphql/schema.js +++ b/lib/new-admin/graphql/schema.js @@ -7,7 +7,6 @@ const machineLoader = require('../../machine-loader') const customers = require('../../customers') const { machineAction } = require('../machines') const logs = require('../../logs') -const supportLogs = require('../../support_logs') const settingsLoader = require('../../new-settings-loader') const serverVersion = require('../../../package.json').version @@ -216,12 +215,6 @@ const typeDefs = gql` config: JSONObject } - type SupportLogsResponse { - id: ID! - timestamp: Date! - deviceId: ID - } - enum MachineAction { rename emptyCashInBills @@ -234,8 +227,6 @@ const typeDefs = gql` type Mutation { machineAction(deviceId:ID!, action: MachineAction!, cassette1: Int, cassette2: Int, newName: String): Machine - machineSupportLogs(deviceId: ID!): SupportLogsResponse - serverSupportLogs: SupportLogsResponse setCustomer(customerId: ID!, customerInput: CustomerInput): Customer saveConfig(config: JSONObject): JSONObject createPairingTotem(name: String!): String @@ -276,9 +267,7 @@ const resolvers = { }, Mutation: { machineAction: (...[, { deviceId, action, cassette1, cassette2, newName }]) => machineAction({ deviceId, action, cassette1, cassette2, newName }), - machineSupportLogs: (...[, { deviceId }]) => supportLogs.insert(deviceId), createPairingTotem: (...[, { name }]) => pairing.totem(name), - serverSupportLogs: () => serverLogs.insert(), saveAccounts: (...[, { accounts }]) => settingsLoader.saveAccounts(accounts), setCustomer: (...[, { customerId, customerInput } ]) => customers.updateCustomer(customerId, customerInput), saveConfig: (...[, { config }]) => settingsLoader.saveConfig(config) diff --git a/lib/new-admin/server-logs.js b/lib/new-admin/server-logs.js index 1a8cf149..3717551a 100644 --- a/lib/new-admin/server-logs.js +++ b/lib/new-admin/server-logs.js @@ -14,11 +14,4 @@ function getServerLogs (from = new Date(0).toISOString(), until = new Date().toI .then(_.map(_.mapKeys(_.camelCase))) } -function insert () { - const sql = `insert into server_support_logs - (id) values ($1) returning *` - return db.one(sql, [uuid.v4()]) - .then(_.mapKeys(_.camelCase)) -} - -module.exports = { getServerLogs, insert } +module.exports = { getServerLogs } diff --git a/lib/support_logs.js b/lib/support_logs.js deleted file mode 100644 index 3ba128a5..00000000 --- a/lib/support_logs.js +++ /dev/null @@ -1,58 +0,0 @@ -const _ = require('lodash/fp') -const uuid = require('uuid') - -const db = require('./db') - -/** - * Get single support_log by id - * - * @name get - * @function - * - * @param {string} phone Customer's phone number - * - * @returns {object} Customer - */ -function get (id) { - if (!id || _.isEmpty(id)) return Promise.resolve() - const sql = 'select * from support_logs where id=$1' - return db.oneOrNone(sql, [id]) - .then(_.mapKeys(_.camelCase)) -} -/** - * Insert a single support_logs row in db - * - * @name insert - * @function - * @async - * - * @param {string} deviceId Machine's id for the log - * - * @returns {object} Newly created support_log - */ -function insert (deviceId) { - const sql = `insert into support_logs - (id, device_id) values ($1, $2) returning *` - return db.one(sql, [uuid.v4(), deviceId]) - .then(_.mapKeys(_.camelCase)) -} - -/** - * Get the latest 48-hour logs snapshots - * - * @name batch - * @function - * @async - * - * @returns {array} List of all support_logs rows - */ -function batch () { - const sql = `select s.id, s.device_id, s.timestamp, devices.name from support_logs as s - inner join devices on s.device_id = devices.device_id - where timestamp > (now() - interval '1 week') - order by s.timestamp desc` - return db.any(sql) - .then(_.map(_.mapKeys(_.camelCase))) -} - -module.exports = { get, insert, batch } diff --git a/migrations/1603853985238-remove-support-log.js b/migrations/1603853985238-remove-support-log.js new file mode 100644 index 00000000..c246f7c8 --- /dev/null +++ b/migrations/1603853985238-remove-support-log.js @@ -0,0 +1,14 @@ +var db = require('./db') + +exports.up = function (next) { + var sql = [ + 'drop table if exists support_logs', + 'drop table if exists server_support_logs' + ] + + db.multi(sql, next) +} + +exports.down = function (next) { + next() +}