feat: cashbox history tab

feat: add information fields to cashbox_batches table
This commit is contained in:
Sérgio Salgado 2021-04-12 01:53:11 +01:00 committed by Josh Harvey
parent 642016efeb
commit 21708aa75c
8 changed files with 267 additions and 13 deletions

View file

@ -1,4 +1,5 @@
const db = require('./db')
const _ = require('lodash/fp')
function createCashboxBatch (rec) {
const sql = 'INSERT INTO cashbox_batches (device_id, created) VALUES ($1, now()) RETURNING *'
@ -15,4 +16,23 @@ function createCashboxBatch (rec) {
})
}
module.exports = { createCashboxBatch }
function getBatches () {
const sql = `SELECT cb.id, cb.device_id, cb.created, cb.operation_type, cb.bill_count_override, cb.performed_by,
json_agg(b.*) AS bills FROM cashbox_batches cb LEFT JOIN bills b ON cb.id=b.cashbox_batch_id GROUP BY cb.id`
return db.any(sql).then(res => _.map(it => ({
id: it.id,
deviceId: it.device_id,
created: it.created,
operationType: it.operation_type,
billCountOverride: it.bill_count_override,
performedBy: it.performed_by,
bills: it.bills
}), res))
}
function getBillsByBatchId (id) {
const sql = `SELECT * FROM bills WHERE cashbox_batch_id=$1`
return db.any(sql, [id])
}
module.exports = { createCashboxBatch, getBatches, getBillsByBatchId }

View file

@ -0,0 +1,9 @@
const cashbox = require('../../../cashbox-batches')
const resolvers = {
Query: {
cashboxBatches: () => cashbox.getBatches()
}
}
module.exports = resolvers

View file

@ -2,6 +2,7 @@ const { mergeResolvers } = require('@graphql-tools/merge')
const bill = require('./bill.resolver')
const blacklist = require('./blacklist.resolver')
const cashbox = require('./cashbox.resolver')
const config = require('./config.resolver')
const currency = require('./currency.resolver')
const customer = require('./customer.resolver')
@ -22,6 +23,7 @@ const version = require('./version.resolver')
const resolvers = [
bill,
blacklist,
cashbox,
config,
currency,
customer,

View file

@ -0,0 +1,19 @@
const { gql } = require('apollo-server-express')
const typeDef = gql`
type CashboxBatch {
id: ID
deviceId: ID
created: Date
operationType: String
customBillCount: Int
performedBy: String
bills: [Bill]
}
type Query {
cashboxBatches: [CashboxBatch]
}
`
module.exports = typeDef

View file

@ -2,6 +2,7 @@ const { mergeTypeDefs } = require('@graphql-tools/merge')
const bill = require('./bill.type')
const blacklist = require('./blacklist.type')
const cashbox = require('./cashbox.type')
const config = require('./config.type')
const currency = require('./currency.type')
const customer = require('./customer.type')
@ -22,6 +23,7 @@ const version = require('./version.type')
const types = [
bill,
blacklist,
cashbox,
config,
currency,
customer,