From 0ce3e63dccfa2d04f653a038d919b0b62ef3f8e2 Mon Sep 17 00:00:00 2001 From: wojtek-krysiak Date: Fri, 7 Aug 2020 22:34:19 +0200 Subject: [PATCH] fix: populate record after editfixes #452 --- example-app/cypress.env.json | 2 +- src/backend/actions/edit-action.ts | 7 +++++-- src/backend/decorators/action-decorator.spec.ts | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/example-app/cypress.env.json b/example-app/cypress.env.json index a49266050..ec1ad81e1 100644 --- a/example-app/cypress.env.json +++ b/example-app/cypress.env.json @@ -1,5 +1,5 @@ { - "MONGO_URL": "mongodb://localhost:27017/e2e", + "MONGO_URL": "mongodb://localhost:27017/e2e2", "ADMIN_EMAIL": "admin@example.com", "ADMIN_PASSWORD": "password", "ADMIN_COMPANY": "default company", diff --git a/src/backend/actions/edit-action.ts b/src/backend/actions/edit-action.ts index cfefc7701..27b9cb45e 100644 --- a/src/backend/actions/edit-action.ts +++ b/src/backend/actions/edit-action.ts @@ -1,5 +1,6 @@ import Action, { RecordActionResponse } from './action.interface' import NotFoundError from '../utils/not-found-error' +import populator from '../utils/populator' /** * @implements Action @@ -38,6 +39,8 @@ const EditAction: Action = { return { record: record.toJSON(currentAdmin) } } await record.update(request.payload) + const [populatedRecord] = await populator([record]) + if (record.isValid()) { return { redirectUrl: h.resourceUrl({ resourceId: resource._decorated?.id() || resource.id() }), @@ -45,11 +48,11 @@ const EditAction: Action = { message: translateMessage('successfullyUpdated', resource.id()), type: 'success', }, - record: record.toJSON(currentAdmin), + record: populatedRecord.toJSON(currentAdmin), } } return { - record: record.toJSON(currentAdmin), + record: populatedRecord.toJSON(currentAdmin), notice: { message: translateMessage('thereWereValidationErrors'), type: 'error', diff --git a/src/backend/decorators/action-decorator.spec.ts b/src/backend/decorators/action-decorator.spec.ts index bfad8b7ae..6f2dc1c83 100644 --- a/src/backend/decorators/action-decorator.spec.ts +++ b/src/backend/decorators/action-decorator.spec.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/explicit-function-return-type */ import { expect } from 'chai' import sinon from 'sinon' import ActionDecorator from './action-decorator'