Skip to content

Commit

Permalink
feat(245): add image comments index and image comments filter
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseLeung97 committed Sep 17, 2024
1 parent 02955aa commit 2905106
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/@types/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ export type Filters = {
createdEnd?: Maybe<Scalars['Date']['output']>;
createdStart?: Maybe<Scalars['Date']['output']>;
custom?: Maybe<Scalars['String']['output']>;
comments?: Maybe<Scalars['String']['output']>;
deployments?: Maybe<Array<Scalars['String']['output']>>;
labels?: Maybe<Array<Scalars['String']['output']>>;
notReviewed?: Maybe<Scalars['Boolean']['output']>;
Expand All @@ -375,6 +376,7 @@ export type FiltersInput = {
createdEnd?: InputMaybe<Scalars['Date']['input']>;
createdStart?: InputMaybe<Scalars['Date']['input']>;
custom?: InputMaybe<Scalars['String']['input']>;
comments?: InputMaybe<Scalars['String']['input']>;
deployments?: InputMaybe<Array<Scalars['String']['input']>>;
labels?: InputMaybe<Array<Scalars['String']['input']>>;
reviewed?: InputMaybe<Scalars['Boolean']['input']>;
Expand Down
2 changes: 1 addition & 1 deletion src/api/db/models/Image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class ImageModel {
hasNext: false,
} as AggregationOutput<ImageSchema>;
}
return await MongoPaging.aggregate(Image.collection, {
return MongoPaging.aggregate(Image.collection, {
aggregation: buildPipeline(input.filters, context.user['curr_project']!),
limit: input.limit,
paginatedField: input.paginatedField,
Expand Down
12 changes: 12 additions & 0 deletions src/api/db/models/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,22 @@ export function buildPipeline(
labels,
reviewed,
custom,
comments
}: gql.Filters,
projectId?: string,
): PipelineStage[] {
const pipeline: PipelineStage[] = [];

if (comments) {
pipeline.push({
$match: {
$text: {
$search: comments
}
}
})
}

// match current project
if (projectId) {
pipeline.push({ $match: { projectId: projectId } });
Expand Down Expand Up @@ -200,6 +211,7 @@ export function buildPipeline(
pipeline.push({ $match: isFilterValid(custom) });
}


console.log('utils.buildPipeline() - pipeline: ', JSON.stringify(pipeline));
return pipeline;
}
Expand Down
2 changes: 2 additions & 0 deletions src/api/db/schemas/Image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const ImageSchema = new Schema({

ImageSchema.plugin(MongoPaging.mongoosePlugin);

ImageSchema.index({ 'comments.comment': 'text' });

export default mongoose.model('Image', ImageSchema);

export type ImageSchema = mongoose.InferSchemaType<typeof ImageSchema>;
Expand Down
1 change: 1 addition & 0 deletions src/api/type-defs/inputs/QueryImagesInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default /* GraphQL */ `
labels: [String!]
reviewed: Boolean
custom: String
comments: String
}
input QueryImagesInput {
Expand Down
1 change: 1 addition & 0 deletions src/api/type-defs/objects/Filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export default /* GraphQL */ `
reviewed: Boolean
notReviewed: Boolean
custom: String
comments: String
}
`;

0 comments on commit 2905106

Please sign in to comment.