Skip to content

Commit

Permalink
fix: edit action updates context.record
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtek-krysiak committed Oct 12, 2020
1 parent 8760ab0 commit d18f296
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/backend/actions/edit/edit-action.ts
Expand Up @@ -29,7 +29,7 @@ export const EditAction: Action<RecordActionResponse> = {
* @memberof module:EditAction
*/
handler: async (request, response, data) => {
const { record, resource, currentAdmin, h, translateMessage } = data
const { record, resource, currentAdmin, h, translateMessage, context } = data
if (!record) {
throw new NotFoundError([
`Record of given id ("${request.params.recordId}") could not be found`,
Expand All @@ -38,8 +38,12 @@ export const EditAction: Action<RecordActionResponse> = {
if (request.method === 'get') {
return { record: record.toJSON(currentAdmin) }
}
await record.update(request.payload)
const [populatedRecord] = await populator([record])

const newRecord = await record.update(request.payload)
const [populatedRecord] = await populator([newRecord])

// eslint-disable-next-line no-param-reassign
context.record = populatedRecord

if (record.isValid()) {
return {
Expand Down

0 comments on commit d18f296

Please sign in to comment.