author BounceCode, Inc.
 *  packageDocumentation import { Resolver , Query , Mutation , Ctx , Arg } from 'type-graphql' ; import { ConfigObject } from '../objects/Config.object' ; import { ConfigWhereInput } from '../inputs/ConfigWhere.input' ; import { ConfigUniqueWhereInput } from '../inputs/ConfigUniqueWhere.input' ; import { ConfigUpsertInput } from '../inputs/ConfigUpsert.input' ; import { ConfigEntity } from '../entities/Config.entity' ; import { Context } from '../../../express' ; import { ConfigLogEntity } from '../entities/ConfigLog.entity' ; import { ConfigLogWhereInput } from '../inputs/ConfigLogWhere.input' ; import { LessThanOrEqual } from 'typeorm' ; import { ConfigLogObject } from '../objects/ConfigLog.object' ; author BounceCode, Inc.
  @ Resolver ( ) export class ConfigResolver { author BounceCode, Inc.
      @ Query ( ( ) => ConfigObject ) async config ( @ Arg ( 'where' ) where ) { return await ConfigEntity . findOne ( { id : where . id , deletedBy : null } ) ; } author BounceCode, Inc.
      @ Query ( ( ) => [ ConfigObject ] ) async configs ( @ Arg ( 'where' ) where ) { return await ConfigEntity . find ( { ... where , deletedBy : null } ) ; } author BounceCode, Inc.
      @ Query ( ( ) => [ ConfigLogObject ] ) async configLogs ( @ Arg ( 'where' ) where , @ Arg ( 'before' , { nullable : true } ) before , @ Arg ( 'take' ) take ) { return await ConfigLogEntity . find ( { where : { ... where , ... ( before ? { id : LessThanOrEqual ( before ) } : undefined ) , } , order : { id : 'DESC' } , take , } ) ; } author BounceCode, Inc.
      @ Mutation ( ( ) => ConfigObject ) async upsertConfig ( @ Arg ( 'data' ) data , @ Ctx ( ) ctx ) { let entity = await ConfigEntity . findOne ( { id : data . id } ) ; if ( ! entity ) { entity = ConfigEntity . create ( data ) ; ConfigEntity . merge ( entity , { createdBy : ctx . user . id , } ) ; } else if ( entity . deletedBy ) { ConfigEntity . merge ( entity , data , { createdBy : ctx . user . id , updatedBy : null , deletedBy : null , } ) ; } else { ConfigEntity . merge ( entity , data , { updatedBy : ctx . user . id , deletedBy : null , } ) ; } return await entity . save ( ) ; } author BounceCode, Inc.
      @ Mutation ( ( ) => Boolean ) async deleteConfig ( @ Arg ( 'where' ) where , @ Ctx ( ) ctx ) { const entity = await ConfigEntity . findOne ( { id : where . id } ) ; ConfigEntity . merge ( entity , { deletedBy : ctx . user . id } ) ; return Boolean ( await entity . save ( ) ) ; } }