feat: add missing types and resolvers

This commit is contained in:
Sérgio Salgado 2021-03-16 20:42:03 +00:00 committed by Josh Harvey
parent b0417f8375
commit de98ed4c2c
25 changed files with 127 additions and 12 deletions

View file

@ -12,7 +12,7 @@ const { ApolloServer, AuthenticationError } = require('apollo-server-express')
const _ = require('lodash/fp')
const { typeDefs, resolvers } = require('./graphql/schema')
const login = require('./modules/login')
const login = require('./services/login')
const register = require('./routes/authentication')
const options = require('../options')

View file

@ -0,0 +1,9 @@
const bills = require('../../services/bills')
const resolvers = {
Query: {
bills: () => bills.getBills()
}
}
module.exports = resolvers

View file

@ -1,4 +1,4 @@
const funding = require('../../modules/funding')
const funding = require('../../services/funding')
const resolvers = {
Query: {

View file

@ -1,5 +1,6 @@
const { mergeResolvers } = require('@graphql-tools/merge')
const bill = require('./bill.resolver')
const blacklist = require('./blacklist.resolver')
const config = require('./config.resolver')
const currency = require('./currency.resolver')
@ -7,8 +8,10 @@ const customer = require('./customer.resolver')
const funding = require('./funding.resolver')
const log = require('./log.resolver')
const machine = require('./machine.resolver')
const notification = require('./notification.resolver')
const pairing = require('./pairing.resolver')
const promo = require('./promo.resolver')
const rates = require('./rates.resolver')
const scalar = require('./scalar.resolver')
const settings = require('./settings.resolver')
const status = require('./status.resolver')
@ -16,6 +19,7 @@ const transaction = require('./transaction.resolver')
const version = require('./version.resolver')
const resolvers = [
bill,
blacklist,
config,
currency,
@ -23,8 +27,10 @@ const resolvers = [
funding,
log,
machine,
notification,
pairing,
promo,
rates,
scalar,
settings,
status,

View file

@ -1,7 +1,7 @@
const { parseAsync } = require('json2csv')
const logs = require('../../../logs')
const serverLogs = require('../../modules/server-logs')
const serverLogs = require('../../services/server-logs')
const resolvers = {
Query: {

View file

@ -1,6 +1,6 @@
const DataLoader = require('dataloader')
const { machineAction } = require('../../modules/machines')
const { machineAction } = require('../../services/machines')
const machineLoader = require('../../../machine-loader')
const machineEventsByIdBatch = require('../../../postgresql_interface').machineEventsByIdBatch

View file

@ -0,0 +1,15 @@
const notifierQueries = require('../../../notifier/queries')
const resolvers = {
Query: {
notifications: () => notifierQueries.getNotifications(),
hasUnreadNotifications: () => notifierQueries.hasUnreadNotifications(),
alerts: () => notifierQueries.getAlerts()
},
Mutation: {
toggleClearNotification: (...[, { id, read }]) => notifierQueries.setRead(id, read),
clearAllNotifications: () => notifierQueries.markAllAsRead()
}
}
module.exports = resolvers

View file

@ -1,4 +1,4 @@
const pairing = require('../../modules/pairing')
const pairing = require('../../services/pairing')
const resolvers = {
Mutation: {

View file

@ -0,0 +1,21 @@
const settingsLoader = require('../../../new-settings-loader')
const forex = require('../../../forex')
const plugins = require('../../../plugins')
const resolvers = {
Query: {
cryptoRates: () =>
settingsLoader.loadLatest().then(settings => {
const pi = plugins(settings)
return pi.getRawRates().then(r => {
return {
withCommissions: pi.buildRates(r),
withoutCommissions: pi.buildRatesNoCommission(r)
}
})
}),
fiatRates: () => forex.getFiatRates()
}
}
module.exports = resolvers

View file

@ -7,7 +7,7 @@ const notify = () => got.post('http://localhost:3030/dbChange')
const resolvers = {
Query: {
accounts: () => settingsLoader.loadAccounts(),
accounts: () => settingsLoader.showAccounts(),
config: () => settingsLoader.loadLatestConfigOrNone()
},
Mutation: {

View file

@ -1,4 +1,4 @@
const supervisor = require('../../modules/supervisor')
const supervisor = require('../../services/supervisor')
const resolvers = {
Query: {

View file

@ -1,7 +1,7 @@
const DataLoader = require('dataloader')
const { parseAsync } = require('json2csv')
const transactions = require('../../modules/transactions')
const transactions = require('../../services/transactions')
const anonymous = require('../../../constants').anonymousCustomer
const transactionsLoader = new DataLoader(ids => transactions.getCustomerTransactionsBatch(ids))
@ -14,8 +14,8 @@ const resolvers = {
isAnonymous: parent => (parent.customerId === anonymous.uuid)
},
Query: {
transactions: (...[, { from, until, limit, offset }]) =>
transactions.batch(from, until, limit, offset),
transactions: (...[, { from, until, limit, offset, deviceId }]) =>
transactions.batch(from, until, limit, offset, deviceId),
transactionsCsv: (...[, { from, until, limit, offset }]) =>
transactions.batch(from, until, limit, offset).then(parseAsync)
}

View file

@ -0,0 +1,16 @@
const { gql } = require('apollo-server-express')
const typeDef = gql`
type Bill {
fiat: Int
deviceId: ID
created: Date
cashbox: Int
}
type Query {
bills: [Bill]
}
`
module.exports = typeDef

View file

@ -1,5 +1,6 @@
const { mergeTypeDefs } = require('@graphql-tools/merge')
const bill = require('./bill.type')
const blacklist = require('./blacklist.type')
const config = require('./config.type')
const currency = require('./currency.type')
@ -7,8 +8,10 @@ const customer = require('./customer.type')
const funding = require('./funding.type')
const log = require('./log.type')
const machine = require('./machine.type')
const notification = require('./notification.type')
const pairing = require('./pairing.type')
const promo = require('./promo.type')
const rates = require('./rates.type')
const scalar = require('./scalar.type')
const settings = require('./settings.type')
const status = require('./status.type')
@ -16,6 +19,7 @@ const transaction = require('./transaction.type')
const version = require('./version.type')
const types = [
bill,
blacklist,
config,
currency,
@ -23,8 +27,10 @@ const types = [
funding,
log,
machine,
notification,
pairing,
promo,
rates,
scalar,
settings,
status,

View file

@ -0,0 +1,26 @@
const { gql } = require('apollo-server-express')
const typeDef = gql`
type Notification {
id: ID!
type: String
detail: JSON
message: String
created: Date
read: Boolean
valid: Boolean
}
type Query {
notifications: [Notification]
alerts: [Notification]
hasUnreadNotifications: Boolean
}
type Mutation {
toggleClearNotification(id: ID!, read: Boolean!): Notification
clearAllNotifications: Notification
}
`
module.exports = typeDef

View file

@ -0,0 +1,16 @@
const { gql } = require('apollo-server-express')
const typeDef = gql`
type Rate {
code: String
name: String
rate: Float
}
type Query {
cryptoRates: JSONObject
fiatRates: [Rate]
}
`
module.exports = typeDef

View file

@ -1,7 +1,7 @@
const express = require('express')
const router = express.Router()
const login = require('../modules/login')
const login = require('../services/login')
const options = require('../../options')
const T = require('../../time')

View file

@ -1,4 +1,4 @@
const db = require('../db')
const db = require('../../db')
// Get all bills with device id
const getBills = () => {