From dc06def9d1932779f935f7e5d004c21a31566466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Zakrzewski?= Date: Fri, 25 Oct 2024 16:34:42 +0200 Subject: [PATCH] Update date type --- data-serving/data-service/src/controllers/case.ts | 12 ++++++------ data-serving/data-service/src/model/events.ts | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/data-serving/data-service/src/controllers/case.ts b/data-serving/data-service/src/controllers/case.ts index 79023c5ff..aa66bbf8f 100644 --- a/data-serving/data-service/src/controllers/case.ts +++ b/data-serving/data-service/src/controllers/case.ts @@ -193,14 +193,14 @@ const updatedRevisionMetadata = ( day0Case: CaseDocument, curator: string, note?: string, - date?: Date, + date?: Date | number, ) => { return { creationMetadata: day0Case.revisionMetadata.creationMetadata, updateMetadata: { curator: curator, note: note, - date: date || new Date(), + date: date || Date.now(), }, revisionNumber: day0Case.revisionMetadata.revisionNumber + 1, }; @@ -757,7 +757,7 @@ export class CasesController { try { this.addGeoResolution(req); - const currentDate: Date = new Date(); + const currentDate = Date.now(); const curator = req.body.curator.email; const receivedCase = { ...req.body, @@ -774,9 +774,9 @@ export class CasesController { }, }, } as CaseDTO; - receivedCase.events.dateLastModified = currentDate; const c = fillEmpty(new Day0Case(await caseFromDTO(receivedCase))); + c.set({'events.dateLastModified': currentDate}); let result; if (req.query.validate_only) { @@ -854,7 +854,7 @@ export class CasesController { }); return; } else { - const updateDate = new Date(); + const updateDate = Date.now(); c.set({ curators: { createdBy: c.curators.createdBy, @@ -1096,7 +1096,7 @@ export class CasesController { return; } const caseDetails = await caseFromDTO(req.body); - const updateDate = new Date(); + const updateDate = Date.now(); c.set({ ...caseDetails, revisionMetadata: updatedRevisionMetadata( diff --git a/data-serving/data-service/src/model/events.ts b/data-serving/data-service/src/model/events.ts index d2af4c650..fa17f5866 100644 --- a/data-serving/data-service/src/model/events.ts +++ b/data-serving/data-service/src/model/events.ts @@ -1,5 +1,7 @@ import mongoose from 'mongoose'; import { YesNo } from '../types/enums'; +import { dateFieldInfo } from './date'; +import validateEnv from '../util/validate-env'; export enum HospitalizationReason { Monitoring = 'monitoring', @@ -22,7 +24,7 @@ export const EventsSchema = new mongoose.Schema( type: Date, required: true, }, - dateLastModified: Date, + dateLastModified: { ...dateFieldInfo(validateEnv().OUTBREAK_DATE) }, dateOnset: Date, dateConfirmation: Date, confirmationMethod: String,