Skip to content
Open
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
6 changes: 2 additions & 4 deletions src/components/budget/budget-record.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,8 @@ export class BudgetRecordRepository extends DtoRepository<
view,
}: BudgetRecordHydrateArgs) {
return (query: Query) =>
query.subQuery((sub) =>
query.subQuery([recordVar, projectVar], (sub) =>
sub
.with([recordVar, projectVar]) // import
// rename to constant, only apply if making a change otherwise cypher breaks
.apply((q) =>
recordVar !== 'node' || projectVar !== 'project'
Expand Down Expand Up @@ -199,9 +198,8 @@ export class BudgetRecordRepository extends DtoRepository<
outputVar?: string;
}) {
return (query: Query) =>
query.subQuery((sub) =>
query.subQuery(budgetVar, (sub) =>
sub
.with(budgetVar)
.match([
node(budgetVar),
relation('out', '', 'record', ACTIVE),
Expand Down
3 changes: 1 addition & 2 deletions src/components/budget/budget.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,8 @@ export class BudgetRepository extends DtoRepository<
const result = await this.db
.query()
.apply(this.currentBudgetForProject(projectId, changeset))
.subQuery((sub) =>
.subQuery(['project', 'budget'], (sub) =>
sub
.with('project, budget')
.apply(this.records.recordsOfBudget({ view }))
.apply(this.records.hydrate({ session, view }))
.return('collect(dto) as records'),
Expand Down
28 changes: 16 additions & 12 deletions src/components/comments/comment-thread.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,22 @@ export class CommentThreadRepository extends DtoRepository(CommentThread) {
.subQuery('node', (sub) =>
sub
.with('node as thread')
.match([
node('thread'),
relation('out', '', 'comment', ACTIVE),
node('comment', 'Comment'),
])
.with('comment')
.orderBy('comment.createdAt')
.with('collect(comment) as comments')
.with('[comments[0], comments[-1]] as comments')
.raw('unwind comments as node')
.subQuery('node', this.comments.hydrate())
.return('collect(dto) as comments'),
.subQuery('thread', (sub2) =>
sub2
.match([
node('thread'),
relation('out', '', 'comment', ACTIVE),
node('comment', 'Comment'),
])
.with('comment')
.orderBy('comment.createdAt')
.with('collect(comment) as comments')
.with('[comments[0], comments[-1]] as comments')
.raw('unwind comments as node')
.subQuery('node', this.comments.hydrate())
.return('collect(dto) as comments'),
)
.return('comments'),
)
.return<{ dto: UnsecuredDto<CommentThread> }>(
merge('node', {
Expand Down
16 changes: 6 additions & 10 deletions src/components/engagement/engagement.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,27 +899,24 @@ export const engagementSorters = defineSorters(IEngagement, {
// eslint-disable-next-line @typescript-eslint/naming-convention
'language.*': (query, input) =>
query
.with('node as eng')
.match([node('eng'), relation('out', '', 'language'), node('node')])
.match([node('outer'), relation('out', '', 'language'), node('node')])
.apply(sortWith(languageSorters, input))
// Use null for all internship engagements
.union()
.with('node')
.with('node as eng')
.raw('where eng:InternshipEngagement')
.with('outer')
.raw('where outer:InternshipEngagement')
.return<SortCol>('null as sortValue'),
// eslint-disable-next-line @typescript-eslint/naming-convention
'project.*': (query, input) =>
query
.with('node as eng')
.match([node('eng'), relation('in', '', 'engagement'), node('node')])
.match([node('outer'), relation('in', '', 'engagement'), node('node')])
.apply(sortWith(projectSorters, input)),
// eslint-disable-next-line @typescript-eslint/naming-convention
'currentProgressReportDue.*': (query, input) =>
query
.subQuery('node', (sub) =>
.with('outer as parent')
.subQuery('parent', (sub) =>
sub
.with('node as parent')
.apply(matchCurrentDue(undefined, 'Progress'))
.return('collect(node) as reports'),
)
Expand All @@ -930,7 +927,6 @@ export const engagementSorters = defineSorters(IEngagement, {
.return('null as sortValue')
.union()
.with('reports')
.with('reports')
.raw('where size(reports) <> 0')
.raw('unwind reports as node')
.apply(sortWith(progressReportSorters, input)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ export class ApplyFinalizedChangesetToEngagement
relation('out', '', 'changeset', ACTIVE),
node('changeset', 'Changeset', { id: changeset.id }),
])
.subQuery((sub) =>
.subQuery(['project', 'changeset'], (sub) =>
sub
.with('project, changeset')
.match([
node('project'),
relation('out', 'engagementRel', 'engagement', ACTIVE),
Expand All @@ -63,9 +62,8 @@ export class ApplyFinalizedChangesetToEngagement
relation('out', '', 'changeset', ACTIVE),
node('changeset', 'Changeset', { id: changeset.id }),
])
.subQuery((sub) =>
.subQuery(['project', 'changeset'], (sub) =>
sub
.with('project, changeset')
.match([
node('project'),
relation('out', 'engagementRel', 'engagement', INACTIVE),
Expand Down Expand Up @@ -95,9 +93,8 @@ export class ApplyFinalizedChangesetToEngagement
relation('out', '', 'changeset', ACTIVE),
node('changeset', 'Changeset', { id: changeset.id }),
])
.subQuery((sub) =>
.subQuery(['project', 'changeset'], (sub) =>
sub
.with('project, changeset')
.match([
node('project'),
relation('out', 'engagement', ACTIVE),
Expand Down
5 changes: 1 addition & 4 deletions src/components/file/file.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,17 @@ export class FileRepository extends CommonRepository {
hydrate() {
return (query: Query) =>
query
.subQuery((sub) =>
.subQuery('node', (sub) =>
sub
.with('node')
.with('node')
.where({ node: hasLabel(FileNodeType.File) })
.apply(this.hydrateFile())
.union()
.with('node')
.with('node')
.where({ node: hasLabel(FileNodeType.FileVersion) })
.apply(this.hydrateFileVersion())
.union()
.with('node')
.with('node')
.where({ node: hasLabel(FileNodeType.Directory) })
.apply(this.hydrateDirectory()),
)
Expand Down
7 changes: 2 additions & 5 deletions src/components/language/language.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,8 @@ export class LanguageRepository extends DtoRepository<
.apply(matchProps())
.apply(matchChangesetAndChangedProps(view?.changeset))
// get lowest sensitivity across all projects associated with each language.
.subQuery((sub) =>
.subQuery(['projList', 'props'], (sub) =>
sub
.with('projList')
.raw('UNWIND projList as project')
.apply(matchProjectSens())
.with('sensitivity')
Expand All @@ -197,7 +196,6 @@ export class LanguageRepository extends DtoRepository<
.return('sensitivity as effectiveSensitivity')
.union()
.with('projList, props')
.with('projList, props')
.raw('WHERE size(projList) = 0')
.return(`props.sensitivity as effectiveSensitivity`),
)
Expand Down Expand Up @@ -382,9 +380,8 @@ export const languageSorters = defineSorters(Language, {
// eslint-disable-next-line @typescript-eslint/naming-convention
'ethnologue.*': (query, input) =>
query
.with('node as lang')
.match([
node('lang'),
node('outer'),
relation('out', '', 'ethnologue'),
node('node', 'EthnologueLanguage'),
])
Expand Down
3 changes: 1 addition & 2 deletions src/components/notifications/notification.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,13 @@ export class NotificationRepository extends CommonRepository {
protected hydrate(session: Session) {
return (query: Query) =>
query
.subQuery((q) => {
.subQuery('node', (q) => {
const concreteHydrates = [...this.service.strategyMap].map(
([dtoCls, strategy]) =>
(q: Query) => {
const type = this.getType(dtoCls);
const hydrate = strategy.hydrateExtraForNeo4j('extra');
return q
.with('node')
.with('node')
.where({ 'node.type': type })
.apply(hydrate ?? ((q) => q.return('{} as extra')));
Expand Down
4 changes: 1 addition & 3 deletions src/components/organization/organization.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ export class OrganizationRepository extends DtoRepository<
'collect(project) as projList',
'keys(apoc.coll.frequenciesAsMap(apoc.coll.flatten(collect(scopedRoles)))) as scopedRoles',
])
.subQuery((sub) =>
.subQuery('projList', (sub) =>
sub
.with('projList')
.raw('UNWIND projList as project')
.apply(matchProjectSens())
.with('sensitivity')
Expand All @@ -102,7 +101,6 @@ export class OrganizationRepository extends DtoRepository<
.return('sensitivity')
.union()
.with('projList')
.with('projList')
.raw('WHERE size(projList) = 0')
.return(`'High' as sensitivity`),
)
Expand Down
7 changes: 2 additions & 5 deletions src/components/partner/partner.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,8 @@ export class PartnerRepository extends DtoRepository<
'collect(project) as projList',
'keys(apoc.coll.frequenciesAsMap(apoc.coll.flatten(collect(scopedRoles)))) as scopedRoles',
])
.subQuery((sub) =>
.subQuery('projList', (sub) =>
sub
.with('projList')
.raw('UNWIND projList as project')
.apply(matchProjectSens())
.with('sensitivity')
Expand All @@ -220,7 +219,6 @@ export class PartnerRepository extends DtoRepository<
.return('sensitivity')
.union()
.with('projList')
.with('projList')
.raw('WHERE size(projList) = 0')
.return(`'High' as sensitivity`),
)
Expand Down Expand Up @@ -352,9 +350,8 @@ export const partnerSorters = defineSorters(Partner, {
// eslint-disable-next-line @typescript-eslint/naming-convention
'organization.*': (query, input) =>
query
.with('node as partner')
.match([
node('partner'),
node('outer'),
relation('out', '', 'organization'),
node('node', 'Organization'),
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ export class ApplyFinalizedChangesetToPartnership
relation('out', '', 'changeset', ACTIVE),
node('changeset', 'Changeset', { id: changeset.id }),
])
.subQuery((sub) =>
.subQuery(['project', 'changeset'], (sub) =>
sub
.with('project, changeset')
.match([
node('project'),
relation('out', 'partnershipRel', 'partnership', ACTIVE),
Expand All @@ -58,9 +57,8 @@ export class ApplyFinalizedChangesetToPartnership
relation('out', '', 'changeset', ACTIVE),
node('changeset', 'Changeset', { id: changeset.id }),
])
.subQuery((sub) =>
.subQuery(['project', 'changeset'], (sub) =>
sub
.with('project, changeset')
.match([
node('project'),
relation('out', 'partnershipRel', 'partnership', INACTIVE),
Expand Down
7 changes: 2 additions & 5 deletions src/components/partnership/partnership.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,8 @@ export class PartnershipRepository extends DtoRepository<
.query()
.optionalMatch(node('partner', 'Partner', { id: partnerId }))
.optionalMatch(node('project', 'Project', { id: projectId }))
.subQuery((sub) =>
.subQuery(['project', 'partner'], (sub) =>
sub
.with('project, partner')
.optionalMatch([
node('project'),
relation('out', '', 'partnership', ACTIVE),
Expand All @@ -295,7 +294,6 @@ export class PartnershipRepository extends DtoRepository<
changeset
? q
.union()
.with('project, partner')
.match([node('changeset', 'Changeset', { id: changeset })])
.optionalMatch([
node('project'),
Expand Down Expand Up @@ -441,9 +439,8 @@ export const partnershipSorters = defineSorters(Partnership, {
// eslint-disable-next-line @typescript-eslint/naming-convention
'partner.*': (query, input) =>
query
.with('node as partnership')
.match([
node('partnership'),
node('outer'),
relation('out', '', 'partner'),
node('node', 'Partner'),
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,13 @@ export class PeriodicReportRepository extends DtoRepository<
protected hydrate(session: Session) {
return (query: Query) =>
query
.subQuery((sub) =>
.subQuery('node', (sub) =>
sub
.with('node')
.with('node')
.where({ node: hasLabel('ProgressReport') })
.apply(this.progressRepo.extraHydrate())
.union()
.with('node')
.with('node')
.where({ node: not(hasLabel('ProgressReport')) })
.return('{} as extra'),
)
Expand All @@ -401,7 +399,6 @@ export class PeriodicReportRepository extends DtoRepository<
])
.return('project')
.union()
.with('node')
.match([
node('node'),
relation('in', '', 'report', ACTIVE),
Expand Down
Loading