Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions __tests__/highlights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,19 @@ describe('query channelConfigurations', () => {
channel: 'career',
displayName: 'Career Growth',
mode: 'shadow',
order: 1,
},
{
channel: 'backend',
displayName: 'Backend Engineering',
mode: 'publish',
order: 2,
},
{
channel: 'disabled',
displayName: 'Disabled',
mode: 'disabled',
order: 0,
},
]);

Expand All @@ -199,6 +202,11 @@ describe('query channelConfigurations', () => {

expect(res.errors).toBeFalsy();
expect(res.data.channelConfigurations).toEqual([
{
channel: 'career',
displayName: 'Career Growth',
digest: null,
},
{
channel: 'backend',
displayName: 'Backend Engineering',
Expand All @@ -211,11 +219,6 @@ describe('query channelConfigurations', () => {
},
},
},
{
channel: 'career',
displayName: 'Career Growth',
digest: null,
},
]);
});
});
Expand Down
1 change: 1 addition & 0 deletions src/common/channelHighlight/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const getChannelHighlightDefinitions = async ({
mode: Not('disabled'),
},
order: {
order: 'ASC',
channel: 'ASC',
},
});
Expand Down
3 changes: 3 additions & 0 deletions src/entity/ChannelHighlightDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export class ChannelHighlightDefinition {
@Column({ type: 'text', default: '' })
displayName: string;

@Column({ type: 'smallint', default: 0 })
order: number;

@Column({ type: 'text', default: 'disabled' })
mode: ChannelHighlightMode;

Expand Down
34 changes: 34 additions & 0 deletions src/migration/1776108702577-ChannelHighlightDefinitionOrder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { MigrationInterface, QueryRunner } from 'typeorm';

export class ChannelHighlightDefinitionOrder1776108702577
implements MigrationInterface
{
name = 'ChannelHighlightDefinitionOrder1776108702577';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(/* sql */ `
ALTER TABLE "channel_highlight_definition"
ADD COLUMN "order" smallint NOT NULL DEFAULT 0
`);

await queryRunner.query(/* sql */ `
WITH ordered_definitions AS (
SELECT
"channel",
ROW_NUMBER() OVER (ORDER BY "channel" ASC) - 1 AS "order"
FROM "channel_highlight_definition"
)
UPDATE "channel_highlight_definition" AS definition
SET "order" = ordered_definitions."order"
FROM ordered_definitions
WHERE ordered_definitions."channel" = definition."channel"
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(/* sql */ `
ALTER TABLE "channel_highlight_definition"
DROP COLUMN "order"
`);
}
}
3 changes: 2 additions & 1 deletion src/schema/highlights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ export const resolvers: IResolvers<unknown, BaseContext> = {
.where(`"${builder.alias}"."mode" != :disabledMode`, {
disabledMode: 'disabled',
})
.orderBy(`"${builder.alias}"."channel"`, 'ASC');
.orderBy(`"${builder.alias}"."order"`, 'ASC')
.addOrderBy(`"${builder.alias}"."channel"`, 'ASC');
return builder;
},
true,
Expand Down
Loading