diff --git a/services/app-api/handlers/reports/buildReport.ts b/services/app-api/handlers/reports/buildReport.ts index 72519d51..e1fab985 100644 --- a/services/app-api/handlers/reports/buildReport.ts +++ b/services/app-api/handlers/reports/buildReport.ts @@ -1,6 +1,7 @@ +import KSUID from "ksuid"; import { qmReportTemplate } from "../../forms/qm"; import { putReport } from "../../storage/reports"; -import { Report, ReportType } from "../../types/reports"; +import { Report, ReportStatus, ReportType } from "../../types/reports"; const reportTemplates = { [ReportType.QM]: qmReportTemplate, @@ -16,10 +17,12 @@ export const buildReport = async ( // TODO: Save version to db (filled or unfilled?) report.state = state; - report.id = state + reportType + ""; // TODO: uid + report.id = KSUID.randomSync().string; report.created = Date.now(); report.lastEdited = Date.now(); report.lastEditedBy = username; + report.type = reportType; + report.status = ReportStatus.NOT_STARTED; if (reportType == ReportType.QM) { /* diff --git a/services/app-api/handlers/reports/update.ts b/services/app-api/handlers/reports/update.ts index 86c7376f..ecdf3a79 100644 --- a/services/app-api/handlers/reports/update.ts +++ b/services/app-api/handlers/reports/update.ts @@ -2,7 +2,7 @@ import handler from "../../libs/handler-lib"; import { parseReportParameters } from "../../libs/param-lib"; import { badRequest, ok } from "../../libs/response-lib"; import { putReport } from "../../storage/reports"; -import { Report } from "../../types/reports"; +import { Report, ReportStatus } from "../../types/reports"; export const updateReport = handler(async (event) => { const { allParamsValid, reportType, state, id } = @@ -26,6 +26,9 @@ export const updateReport = handler(async (event) => { return badRequest("Invalid request"); } + report.status = ReportStatus.IN_PROGRESS; + report.lastEdited = Date.now(); + // Validation required. await putReport(report); diff --git a/services/app-api/package.json b/services/app-api/package.json index 7b6cc37c..e6e464e4 100644 --- a/services/app-api/package.json +++ b/services/app-api/package.json @@ -31,6 +31,7 @@ "dompurify": "^3.1.6", "jsdom": "20.0.0", "jwt-decode": "3.1.2", + "ksuid": "^3.0.0", "util": "^0.12.5" }, "jest": { diff --git a/services/app-api/types/reports.ts b/services/app-api/types/reports.ts index 2fbf14ae..6223dd9c 100644 --- a/services/app-api/types/reports.ts +++ b/services/app-api/types/reports.ts @@ -37,12 +37,19 @@ export enum MeasureTemplateName { StandardMeasure, } +export enum ReportStatus { + NOT_STARTED = "Not started", + IN_PROGRESS = "In progress", + SUBMITTED = "Submitted", +} + export interface Report extends ReportTemplate { id?: string; state: string; created?: number; lastEdited?: number; lastEditedBy?: string; + status: ReportStatus; } export interface MeasurePageTemplate extends FormPageTemplate { diff --git a/services/app-api/yarn.lock b/services/app-api/yarn.lock index da366e13..a061c227 100644 --- a/services/app-api/yarn.lock +++ b/services/app-api/yarn.lock @@ -1913,6 +1913,11 @@ balanced-match@^1.0.0: resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== +base-convert-int-array@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/base-convert-int-array/-/base-convert-int-array-1.0.1.tgz#5b4ddbfa72d2d3b5f75dd86cd32fe3dc8e7e81fe" + integrity sha512-NWqzaoXx8L/SS32R+WmKqnQkVXVYl2PwNJ68QV3RAlRRL1uV+yxJT66abXI1cAvqCXQTyXr7/9NN4Af90/zDVw== + bowser@^2.11.0: version "2.11.0" resolved "https://registry.yarnpkg.com/bowser/-/bowser-2.11.0.tgz#5ca3c35757a7aa5771500c70a73a9f91ef420a8f" @@ -3226,6 +3231,13 @@ kleur@^3.0.3: resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e" integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w== +ksuid@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/ksuid/-/ksuid-3.0.0.tgz#aeef71afc9409fd7aae2d42bc236c7b00fa9f4b8" + integrity sha512-81CkBGn/06ZVAjGvFZi6fVG8VcPeMH0JpJ4V1Z9VwrMMaGIeAjY4jrVdrIcxhL9I2ZUU6t5uiyswcmkk+KZegA== + dependencies: + base-convert-int-array "^1.0.1" + leven@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/leven/-/leven-3.1.0.tgz#77891de834064cccba82ae7842bb6b14a13ed7f2" diff --git a/services/ui-src/src/components/pages/Dashboard/DashboardPage.test.tsx b/services/ui-src/src/components/pages/Dashboard/DashboardPage.test.tsx index b1391ada..13920d72 100644 --- a/services/ui-src/src/components/pages/Dashboard/DashboardPage.test.tsx +++ b/services/ui-src/src/components/pages/Dashboard/DashboardPage.test.tsx @@ -36,7 +36,7 @@ jest.mock("utils/api/requestMethods/report", () => ({ lastEdited: new Date("2024-10-24T08:31:54").valueOf(), lastEditedBy: "Mock User", status: "Not Started", - } as Report, + } as unknown as Report, ]), })); diff --git a/services/ui-src/src/components/report/ReportPageWrapper.test.tsx b/services/ui-src/src/components/report/ReportPageWrapper.test.tsx index 53062af3..593f303b 100644 --- a/services/ui-src/src/components/report/ReportPageWrapper.test.tsx +++ b/services/ui-src/src/components/report/ReportPageWrapper.test.tsx @@ -14,7 +14,7 @@ const testReport: Report = { title: "plan id", state: "NJ", id: "NJQM123", - status: ReportStatus.NotStarted, + status: ReportStatus.NOT_STARTED, pages: [ { id: "root", diff --git a/services/ui-src/src/types/report.ts b/services/ui-src/src/types/report.ts index 793e0215..4d22bf2a 100644 --- a/services/ui-src/src/types/report.ts +++ b/services/ui-src/src/types/report.ts @@ -9,11 +9,10 @@ export const isReportType = ( return Object.values(ReportType).includes(reportType as ReportType); }; -// TODO: We probably will need more statuses? In Revision? Approved? export enum ReportStatus { - NotStarted = "Not Started", - InProgress = "In Progress", - Submitted = "Submitted", + NOT_STARTED = "Not started", + IN_PROGRESS = "In progress", + SUBMITTED = "Submitted", } export const isReportStatus = (status: string): status is ReportStatus => { return Object.values(ReportStatus).includes(status as ReportStatus); @@ -37,7 +36,6 @@ export interface Report extends ReportTemplate { lastEdited?: number; lastEditedBy?: string; status: ReportStatus; - answers?: any[]; //TODO: any } export type PageTemplate = diff --git a/services/ui-src/src/utils/state/management/reportState.test.ts b/services/ui-src/src/utils/state/management/reportState.test.ts index 8ae501bc..75e457d8 100644 --- a/services/ui-src/src/utils/state/management/reportState.test.ts +++ b/services/ui-src/src/utils/state/management/reportState.test.ts @@ -18,7 +18,7 @@ const testReport: Report = { title: "plan id", state: "NJ", id: "NJQM123", - status: ReportStatus.NotStarted, + status: ReportStatus.NOT_STARTED, pages: [ { id: "root",