-
Notifications
You must be signed in to change notification settings - Fork 6
[Gel] Add PeriodicReport
queries | refactor service/repo layers
#3247
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
Open
bryanjnelson
wants to merge
3
commits into
develop
Choose a base branch
from
0933-periodic-report-queries
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+419
−194
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
src/components/periodic-report/periodic-report.gel.repository.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { type Without } from 'type-fest/source/merge-exclusive'; | ||
import { | ||
CalendarDate, | ||
EnhancedResource, | ||
type ID, | ||
type PublicOf, | ||
type UnsecuredDto, | ||
} from '~/common'; | ||
import { castToEnum, e, RepoFor } from '~/core/gel'; | ||
import { type ProgressReport } from '../progress-report/dto'; | ||
import { | ||
type FinancialReport, | ||
IPeriodicReport, | ||
type NarrativeReport, | ||
ReportType, | ||
resolveReportType, | ||
} from './dto'; | ||
import { type PeriodicReportRepository } from './periodic-report.repository'; | ||
|
||
@Injectable() | ||
export class PeriodicReportGelRepository | ||
extends RepoFor(IPeriodicReport, { | ||
hydrate: (periodicReport) => ({ | ||
...periodicReport['*'], | ||
type: castToEnum(periodicReport.__type__.name.slice(9, -7), ReportType), | ||
reportFile: true, | ||
sensitivity: periodicReport.container.is(e.Project.ContextAware) | ||
.sensitivity, | ||
scope: false, | ||
parent: e.select({ | ||
identity: periodicReport.id, | ||
labels: e.array_agg(e.set(periodicReport.__type__.name.slice(9, null))), | ||
properties: e.select({ | ||
id: periodicReport.id, | ||
createdAt: periodicReport.createdAt, | ||
}), | ||
}), | ||
}), | ||
omit: ['create'], | ||
}) | ||
implements PublicOf<PeriodicReportRepository> | ||
{ | ||
//TODO - this is close but the hydrate for ProgressReport needs worked on | ||
async matchCurrentDue(parentId: ID, reportType: ReportType) { | ||
const enhancedResource = EnhancedResource.of( | ||
resolveReportType({ type: reportType }), | ||
); | ||
const resource = e.cast(enhancedResource.db, e.uuid(parentId)); | ||
const report = e.select(resource, (report) => ({ | ||
...this.hydrate(report), | ||
filter: e.all( | ||
e.set( | ||
e.op(resource.id, '=', report.container.id), | ||
e.op(report.end, '<', CalendarDate.now()), | ||
), | ||
), | ||
order_by: [ | ||
{ expression: report.end, direction: e.DESC }, | ||
{ expression: report.start, direction: e.ASC }, | ||
], | ||
})); | ||
return await this.db.run(report); | ||
} | ||
|
||
getCurrentDue( | ||
_parentId: ID, | ||
_reportType: ReportType, | ||
): Promise< | ||
| UnsecuredDto< | ||
| (Without< | ||
| (Without<FinancialReport, NarrativeReport> & NarrativeReport) | ||
| (Without<NarrativeReport, FinancialReport> & FinancialReport), | ||
ProgressReport | ||
> & | ||
ProgressReport) | ||
| (Without< | ||
ProgressReport, | ||
| (Without<FinancialReport, NarrativeReport> & NarrativeReport) | ||
| (Without<NarrativeReport, FinancialReport> & FinancialReport) | ||
> & | ||
( | ||
| (Without<FinancialReport, NarrativeReport> & NarrativeReport) | ||
| (Without<NarrativeReport, FinancialReport> & FinancialReport) | ||
)) | ||
> | ||
| undefined | ||
> { | ||
//TODO - is this needed? How does this differ from matchCurrentDue? | ||
throw new Error('Method not implemented.'); | ||
} | ||
bryanjnelson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
//TODO - this is close but the hydrate for ProgressReport needs worked on | ||
async getByDate(parentId: ID, date: CalendarDate, reportType: ReportType) { | ||
const enhancedResource = EnhancedResource.of( | ||
resolveReportType({ type: reportType }), | ||
); | ||
const resource = e.cast(enhancedResource.db, e.uuid(parentId)); | ||
const report = e.select(resource, (report) => ({ | ||
...this.hydrate(report), | ||
filter: e.all( | ||
e.set( | ||
e.op(resource.id, '=', report.container.id), | ||
e.op(report.start, '<=', date), | ||
e.op(report.end, '>=', date), | ||
), | ||
), | ||
})); | ||
return await this.db.run(report); | ||
} | ||
|
||
//TODO - this is close but the hydrate for ProgressReport needs worked on | ||
async getNextDue(parentId: ID, reportType: ReportType) { | ||
const enhancedResource = EnhancedResource.of( | ||
resolveReportType({ type: reportType }), | ||
); | ||
const resource = e.cast(enhancedResource.db, e.uuid(parentId)); | ||
const report = e.select(resource, (report) => ({ | ||
...this.hydrate(report), | ||
filter: e.all( | ||
e.set( | ||
e.op(resource.id, '=', report.container.id), | ||
e.op(report.end, '>', CalendarDate.now()), | ||
), | ||
), | ||
order_by: { expression: report.end, direction: e.ASC }, | ||
})); | ||
|
||
return await this.db.run(report); | ||
} | ||
|
||
//TODO - this is close but the hydrate for ProgressReport needs worked on | ||
async getLatestReportSubmitted(parentId: ID, reportType: ReportType) { | ||
const enhancedResource = EnhancedResource.of( | ||
resolveReportType({ type: reportType }), | ||
); | ||
const resource = e.cast(enhancedResource.db, e.uuid(parentId)); | ||
const report = e.select(resource, (report) => ({ | ||
...this.hydrate(report), | ||
filter: e.all( | ||
e.set( | ||
e.op(resource.id, '=', report.container.id), | ||
e.op('exists', report.reportFile), | ||
), | ||
), | ||
order_by: { expression: report.start, direction: e.DESC }, | ||
})); | ||
|
||
return await this.db.run(report); | ||
} | ||
|
||
//TODO - this is close but the hydrate for ProgressReport needs worked on | ||
async getFinalReport(parentId: ID, reportType: ReportType) { | ||
const enhancedResource = EnhancedResource.of( | ||
resolveReportType({ type: reportType }), | ||
); | ||
const resource = e.cast(enhancedResource.db, e.uuid(parentId)); | ||
const report = e.select(resource, (report) => ({ | ||
...this.hydrate(report), | ||
filter: e.all( | ||
e.set( | ||
e.op(resource.id, '=', report.container.id), | ||
e.op(report.start, '=', report.end), | ||
), | ||
), | ||
order_by: { expression: report.start, direction: e.DESC }, | ||
})); | ||
|
||
return await this.db.run(report); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.