Skip to content

Commit

Permalink
[Cmdct-4010] - Update Report ID (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
BearHanded authored Oct 29, 2024
1 parent 12d778a commit 21de2c7
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 11 deletions.
7 changes: 5 additions & 2 deletions services/app-api/handlers/reports/buildReport.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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) {
/*
Expand Down
5 changes: 4 additions & 1 deletion services/app-api/handlers/reports/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } =
Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions services/app-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 7 additions & 0 deletions services/app-api/types/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions services/app-api/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const testReport: Report = {
title: "plan id",
state: "NJ",
id: "NJQM123",
status: ReportStatus.NotStarted,
status: ReportStatus.NOT_STARTED,
pages: [
{
id: "root",
Expand Down
8 changes: 3 additions & 5 deletions services/ui-src/src/types/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -37,7 +36,6 @@ export interface Report extends ReportTemplate {
lastEdited?: number;
lastEditedBy?: string;
status: ReportStatus;
answers?: any[]; //TODO: any
}

export type PageTemplate =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const testReport: Report = {
title: "plan id",
state: "NJ",
id: "NJQM123",
status: ReportStatus.NotStarted,
status: ReportStatus.NOT_STARTED,
pages: [
{
id: "root",
Expand Down

0 comments on commit 21de2c7

Please sign in to comment.