Skip to content

Commit c5463a1

Browse files
authored
Allow sorting project's engagement totals with engagements.total (#3417)
1 parent 88453ae commit c5463a1

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/components/project/project.repository.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Injectable } from '@nestjs/common';
2+
import { mapValues } from '@seedcompany/common';
23
import { inArray, node, not, type Query, relation } from 'cypher-query-builder';
34
import { DateTime } from 'luxon';
45
import {
@@ -391,14 +392,20 @@ export const projectSorters = defineSorters(IProject, {
391392
query
392393
.apply(matchProjectSens('node', 'sortValue'))
393394
.return<SortCol>('sortValue'),
394-
engagements: (query) =>
395-
query
396-
.match([
397-
node('node'),
398-
relation('out', '', 'engagement'),
399-
node('engagement', 'LanguageEngagement'),
400-
])
401-
.return<SortCol>('count(engagement) as sortValue'),
395+
...mapValues.fromList(
396+
[
397+
'engagements', // probably "deprecated"
398+
'engagements.total',
399+
],
400+
() => (query: Query) =>
401+
query
402+
.match([
403+
node('node'),
404+
relation('out', '', 'engagement'),
405+
node('engagement', 'LanguageEngagement'),
406+
])
407+
.return<SortCol>('count(engagement) as sortValue'),
408+
).asRecord,
402409
// eslint-disable-next-line @typescript-eslint/naming-convention
403410
'primaryLocation.*': (query, input) => {
404411
const getPath = (anon = false) => [

0 commit comments

Comments
 (0)