Skip to content
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: sort flows by enabled first #4003

Merged
merged 1 commit into from Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/server/api/src/app/flows/flow/flow.service.ts
Expand Up @@ -99,7 +99,7 @@ export const flowService = {
}

const paginationResult = await paginator.paginate(
flowRepo().createQueryBuilder('flow').where(queryWhere),
flowRepo().createQueryBuilder('flow').where(queryWhere).addOrderBy('flow.status', 'DESC'),
)

const populatedFlowPromises = paginationResult.data.map(async (flow) => {
Expand Down
12 changes: 6 additions & 6 deletions packages/server/api/src/app/helper/pagination/paginator.ts
Expand Up @@ -2,7 +2,6 @@ import {
Brackets,
EntitySchema,
ObjectLiteral,
OrderByCondition,
SelectQueryBuilder,
WhereExpressionBuilder,
} from 'typeorm'
Expand Down Expand Up @@ -43,7 +42,7 @@ export default class Paginator<Entity extends ObjectLiteral> {

private order: Order = Order.DESC

public constructor(private readonly entity: EntitySchema) {}
public constructor(private readonly entity: EntitySchema) { }

public setAlias(alias: string): void {
this.alias = alias
Expand Down Expand Up @@ -121,8 +120,9 @@ export default class Paginator<Entity extends ObjectLiteral> {
}

clonedBuilder.take(this.limit + 1)
clonedBuilder.orderBy(this.buildOrder())

for (const [key, value] of Object.entries(this.buildOrder())) {
clonedBuilder.addOrderBy(key, value)
}
return clonedBuilder
}

Expand Down Expand Up @@ -159,14 +159,14 @@ export default class Paginator<Entity extends ObjectLiteral> {
return '='
}

private buildOrder(): OrderByCondition {
private buildOrder(): Record<string, Order> {
let { order } = this

if (!this.hasAfterCursor() && this.hasBeforeCursor()) {
order = this.flipOrder(order)
}

const orderByCondition: OrderByCondition = {}
const orderByCondition: Record<string, Order> = {}
orderByCondition[`${this.alias}.${PAGINATION_KEY}`] = order

return orderByCondition
Expand Down

This file was deleted.