Skip to content

Commit

Permalink
Add search flows query
Browse files Browse the repository at this point in the history
  • Loading branch information
czmj authored and manelcecs committed Nov 16, 2023
1 parent 6969f0d commit 71128c8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/domain-services/flow/flow-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ import { Service } from 'typedi';

@Service()
export class FlowService {
async search(
models: Database,
params: {
limit?: number;
offset?: number;
}
): Promise<InstanceDataOfModel<Database['flow']>[]> {
const { limit, offset } = params;
return await models.flow.find({
limit: limit || 100,
offset: offset || 0,
});
}

async findLatestVersionById(
models: Database,
id: number
Expand Down
26 changes: 25 additions & 1 deletion src/domain-services/flow/graphql/resolver.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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);
Expand Down

0 comments on commit 71128c8

Please sign in to comment.