diff --git a/src/domain-services/flow/flow-service.ts b/src/domain-services/flow/flow-service.ts index 47dc5539..fde57a33 100644 --- a/src/domain-services/flow/flow-service.ts +++ b/src/domain-services/flow/flow-service.ts @@ -6,6 +6,20 @@ import { Service } from 'typedi'; @Service() export class FlowService { + async search( + models: Database, + params: { + limit?: number; + offset?: number; + } + ): Promise[]> { + const { limit, offset } = params; + return await models.flow.find({ + limit: limit || 100, + offset: offset || 0, + }); + } + async findLatestVersionById( models: Database, id: number diff --git a/src/domain-services/flow/graphql/resolver.ts b/src/domain-services/flow/graphql/resolver.ts index 311068e9..03846b3e 100644 --- a/src/domain-services/flow/graphql/resolver.ts +++ b/src/domain-services/flow/graphql/resolver.ts @@ -1,11 +1,30 @@ import { groupBy } from 'lodash'; -import { Arg, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql'; +import { + Arg, + Args, + ArgsType, + Ctx, + Field, + FieldResolver, + Query, + Resolver, + Root, +} from 'type-graphql'; import { Service } from 'typedi'; import Context from '../../Context'; import { FlowObjectService } from '../../flow-object/flow-object-service'; import { FlowService } from '../flow-service'; import { Flow } from './types'; +@ArgsType() +class SearchFlowsArgs { + @Field() + limit?: number; + + @Field() + offset?: number; +} + @Service() @Resolver(Flow) export default class FlowResolver { @@ -14,6 +33,11 @@ export default class FlowResolver { private flowObjectService: FlowObjectService ) {} + @Query(() => [Flow]) + async searchFlow(@Args() params: SearchFlowsArgs, @Ctx() context: Context) { + return await this.flowService.search(context.models, params); + } + @Query(() => Flow) async flow(@Arg('id') id: number, @Ctx() context: Context) { return await this.flowService.findLatestVersionById(context.models, id);