Skip to content

Commit

Permalink
chore: add submitForReview to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
bdolor committed Nov 6, 2023
1 parent 8ec85cc commit 1263b4b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/back-end/lib/resources/opportunity/code-with-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ interface ValidatedUpdateRequestBody {
session: AuthenticatedSession;
body:
| ADT<"edit", ValidatedUpdateEditRequestBody>
| ADT<"submitForReview", string>
| ADT<"publish", string>
| ADT<"suspend", string>
| ADT<"cancel", string>
Expand Down Expand Up @@ -441,6 +442,8 @@ const update: crud.Update<
evaluationCriteria: getString(value, "evaluationCriteria"),
attachments: getStringArray(value, "attachments")
});
case "submitForReview":
return adt("submitForReview", getString(body, "value"));
case "publish":
return adt("publish", getString(body, "value", ""));
case "suspend":
Expand Down Expand Up @@ -513,6 +516,7 @@ const update: crud.Update<
if (
![
CWUOpportunityStatus.Draft,
CWUOpportunityStatus.UnderReview,
CWUOpportunityStatus.Published,
CWUOpportunityStatus.Suspended
].includes(cwuOpportunity.status)
Expand Down Expand Up @@ -697,6 +701,52 @@ const update: crud.Update<
});
}
}
case "submitForReview": {
if (
!isValidStatusChange(
cwuOpportunity.status,
CWUOpportunityStatus.UnderReview
)
) {
return invalid({ permissions: [permissions.ERROR_MESSAGE] });
}
// Perform validation on draft to ensure it's ready for publishing
if (
!allValid([
genericValidation.validateTitle(cwuOpportunity.title),
genericValidation.validateTeaser(cwuOpportunity.teaser),
genericValidation.validateRemoteOk(cwuOpportunity.remoteOk),
genericValidation.validateRemoteDesc(
cwuOpportunity.remoteDesc,
cwuOpportunity.remoteOk
),
genericValidation.validateLocation(cwuOpportunity.location),
genericValidation.validateDescription(cwuOpportunity.description)
])
) {
return invalid({
opportunity: adt("submitForReview" as const, [
"This opportunity could not be submitted for review because it is incomplete. Please edit, complete and save the form below before trying to publish it again."
])
});
}

const validatedSubmitNote = opportunityValidation.validateNote(
request.body.value
);
if (isInvalid(validatedSubmitNote)) {
return invalid({
opportunity: adt(
"submitForReview" as const,
validatedSubmitNote.value
)
});
}
return valid({
session: request.session,
body: adt("submitForReview", validatedSubmitNote.value)
} as ValidatedUpdateRequestBody);
}
case "publish": {
if (
!isValidStatusChange(
Expand Down Expand Up @@ -892,6 +942,22 @@ const update: crud.Update<
);
}
break;
case "submitForReview":
dbResult = await db.updateCWUOpportunityStatus(
connection,
request.params.id,
CWUOpportunityStatus.UnderReview,
body.value,
session
);
//Notify of submission
if (isValid(dbResult)) {
cwuOpportunityNotifications.handleCWUSubmittedForReview(
connection,
dbResult.value
);
}
break;
case "publish": {
const existingOpportunity = getValidValue(
await db.readOneCWUOpportunity(
Expand Down
1 change: 1 addition & 0 deletions src/shared/lib/resources/opportunity/code-with-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export interface UpdateWithNoteValidationErrors

type UpdateADTErrors =
| ADT<"edit", UpdateEditValidationErrors>
| ADT<"submitForReview", string[]>
| ADT<"publish", string[]>
| ADT<"suspend", string[]>
| ADT<"cancel", string[]>
Expand Down

0 comments on commit 1263b4b

Please sign in to comment.