Skip to content

Commit

Permalink
fix(imports): Pass entity model instead of JSON to search indexing
Browse files Browse the repository at this point in the history
The ORM functions have been changed to return the Bookshelf model.
  • Loading branch information
kellnerd committed Jul 9, 2024
1 parent f289c71 commit 148bd95
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/server/routes/import-entity/import-routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,23 @@ export async function approveImportEntity(req, res: Response) {
const {orm} = res.app.locals;
const editorId = req.session.passport.user.id;
const {importEntity} = res.locals;
const entity = await orm.bookshelf.transaction((transacting) =>
const savedEntityModel = await orm.bookshelf.transaction((transacting) =>
orm.func.imports.approveImport(
{editorId, importEntity, orm, transacting}
));
const entityUrl = getEntityUrl(entity);
const entityJSON = savedEntityModel.toJSON();
const entityUrl = getEntityUrl(entityJSON);

/* Add code to remove import and add the newly created entity to the elastic
search index and remove delete import */

// Update editor achievement
entity.alert = (await achievement.processEdit(
orm, editorId, entity.revisionId
entityJSON.alert = (await achievement.processEdit(
orm, editorId, entityJSON.revisionId
)).alert;

// Cleanup search indexing
search.indexEntity(entity);
search.indexEntity(savedEntityModel);
// Todo: Add functionality to remove imports from ES index upon deletion

res.redirect(entityUrl);
Expand All @@ -157,7 +158,7 @@ export function editImportEntity(req: Request, res: Response) {
markup,
props: escapeProps(props),
script: '/js/entity-editor.js',
title: 'Edit Work Import'
title: 'Edit Import'
}));
}

Expand All @@ -177,23 +178,24 @@ export async function approveImportPostEditing(req, res) {

const entityData = transformForm[type](formData);

const entity = await orm.bookshelf.transaction(async (transacting) => {
const savedEntityModel = await orm.bookshelf.transaction(async (transacting) => {
await orm.func.imports.deleteImport(
transacting, importId
);
return orm.func.createEntity(
{editorId, entityData, orm, transacting}
);
});
const entityJSON = savedEntityModel.toJSON();

// Update editor achievement
entity.alert = (await achievement.processEdit(
orm, editorId, entity.revisionId
entityJSON.alert = (await achievement.processEdit(
orm, editorId, entityJSON.revisionId
)).alert;

// Cleanup search indexing
await search.indexEntity(entity);
await search.indexEntity(savedEntityModel);
// To-do: Add code to remove importEntity from the search index

res.send(entity);
res.send(entityJSON);
}

0 comments on commit 148bd95

Please sign in to comment.