Skip to content

Commit

Permalink
[75] bulk add button did not work (#120)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
stanislaw-zakrzewski committed Apr 3, 2024
1 parent 115a67d commit 4a6b5c5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 31 deletions.
45 changes: 33 additions & 12 deletions data-serving/data-service/src/controllers/preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CaseDocument | null> => {
Expand Down Expand Up @@ -75,6 +77,7 @@ export const setBatchUpsertFields = async (
response: Response,
next: NextFunction,
): Promise<void> => {
const currentDate = Date.now();
// Find and map existing cases by sourceId:sourceEntryId.
const existingCasesByCaseRefCombo = new Map(
(await findCasesWithCaseReferenceData(request))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
};
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 9 additions & 5 deletions verification/curator-service/ui/src/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,15 @@ export default function App(): JSX.Element {
<AutomatedSourceForm onModalClose={onModalClose} />
</Route>
)}
{user && hasAnyRole(user, [Role.Curator]) && (
<Route path="/cases/bulk">
<BulkCaseForm onModalClose={onModalClose} />
</Route>
)}
{user &&
hasAnyRole(user, [
Role.Curator,
Role.JuniorCurator,
]) && (
<Route path="/cases/bulk">
<BulkCaseForm onModalClose={onModalClose} />
</Route>
)}
{user && hasAnyRole(user, [Role.Curator]) && (
<Route path="/sources/backfill">
<AutomatedBackfill onModalClose={onModalClose} />
Expand Down
34 changes: 20 additions & 14 deletions verification/curator-service/ui/src/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,26 @@ const Sidebar = ({ drawerOpen }: SidebarProps): JSX.Element => {
>
<MenuItem>New bulk upload</MenuItem>
</Link>
<Link
to="/sources/automated"
onClick={closeCreateNewPopup}
className={classes.link}
>
<MenuItem>New automated source</MenuItem>
</Link>
<Link
to="/sources/backfill"
onClick={closeCreateNewPopup}
className={classes.link}
>
<MenuItem>New automated source backfill</MenuItem>
</Link>
{hasAnyRole(user, [Role.Curator]) && (
<>
<Link
to="/sources/automated"
onClick={closeCreateNewPopup}
className={classes.link}
>
<MenuItem>New automated source</MenuItem>
</Link>
<Link
to="/sources/backfill"
onClick={closeCreateNewPopup}
className={classes.link}
>
<MenuItem>
New automated source backfill
</MenuItem>
</Link>
</>
)}
</Menu>
</>
<List>
Expand Down

0 comments on commit 4a6b5c5

Please sign in to comment.