From 9b0d4d26256d5d49167436b1a0ff1269e0130990 Mon Sep 17 00:00:00 2001 From: Jamie Maynard <29251905+j-maynard@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:43:53 +0000 Subject: [PATCH] Fix issues affecting the pipeline --- src/@types/express-session/index.d.ts | 4 ++-- src/controllers/publish.ts | 24 +++++++++++++----------- src/dtos/dimension-state.ts | 1 + src/services/stats-wales-api.ts | 5 +++-- src/validators/index.ts | 17 +++++++++++------ src/views/publish/tasklist.ejs | 2 +- test/publish.test.ts | 2 +- 7 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/@types/express-session/index.d.ts b/src/@types/express-session/index.d.ts index b0be7ba..21e0fdb 100644 --- a/src/@types/express-session/index.d.ts +++ b/src/@types/express-session/index.d.ts @@ -1,10 +1,10 @@ import 'express-session'; -import { ViewErrDTO } from '../../dtos/view-dto'; import { DimensionPatchDto } from '../../dtos/dimension-patch-dto'; +import { ViewError } from '../../dtos/view-error'; declare module 'express-session' { interface SessionData { - errors: ViewErrDTO | undefined; + errors: ViewError[] | undefined; dimensionPatch: DimensionPatchDto | undefined; } } diff --git a/src/controllers/publish.ts b/src/controllers/publish.ts index 4f412fe..3115a9e 100644 --- a/src/controllers/publish.ts +++ b/src/controllers/publish.ts @@ -639,13 +639,14 @@ export const periodReview = async (req: Request, res: Response, next: NextFuncti status: error.status || 500, errors: [ { - tag: { - name: 'errors.dimension_reset' + field: '', + message: { + key: 'errors.dimension_reset' } } ], dataset_id: req.params.datasetId - }; + } as ViewErrDTO; } break; } @@ -686,8 +687,8 @@ export const dimensionName = async (req: Request, res: Response, next: NextFunct errors: [ { field: 'name', - tag: { - name: 'errors.no_name' + message: { + key: 'errors.no_name' } } ], @@ -704,8 +705,8 @@ export const dimensionName = async (req: Request, res: Response, next: NextFunct errors: [ { field: 'name', - tag: { - name: 'errors.dimension.name_to_long' + message: { + key: 'errors.dimension.name_to_long' } } ], @@ -721,8 +722,8 @@ export const dimensionName = async (req: Request, res: Response, next: NextFunct errors: [ { field: 'name', - tag: { - name: 'errors.dimension.name_to_short' + message: { + key: 'errors.dimension.name_to_short' } } ], @@ -747,8 +748,9 @@ export const dimensionName = async (req: Request, res: Response, next: NextFunct status: error.status || 500, errors: [ { - tag: { - name: 'errors.dimension.naming_failed' + field: '', + message: { + key: 'errors.dimension.naming_failed' } } ], diff --git a/src/dtos/dimension-state.ts b/src/dtos/dimension-state.ts index fdc4672..28e2b59 100644 --- a/src/dtos/dimension-state.ts +++ b/src/dtos/dimension-state.ts @@ -3,4 +3,5 @@ import { TaskStatus } from '../enums/task-status'; export interface DimensionState { name: string; status: TaskStatus; + type: string; } diff --git a/src/services/stats-wales-api.ts b/src/services/stats-wales-api.ts index b39d71f..79a2754 100644 --- a/src/services/stats-wales-api.ts +++ b/src/services/stats-wales-api.ts @@ -62,10 +62,11 @@ export class StatsWalesApi { return fetch(`${this.backendUrl}/${url}`, { method, headers: head, body: data }) .then(async (response: Response) => { if (!response.ok) { - if (response.body) { + const body = await new Response(response.body).text(); + if (body) { throw new ApiException(response.statusText, response.status, body); } - throw new ApiException(response.statusText, response.status, body); + throw new ApiException(response.statusText, response.status); } return response; }) diff --git a/src/validators/index.ts b/src/validators/index.ts index a5ca248..b6c340d 100644 --- a/src/validators/index.ts +++ b/src/validators/index.ts @@ -1,5 +1,3 @@ -/* eslint-disable prettier/prettier */ - import { Request } from 'express'; import { body, FieldValidationError, param, ValidationChain } from 'express-validator'; import { ResultWithContext } from 'express-validator/lib/chain/context-runner'; @@ -42,10 +40,17 @@ export const datasetIdValidator = () => param('datasetId').trim().notEmpty().isU export const revisionIdValidator = () => param('revisionId').trim().notEmpty().isUUID(4); export const factTableIdValidator = () => param('factTableId').trim().notEmpty().isUUID(4); -export const titleValidator = () => body('title').trim() - .notEmpty().withMessage('missing').bail() - .isLength({ min: 3 }).withMessage('too_short').bail() - .isLength({ max: 1000 }).withMessage('too_long'); +export const titleValidator = () => + body('title') + .trim() + .notEmpty() + .withMessage('missing') + .bail() + .isLength({ min: 3 }) + .withMessage('too_short') + .bail() + .isLength({ max: 1000 }) + .withMessage('too_long'); export const descriptionValidator = () => body('description').trim().notEmpty(); export const collectionValidator = () => body('collection').trim().notEmpty(); diff --git a/src/views/publish/tasklist.ejs b/src/views/publish/tasklist.ejs index 8de12ee..46b7172 100644 --- a/src/views/publish/tasklist.ejs +++ b/src/views/publish/tasklist.ejs @@ -42,7 +42,7 @@ <% const dim = locals.dimensions.find((d) => d.dimensionInfo.name === dimension.name) %>