Skip to content

Commit

Permalink
fix: CE-828 - fixes report run on date/time (#487)
Browse files Browse the repository at this point in the history
Co-authored-by: Mike Sears <[email protected]>
Co-authored-by: barrfalk <[email protected]>
Co-authored-by: afwilcox <[email protected]>
  • Loading branch information
4 people authored Jun 25, 2024
1 parent a51fa94 commit 0113364
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions backend/src/v1/complaint/complaint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import { PersonComplaintXrefTable } from "../../types/tables/person-complaint-xr
import { OfficeStats, OfficerStats, ZoneAtAGlanceStats } from "src/types/zone_at_a_glance/zone_at_a_glance_stats";
import { CosGeoOrgUnit } from "../cos_geo_org_unit/entities/cos_geo_org_unit.entity";
import { UUID, randomUUID } from "crypto";
import { format } from "date-fns";
import { format, toDate, toZonedTime } from "date-fns-tz";

@Injectable({ scope: Scope.REQUEST })
export class ComplaintService {
Expand Down Expand Up @@ -1306,6 +1306,8 @@ export class ComplaintService {
};

getReportData = async (id: string, complaintType: COMPLAINT_TYPE, tz: string) => {
let data;

mapWildlifeReport(this.mapper, tz);
mapAllegationReport(this.mapper, tz);

Expand Down Expand Up @@ -1345,23 +1347,32 @@ export class ComplaintService {

switch (complaintType) {
case "HWCR": {
const hwcr = this.mapper.map<HwcrComplaint, WildlifeReportData>(
data = this.mapper.map<HwcrComplaint, WildlifeReportData>(
result as HwcrComplaint,
"HwcrComplaint",
"WildlifeReportData",
);
return hwcr;
break;
}
case "ERS": {
const ers = this.mapper.map<AllegationComplaint, AllegationReportData>(
data = this.mapper.map<AllegationComplaint, AllegationReportData>(
result as AllegationComplaint,
"AllegationComplaint",
"AllegationReportData",
);

return ers;
break;
}
}

//-- set the report run date/time
//-- use this in CE-828
const utcDate = toDate(new Date(), { timeZone: "UTC" });
const zonedDate = toZonedTime(utcDate, tz);
data.reportDate = format(zonedDate, "yyyy-MM-dd ", { timeZone: tz });
data.reportTime = format(zonedDate, "HH:mm", { timeZone: tz });

return data;
} catch (error) {
this.logger.error(error);
}
Expand Down

0 comments on commit 0113364

Please sign in to comment.