Skip to content

Commit 71128c8

Browse files
czmjmanelcecs
authored andcommitted
Add search flows query
1 parent 6969f0d commit 71128c8

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/domain-services/flow/flow-service.ts

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ import { Service } from 'typedi';
66

77
@Service()
88
export class FlowService {
9+
async search(
10+
models: Database,
11+
params: {
12+
limit?: number;
13+
offset?: number;
14+
}
15+
): Promise<InstanceDataOfModel<Database['flow']>[]> {
16+
const { limit, offset } = params;
17+
return await models.flow.find({
18+
limit: limit || 100,
19+
offset: offset || 0,
20+
});
21+
}
22+
923
async findLatestVersionById(
1024
models: Database,
1125
id: number

src/domain-services/flow/graphql/resolver.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
import { groupBy } from 'lodash';
2-
import { Arg, Ctx, FieldResolver, Query, Resolver, Root } from 'type-graphql';
2+
import {
3+
Arg,
4+
Args,
5+
ArgsType,
6+
Ctx,
7+
Field,
8+
FieldResolver,
9+
Query,
10+
Resolver,
11+
Root,
12+
} from 'type-graphql';
313
import { Service } from 'typedi';
414
import Context from '../../Context';
515
import { FlowObjectService } from '../../flow-object/flow-object-service';
616
import { FlowService } from '../flow-service';
717
import { Flow } from './types';
818

19+
@ArgsType()
20+
class SearchFlowsArgs {
21+
@Field()
22+
limit?: number;
23+
24+
@Field()
25+
offset?: number;
26+
}
27+
928
@Service()
1029
@Resolver(Flow)
1130
export default class FlowResolver {
@@ -14,6 +33,11 @@ export default class FlowResolver {
1433
private flowObjectService: FlowObjectService
1534
) {}
1635

36+
@Query(() => [Flow])
37+
async searchFlow(@Args() params: SearchFlowsArgs, @Ctx() context: Context) {
38+
return await this.flowService.search(context.models, params);
39+
}
40+
1741
@Query(() => Flow)
1842
async flow(@Arg('id') id: number, @Ctx() context: Context) {
1943
return await this.flowService.findLatestVersionById(context.models, id);

0 commit comments

Comments
 (0)