|
| 1 | +import { Injectable } from '@nestjs/common'; |
| 2 | +import { type Query } from 'cypher-query-builder'; |
| 3 | +import { type Without } from 'type-fest/source/merge-exclusive'; |
| 4 | +import { |
| 5 | + type CalendarDate, |
| 6 | + EnhancedResource, |
| 7 | + type ID, |
| 8 | + type PublicOf, |
| 9 | + type UnsecuredDto, |
| 10 | +} from '~/common'; |
| 11 | +import { castToEnum, e, RepoFor } from '~/core/gel'; |
| 12 | +import { type Variable } from '../../core/database/query'; |
| 13 | +import { type ProgressReport } from '../progress-report/dto'; |
| 14 | +import { |
| 15 | + type FinancialReport, |
| 16 | + IPeriodicReport, |
| 17 | + type NarrativeReport, |
| 18 | + ReportType, |
| 19 | + resolveReportType, |
| 20 | +} from './dto'; |
| 21 | +import { type PeriodicReportRepository } from './periodic-report.repository'; |
| 22 | + |
| 23 | +@Injectable() |
| 24 | +export class PeriodicReportGelRepository |
| 25 | + extends RepoFor(IPeriodicReport, { |
| 26 | + hydrate: (periodicReport) => ({ |
| 27 | + ...periodicReport['*'], |
| 28 | + type: castToEnum(periodicReport.__type__.name.slice(9, -7), ReportType), |
| 29 | + reportFile: true, |
| 30 | + sensitivity: periodicReport.container.is(e.Project.ContextAware) |
| 31 | + .sensitivity, |
| 32 | + scope: false, |
| 33 | + parent: e.select({ |
| 34 | + identity: periodicReport.id, |
| 35 | + labels: e.array_agg(e.set(periodicReport.__type__.name.slice(9, null))), |
| 36 | + properties: e.select({ |
| 37 | + id: periodicReport.id, |
| 38 | + createdAt: periodicReport.createdAt, |
| 39 | + }), |
| 40 | + }), |
| 41 | + }), |
| 42 | + omit: ['create'], |
| 43 | + }) |
| 44 | + implements PublicOf<PeriodicReportRepository> |
| 45 | +{ |
| 46 | + matchCurrentDue( |
| 47 | + _parentId: ID | Variable, |
| 48 | + _reportType: ReportType, |
| 49 | + ): (query: Query) => Query { |
| 50 | + throw new Error('Method not implemented.'); |
| 51 | + } |
| 52 | + |
| 53 | + async getByDate(parentId: ID, date: CalendarDate, reportType: ReportType) { |
| 54 | + const enhancedResource = EnhancedResource.of( |
| 55 | + resolveReportType({ type: reportType }), |
| 56 | + ); |
| 57 | + const resource = e.cast(enhancedResource.db, e.uuid(parentId)); |
| 58 | + |
| 59 | + const report = e.select(e.PeriodicReport, (report) => ({ |
| 60 | + filter: e.all( |
| 61 | + e.set( |
| 62 | + e.op(resource.id, '=', report.container.id), |
| 63 | + e.op(report.start, '<=', date), |
| 64 | + e.op(report.end, '>=', date), |
| 65 | + ), |
| 66 | + ), |
| 67 | + ...report.is(resolveReportType(reportType)), |
| 68 | + })); |
| 69 | + |
| 70 | + return this.db.run(report); |
| 71 | + } |
| 72 | + |
| 73 | + getCurrentDue( |
| 74 | + _parentId: ID, |
| 75 | + _reportType: ReportType, |
| 76 | + ): Promise< |
| 77 | + | UnsecuredDto< |
| 78 | + | (Without< |
| 79 | + | (Without<FinancialReport, NarrativeReport> & NarrativeReport) |
| 80 | + | (Without<NarrativeReport, FinancialReport> & FinancialReport), |
| 81 | + ProgressReport |
| 82 | + > & |
| 83 | + ProgressReport) |
| 84 | + | (Without< |
| 85 | + ProgressReport, |
| 86 | + | (Without<FinancialReport, NarrativeReport> & NarrativeReport) |
| 87 | + | (Without<NarrativeReport, FinancialReport> & FinancialReport) |
| 88 | + > & |
| 89 | + ( |
| 90 | + | (Without<FinancialReport, NarrativeReport> & NarrativeReport) |
| 91 | + | (Without<NarrativeReport, FinancialReport> & FinancialReport) |
| 92 | + )) |
| 93 | + > |
| 94 | + | undefined |
| 95 | + > { |
| 96 | + throw new Error('Method not implemented.'); |
| 97 | + } |
| 98 | + |
| 99 | + getNextDue( |
| 100 | + _parentId: ID, |
| 101 | + _reportType: ReportType, |
| 102 | + ): Promise< |
| 103 | + | UnsecuredDto< |
| 104 | + | (Without< |
| 105 | + | (Without<FinancialReport, NarrativeReport> & NarrativeReport) |
| 106 | + | (Without<NarrativeReport, FinancialReport> & FinancialReport), |
| 107 | + ProgressReport |
| 108 | + > & |
| 109 | + ProgressReport) |
| 110 | + | (Without< |
| 111 | + ProgressReport, |
| 112 | + | (Without<FinancialReport, NarrativeReport> & NarrativeReport) |
| 113 | + | (Without<NarrativeReport, FinancialReport> & FinancialReport) |
| 114 | + > & |
| 115 | + ( |
| 116 | + | (Without<FinancialReport, NarrativeReport> & NarrativeReport) |
| 117 | + | (Without<NarrativeReport, FinancialReport> & FinancialReport) |
| 118 | + )) |
| 119 | + > |
| 120 | + | undefined |
| 121 | + > { |
| 122 | + throw new Error('Method not implemented.'); |
| 123 | + } |
| 124 | + |
| 125 | + getLatestReportSubmitted( |
| 126 | + _parentId: ID, |
| 127 | + _type: ReportType, |
| 128 | + ): Promise< |
| 129 | + | UnsecuredDto< |
| 130 | + | (Without< |
| 131 | + | (Without<FinancialReport, NarrativeReport> & NarrativeReport) |
| 132 | + | (Without<NarrativeReport, FinancialReport> & FinancialReport), |
| 133 | + ProgressReport |
| 134 | + > & |
| 135 | + ProgressReport) |
| 136 | + | (Without< |
| 137 | + ProgressReport, |
| 138 | + | (Without<FinancialReport, NarrativeReport> & NarrativeReport) |
| 139 | + | (Without<NarrativeReport, FinancialReport> & FinancialReport) |
| 140 | + > & |
| 141 | + ( |
| 142 | + | (Without<FinancialReport, NarrativeReport> & NarrativeReport) |
| 143 | + | (Without<NarrativeReport, FinancialReport> & FinancialReport) |
| 144 | + )) |
| 145 | + > |
| 146 | + | undefined |
| 147 | + > { |
| 148 | + throw new Error('Method not implemented.'); |
| 149 | + } |
| 150 | + |
| 151 | + getFinalReport( |
| 152 | + _parentId: ID, |
| 153 | + _type: ReportType, |
| 154 | + ): Promise< |
| 155 | + | UnsecuredDto< |
| 156 | + | (Without< |
| 157 | + | (Without<FinancialReport, NarrativeReport> & NarrativeReport) |
| 158 | + | (Without<NarrativeReport, FinancialReport> & FinancialReport), |
| 159 | + ProgressReport |
| 160 | + > & |
| 161 | + ProgressReport) |
| 162 | + | (Without< |
| 163 | + ProgressReport, |
| 164 | + | (Without<FinancialReport, NarrativeReport> & NarrativeReport) |
| 165 | + | (Without<NarrativeReport, FinancialReport> & FinancialReport) |
| 166 | + > & |
| 167 | + ( |
| 168 | + | (Without<FinancialReport, NarrativeReport> & NarrativeReport) |
| 169 | + | (Without<NarrativeReport, FinancialReport> & FinancialReport) |
| 170 | + )) |
| 171 | + > |
| 172 | + | undefined |
| 173 | + > { |
| 174 | + throw new Error('Method not implemented.'); |
| 175 | + } |
| 176 | +} |
0 commit comments