fix: removed unnecessary support log code from server

This commit is contained in:
Liordino Neto 2020-10-28 00:09:21 -03:00 committed by Josh Harvey
parent 1f7b517c07
commit a1cc7cad13
4 changed files with 15 additions and 77 deletions

View file

@ -7,7 +7,6 @@ const machineLoader = require('../../machine-loader')
const customers = require('../../customers') const customers = require('../../customers')
const { machineAction } = require('../machines') const { machineAction } = require('../machines')
const logs = require('../../logs') const logs = require('../../logs')
const supportLogs = require('../../support_logs')
const settingsLoader = require('../../new-settings-loader') const settingsLoader = require('../../new-settings-loader')
const serverVersion = require('../../../package.json').version const serverVersion = require('../../../package.json').version
@ -216,12 +215,6 @@ const typeDefs = gql`
config: JSONObject config: JSONObject
} }
type SupportLogsResponse {
id: ID!
timestamp: Date!
deviceId: ID
}
enum MachineAction { enum MachineAction {
rename rename
emptyCashInBills emptyCashInBills
@ -234,8 +227,6 @@ const typeDefs = gql`
type Mutation { type Mutation {
machineAction(deviceId:ID!, action: MachineAction!, cassette1: Int, cassette2: Int, newName: String): Machine machineAction(deviceId:ID!, action: MachineAction!, cassette1: Int, cassette2: Int, newName: String): Machine
machineSupportLogs(deviceId: ID!): SupportLogsResponse
serverSupportLogs: SupportLogsResponse
setCustomer(customerId: ID!, customerInput: CustomerInput): Customer setCustomer(customerId: ID!, customerInput: CustomerInput): Customer
saveConfig(config: JSONObject): JSONObject saveConfig(config: JSONObject): JSONObject
createPairingTotem(name: String!): String createPairingTotem(name: String!): String
@ -276,9 +267,7 @@ const resolvers = {
}, },
Mutation: { Mutation: {
machineAction: (...[, { deviceId, action, cassette1, cassette2, newName }]) => machineAction({ deviceId, action, cassette1, cassette2, newName }), machineAction: (...[, { deviceId, action, cassette1, cassette2, newName }]) => machineAction({ deviceId, action, cassette1, cassette2, newName }),
machineSupportLogs: (...[, { deviceId }]) => supportLogs.insert(deviceId),
createPairingTotem: (...[, { name }]) => pairing.totem(name), createPairingTotem: (...[, { name }]) => pairing.totem(name),
serverSupportLogs: () => serverLogs.insert(),
saveAccounts: (...[, { accounts }]) => settingsLoader.saveAccounts(accounts), saveAccounts: (...[, { accounts }]) => settingsLoader.saveAccounts(accounts),
setCustomer: (...[, { customerId, customerInput } ]) => customers.updateCustomer(customerId, customerInput), setCustomer: (...[, { customerId, customerInput } ]) => customers.updateCustomer(customerId, customerInput),
saveConfig: (...[, { config }]) => settingsLoader.saveConfig(config) saveConfig: (...[, { config }]) => settingsLoader.saveConfig(config)

View file

@ -14,11 +14,4 @@ function getServerLogs (from = new Date(0).toISOString(), until = new Date().toI
.then(_.map(_.mapKeys(_.camelCase))) .then(_.map(_.mapKeys(_.camelCase)))
} }
function insert () { module.exports = { getServerLogs }
const sql = `insert into server_support_logs
(id) values ($1) returning *`
return db.one(sql, [uuid.v4()])
.then(_.mapKeys(_.camelCase))
}
module.exports = { getServerLogs, insert }

View file

@ -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 }

View file

@ -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()
}