Skip to content

Commit 7b4aa98

Browse files
authored
Add explicit ordering for highlight channels (#3792)
1 parent 3cc9e07 commit 7b4aa98

5 files changed

Lines changed: 48 additions & 6 deletions

File tree

__tests__/highlights.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,19 @@ describe('query channelConfigurations', () => {
171171
channel: 'career',
172172
displayName: 'Career Growth',
173173
mode: 'shadow',
174+
order: 1,
174175
},
175176
{
176177
channel: 'backend',
177178
displayName: 'Backend Engineering',
178179
mode: 'publish',
180+
order: 2,
179181
},
180182
{
181183
channel: 'disabled',
182184
displayName: 'Disabled',
183185
mode: 'disabled',
186+
order: 0,
184187
},
185188
]);
186189

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

200203
expect(res.errors).toBeFalsy();
201204
expect(res.data.channelConfigurations).toEqual([
205+
{
206+
channel: 'career',
207+
displayName: 'Career Growth',
208+
digest: null,
209+
},
202210
{
203211
channel: 'backend',
204212
displayName: 'Backend Engineering',
@@ -211,11 +219,6 @@ describe('query channelConfigurations', () => {
211219
},
212220
},
213221
},
214-
{
215-
channel: 'career',
216-
displayName: 'Career Growth',
217-
digest: null,
218-
},
219222
]);
220223
});
221224
});

src/common/channelHighlight/definitions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const getChannelHighlightDefinitions = async ({
1212
mode: Not('disabled'),
1313
},
1414
order: {
15+
order: 'ASC',
1516
channel: 'ASC',
1617
},
1718
});

src/entity/ChannelHighlightDefinition.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export class ChannelHighlightDefinition {
1515
@Column({ type: 'text', default: '' })
1616
displayName: string;
1717

18+
@Column({ type: 'smallint', default: 0 })
19+
order: number;
20+
1821
@Column({ type: 'text', default: 'disabled' })
1922
mode: ChannelHighlightMode;
2023

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { MigrationInterface, QueryRunner } from 'typeorm';
2+
3+
export class ChannelHighlightDefinitionOrder1776108702577
4+
implements MigrationInterface
5+
{
6+
name = 'ChannelHighlightDefinitionOrder1776108702577';
7+
8+
public async up(queryRunner: QueryRunner): Promise<void> {
9+
await queryRunner.query(/* sql */ `
10+
ALTER TABLE "channel_highlight_definition"
11+
ADD COLUMN "order" smallint NOT NULL DEFAULT 0
12+
`);
13+
14+
await queryRunner.query(/* sql */ `
15+
WITH ordered_definitions AS (
16+
SELECT
17+
"channel",
18+
ROW_NUMBER() OVER (ORDER BY "channel" ASC) - 1 AS "order"
19+
FROM "channel_highlight_definition"
20+
)
21+
UPDATE "channel_highlight_definition" AS definition
22+
SET "order" = ordered_definitions."order"
23+
FROM ordered_definitions
24+
WHERE ordered_definitions."channel" = definition."channel"
25+
`);
26+
}
27+
28+
public async down(queryRunner: QueryRunner): Promise<void> {
29+
await queryRunner.query(/* sql */ `
30+
ALTER TABLE "channel_highlight_definition"
31+
DROP COLUMN "order"
32+
`);
33+
}
34+
}

src/schema/highlights.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ export const resolvers: IResolvers<unknown, BaseContext> = {
124124
.where(`"${builder.alias}"."mode" != :disabledMode`, {
125125
disabledMode: 'disabled',
126126
})
127-
.orderBy(`"${builder.alias}"."channel"`, 'ASC');
127+
.orderBy(`"${builder.alias}"."order"`, 'ASC')
128+
.addOrderBy(`"${builder.alias}"."channel"`, 'ASC');
128129
return builder;
129130
},
130131
true,

0 commit comments

Comments
 (0)