-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(api): search workflows by name or trigger identifier #5268
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
LetItRock marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ApiPropertyOptional } from '@nestjs/swagger'; | ||
import { IsOptional, IsString } from 'class-validator'; | ||
|
||
import { Constructor } from '../types'; | ||
import { IPagination, PaginationRequestDto } from './pagination-request'; | ||
|
||
export interface IPaginationWithFilters extends IPagination { | ||
query?: string; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export function PaginationWithFiltersRequestDto({ | ||
defaultLimit = 10, | ||
maxLimit = 100, | ||
queryDescription, | ||
}: { | ||
defaultLimit: number; | ||
maxLimit: number; | ||
queryDescription: string; | ||
}): Constructor<IPaginationWithFilters> { | ||
class PaginationWithFiltersRequest extends PaginationRequestDto(defaultLimit, maxLimit) { | ||
@ApiPropertyOptional({ | ||
type: String, | ||
required: false, | ||
description: `A query string to filter the results. ${queryDescription}`, | ||
}) | ||
@IsOptional() | ||
@IsString() | ||
query?: string; | ||
} | ||
|
||
return PaginationWithFiltersRequest; | ||
} | ||
Comment on lines
+12
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extended the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type Constructor<I> = new (...args: any[]) => I; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
import { PaginationRequestDto } from '../../shared/dtos/pagination-request'; | ||
import { PaginationWithFiltersRequestDto } from '../../shared/dtos/pagination-with-filters-request'; | ||
|
||
export class WorkflowsRequestDto extends PaginationRequestDto(10, 100) {} | ||
export class WorkflowsRequestDto extends PaginationWithFiltersRequestDto({ | ||
defaultLimit: 10, | ||
maxLimit: 100, | ||
queryDescription: 'It allows filtering based on either the name or trigger identifier of the workflow items.', | ||
}) {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,15 +165,31 @@ export class NotificationTemplateRepository extends BaseRepository< | |
return { totalCount: totalItemsCount, data: this.mapEntities(items) }; | ||
} | ||
|
||
async getList(organizationId: string, environmentId: string, skip = 0, limit = 10) { | ||
const totalItemsCount = await this.count({ _environmentId: environmentId }); | ||
async getList(organizationId: string, environmentId: string, skip = 0, limit = 10, query?: string) { | ||
let searchQuery: FilterQuery<NotificationTemplateDBModel> = {}; | ||
if (query) { | ||
searchQuery = { | ||
$or: [ | ||
{ name: { $regex: regExpEscape(query), $options: 'i' } }, | ||
{ 'triggers.identifier': { $regex: regExpEscape(query), $options: 'i' } }, | ||
], | ||
Comment on lines
+172
to
+175
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. allow searching by the name or trigger identifier case-insensitive There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, i missed this part of the search implementation.
This is because if we have only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I do understand what you mean. I will add it, thanks! 🙌 I see that we also have Also, in Atlas There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only places i found that depend on
Thats right we could extend |
||
}; | ||
} | ||
|
||
const totalItemsCount = await this.count({ | ||
_environmentId: environmentId, | ||
...searchQuery, | ||
}); | ||
|
||
const requestQuery: NotificationTemplateQuery = { | ||
_environmentId: environmentId, | ||
_organizationId: organizationId, | ||
}; | ||
|
||
const items = await this.MongooseModel.find(requestQuery) | ||
const items = await this.MongooseModel.find({ | ||
...requestQuery, | ||
...searchQuery, | ||
}) | ||
.sort({ createdAt: -1 }) | ||
.skip(skip) | ||
.limit(limit) | ||
|
@@ -218,3 +234,7 @@ export class NotificationTemplateRepository extends BaseRepository< | |
return process.env.BLUEPRINT_CREATOR; | ||
} | ||
} | ||
|
||
function regExpEscape(literalString: string): string { | ||
return literalString.replace(/[-[\]{}()*+!<=:?./\\^$|#\s,]/g, '\\$&'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to a shared type