generated from nhcarrigan/template
Some checks failed
Node.js CI / Lint and Test (push) Has been cancelled
### Explanation _No response_ ### Issue _No response_ ### Attestations - [x] I have read and agree to the [Code of Conduct](https://docs.nhcarrigan.com/community/coc/) - [x] I have read and agree to the [Community Guidelines](https://docs.nhcarrigan.com/community/guide/). - [x] My contribution complies with the [Contributor Covenant](https://docs.nhcarrigan.com/dev/covenant/). ### Dependencies - [x] I have pinned the dependencies to a specific patch version. ### Style - [x] I have run the linter and resolved any errors. - [x] My pull request uses an appropriate title, matching the conventional commit standards. - [x] My scope of feat/fix/chore/etc. correctly matches the nature of changes in my pull request. ### Tests - [ ] My contribution adds new code, and I have added tests to cover it. - [ ] My contribution modifies existing code, and I have updated the tests to reflect these changes. - [x] All new and existing tests pass locally with my changes. - [x] Code coverage remains at or above the configured threshold. ### Documentation _No response_ ### Versioning Major - My pull request introduces a breaking change. Reviewed-on: nhcarrigan/forms#2 Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com> Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
57 lines
1.8 KiB
TypeScript
57 lines
1.8 KiB
TypeScript
/**
|
|
* @copyright nhcarrigan
|
|
* @license Naomi's Public License
|
|
* @author Naomi Carrigan
|
|
*/
|
|
import {
|
|
checkSubmissionExists,
|
|
markSubmissionReviewed,
|
|
} from "../../modules/genericDataQueries.js";
|
|
import { logger } from "../../utils/logger.js";
|
|
import type { DatabasePath } from "../../interfaces/databasePath.js";
|
|
import type { PrismaClient } from "@prisma/client";
|
|
import type {
|
|
ErrorResponse,
|
|
ReviewRequest,
|
|
SuccessResponse,
|
|
} from "@repo/types";
|
|
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
|
|
/**
|
|
* Queries the database for a specific submission type (based on
|
|
* the route parameter) and returns all unreviewed submissions.).
|
|
* @param database - The Prisma client.
|
|
* @param route - The type of data to list.
|
|
* @param data - The fastify data.
|
|
* @param data.request - The request body.
|
|
* @param data.response - The Fastify reply object.
|
|
*/
|
|
export const reviewHandler = async(
|
|
database: PrismaClient,
|
|
route: DatabasePath,
|
|
{
|
|
request,
|
|
response,
|
|
}: {
|
|
request: FastifyRequest<{ Body: ReviewRequest }>;
|
|
response: FastifyReply<{ Reply: SuccessResponse | ErrorResponse }>;
|
|
},
|
|
): Promise<void> => {
|
|
try {
|
|
const { submissionId } = request.body;
|
|
const exists = await checkSubmissionExists(database, route, submissionId);
|
|
if (!exists) {
|
|
response.code(404).send({ error: `${route} submission not found.` });
|
|
return;
|
|
}
|
|
await markSubmissionReviewed(database, route, submissionId);
|
|
await response.code(200).send({ success: true });
|
|
} catch (error) {
|
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- we bein' lazy.
|
|
await logger.error(`/review/${route}`, error as Error);
|
|
await response.status(500).send({ error: error instanceof Error
|
|
? error.message
|
|
: "Internal Server Error" });
|
|
}
|
|
};
|