Skip to content

Commit

Permalink
Merge pull request #542 from SoftwareBrothers/fix/452-populate-edit-a…
Browse files Browse the repository at this point in the history
…ction

fix: populate record after editfixes #452
  • Loading branch information
wojtek-krysiak committed Aug 7, 2020
2 parents 411698a + 0ce3e63 commit 9b126d3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion example-app/cypress.env.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 5 additions & 2 deletions src/backend/actions/edit-action.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Action, { RecordActionResponse } from './action.interface'
import NotFoundError from '../utils/not-found-error'
import populator from '../utils/populator'

/**
* @implements Action
Expand Down Expand Up @@ -38,18 +39,20 @@ const EditAction: Action<RecordActionResponse> = {
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() }),
notice: {
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',
Expand Down
1 change: 1 addition & 0 deletions src/backend/decorators/action-decorator.spec.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit 9b126d3

Please sign in to comment.