From 4a6b5c5615077034a82eaec69671b8a35b897e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Zakrzewski?= <41862803+stanislaw-zakrzewski@users.noreply.github.com> Date: Wed, 3 Apr 2024 16:11:58 +0200 Subject: [PATCH] [75] bulk add button did not work (#120) * Allow Junior Curator to add bulk uploads * Add revision metadata to the bulk uploads * Update preprocessor Handle errors while creating caserevisions update curator data * Use logger instead of console.log --- .../src/controllers/preprocessor.ts | 45 ++++++++++++++----- .../ui/src/components/App/index.tsx | 14 +++--- .../ui/src/components/Sidebar/index.tsx | 34 ++++++++------ 3 files changed, 62 insertions(+), 31 deletions(-) diff --git a/data-serving/data-service/src/controllers/preprocessor.ts b/data-serving/data-service/src/controllers/preprocessor.ts index 61b634bc1..14478502e 100644 --- a/data-serving/data-service/src/controllers/preprocessor.ts +++ b/data-serving/data-service/src/controllers/preprocessor.ts @@ -9,6 +9,8 @@ import { CaseRevision } from '../model/case-revision'; import { Query } from 'mongoose'; import _ from 'lodash'; +import { logger } from '../util/logger'; + export const getCase = async ( request: Request, ): Promise => { @@ -75,6 +77,7 @@ export const setBatchUpsertFields = async ( response: Response, next: NextFunction, ): Promise => { + const currentDate = Date.now(); // Find and map existing cases by sourceId:sourceEntryId. const existingCasesByCaseRefCombo = new Map( (await findCasesWithCaseReferenceData(request)) @@ -104,6 +107,22 @@ export const setBatchUpsertFields = async ( ); } } + const curator = request.body.curator; + if (curator) { + c.curator = curator; + c.revisionMetadata = { + revisionNumber: 0, + creationMetadata: { + curator: curator.email, + date: currentDate, + }, + updateMetadata: { + curator: curator.email, + date: currentDate, + notes: 'Creation', + }, + }; + } }); // Clean up the additional metadata that falls outside the `case` entity. delete request.body.curator; @@ -226,14 +245,18 @@ export const createBatchDeleteCaseRevisions = async ( }); } - await CaseRevision.insertMany(casesToDelete, { - ordered: false, - rawResult: true, - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore Mongoose types don't include the `lean` option from its - // documentation: https://mongoosejs.com/docs/api.html#model_Model.insertMany - lean: true, - }); + try { + await CaseRevision.insertMany(casesToDelete, { + ordered: false, + rawResult: true, + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore Mongoose types don't include the `lean` option from its + // documentation: https://mongoosejs.com/docs/api.html#model_Model.insertMany + lean: true, + }); + } catch (err) { + logger.error(`Failed to insert some case revisions: ${err}`); + } next(); }; @@ -261,8 +284,7 @@ export const createBatchUpsertCaseRevisions = async ( lean: true, }); } catch (err) { - console.log('Failed to insert some case revisions'); - console.log(err); + logger.error(`Failed to insert some case revisions: ${err}`); } next(); @@ -297,8 +319,7 @@ export const createBatchUpdateCaseRevisions = async ( lean: true, }); } catch (err) { - console.log('Failed to insert some case revisions'); - console.log(err); + logger.error(`Failed to insert some case revisions: ${err}`); } next(); diff --git a/verification/curator-service/ui/src/components/App/index.tsx b/verification/curator-service/ui/src/components/App/index.tsx index 9cbd11c4c..d22c12a74 100644 --- a/verification/curator-service/ui/src/components/App/index.tsx +++ b/verification/curator-service/ui/src/components/App/index.tsx @@ -482,11 +482,15 @@ export default function App(): JSX.Element { )} - {user && hasAnyRole(user, [Role.Curator]) && ( - - - - )} + {user && + hasAnyRole(user, [ + Role.Curator, + Role.JuniorCurator, + ]) && ( + + + + )} {user && hasAnyRole(user, [Role.Curator]) && ( diff --git a/verification/curator-service/ui/src/components/Sidebar/index.tsx b/verification/curator-service/ui/src/components/Sidebar/index.tsx index e5e248232..11db67773 100644 --- a/verification/curator-service/ui/src/components/Sidebar/index.tsx +++ b/verification/curator-service/ui/src/components/Sidebar/index.tsx @@ -162,20 +162,26 @@ const Sidebar = ({ drawerOpen }: SidebarProps): JSX.Element => { > New bulk upload - - New automated source - - - New automated source backfill - + {hasAnyRole(user, [Role.Curator]) && ( + <> + + New automated source + + + + New automated source backfill + + + + )}