Extend fbByOwner Query to return all FBs
This commit is contained in:
1 parent
c20ac392a9
commit
79f88dcf75
2 files changed
+76
-1
No files matched your search
@@ -3,6 +3,8 @@ import { logger } from '../../../logger'
|
||||
import FB_FRAGMENT from '../../fragments/FBFragment'
|
||||
import FB_TEAM_FRAGMENT from '../../fragments/FBTeamFragment'
|
||||
|
||||
import { isDefined, isNull } from '../../../utils'
|
||||
|
||||
export const fbByFbId = async (parent, { fbId }, ctx, info) => {
|
||||
logger.info(`fbByFbId: ${fbId}`)
|
||||
let FB = await ctx.db.query.financialBeings({where: {id: fbId}}, FB_FRAGMENT)
|
||||
@@ -24,5 +26,9 @@ export const fbByOwner = async (parent, { fbId, fbSlug }, ctx, info) => {
|
||||
throw new AuthenticationError()
|
||||
return
|
||||
}
|
||||
return ctx.db.query.financialBeingsesConnection({where: {AND:[{team:{members_some:{member:{authId: authId}}}},{OR:[{slug:fbSlug},{id:fbId}]}]}}, FB_TEAM_FRAGMENT)
|
||||
if ((isDefined(fbId) && !isNull(fbId)) || (isDefined(fbSlug) && !isNull(fbSlug))){
|
||||
return ctx.db.query.financialBeingsesConnection({where: {AND:[{team:{members_some:{member:{authId: authId}}}},{OR:[{slug:fbSlug},{id:fbId}]}]}}, FB_TEAM_FRAGMENT)
|
||||
} else {
|
||||
return ctx.db.query.financialBeingsesConnection({where: {team:{members_some:{member:{authId: authId}}}}}, FB_TEAM_FRAGMENT)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
export const toLocalTime = (epoch) => {
|
||||
const localDate = new Date(0);
|
||||
localDate.setUTCSeconds(epoch);
|
||||
const options = { year: 'numeric', month: 'long', day: '2-digit' };
|
||||
return (
|
||||
`${localDate.toLocaleDateString(options)
|
||||
} at ${
|
||||
localDate.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' })}`
|
||||
);
|
||||
};
|
||||
|
||||
export const temporaryFunction = input => input;
|
||||
|
||||
export function isDefined (d) {
|
||||
return d !== null && typeof d !== 'undefined'
|
||||
}
|
||||
|
||||
export function isNull (d) {
|
||||
return d === null
|
||||
}
|
||||
|
||||
export const isArray = Array.isArray
|
||||
|
||||
export function isObject (d) {
|
||||
return isDefined(d) && typeof d === 'object' && !Array.isArray(d)
|
||||
}
|
||||
|
||||
export function isEmpty (obj) {
|
||||
for (var key in obj) {
|
||||
if (obj.hasOwnProperty(key)) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
export function validObject (object, ...keys) {
|
||||
return keys.reduce((a, b) => (a || { })[b], object) !== undefined
|
||||
}
|
||||
|
||||
export function mergeDeep (target, ...sources) {
|
||||
if (!sources.length) return target
|
||||
const source = sources.shift()
|
||||
|
||||
if (isObject(target) && isObject(source)) {
|
||||
for (const key in source) {
|
||||
if (isObject(source[key])) {
|
||||
if (!target[key]) Object.assign(target, { [key]: {} })
|
||||
mergeDeep(target[key], source[key])
|
||||
} else {
|
||||
Object.assign(target, { [key]: source[key] })
|
||||
}
|
||||
}
|
||||
}
|
||||
return mergeDeep(target, ...sources)
|
||||
}
|
||||
|
||||
export function slugify (string) {
|
||||
const a = 'àáäâãåèéëêìíïîòóöôùúüûñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;'
|
||||
const b = 'aaaaaaeeeeiiiioooouuuuncsyoarsnpwgnmuxzh------'
|
||||
const p = new RegExp(a.split('').join('|'), 'g')
|
||||
|
||||
return string.toString().toLowerCase()
|
||||
.replace(/\s+/g, '-') // Replace spaces with -
|
||||
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters
|
||||
.replace(/&/g, '-and-') // Replace & with 'and'
|
||||
.replace(/[^\w-]+/g, '') // Remove all non-word characters
|
||||
.replace(/--+/g, '-') // Replace multiple - with single -
|
||||
.replace(/^-+/, '') // Trim - from start of text
|
||||
.replace(/-+$/, '') // Trim - from end of text
|
||||
}
|
||||
Reference in new issue
Block a user