Skip to content

Commit eb6833f

Browse files
committed
Merge branch 'release-4.4.5'
2 parents 4852ae6 + c976cb7 commit eb6833f

4 files changed

Lines changed: 36 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [4.4.5] (2019-01-24)
8+
9+
### Fixed
10+
11+
- [#530](https://github.com/dadi/api/issues/530): run `afterGet` hooks after field hooks
12+
713
## [4.4.4] (2018-12-20)
814

915
### Changed

dadi/lib/model/collections/get.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,37 @@ function get ({
7777
query,
7878
options
7979
})
80-
}).then(response => {
81-
if (isRestIDQuery && response.results.length === 0) {
80+
}).then(({metadata, results}) => {
81+
if (isRestIDQuery && results.length === 0) {
8282
let error = new Error('Document not found')
8383

8484
error.statusCode = 404
8585

8686
return Promise.reject(error)
8787
}
8888

89-
if (this.settings.hooks && this.settings.hooks.afterGet) {
89+
let formatter = rawOutput
90+
? Promise.resolve(results)
91+
: this.formatForOutput(
92+
results,
93+
{
94+
client,
95+
composeOverride: options.compose,
96+
language,
97+
urlFields: options.fields
98+
}
99+
)
100+
101+
return formatter.then(results => {
102+
return {results, metadata}
103+
})
104+
}).then(response => {
105+
const {hooks} = this.settings
106+
107+
if (hooks && hooks.afterGet) {
90108
return new Promise((resolve, reject) => {
91109
async.reduce(
92-
this.settings.hooks.afterGet,
110+
hooks.afterGet,
93111
response,
94112
(current, hookConfig, callback) => {
95113
let hook = new Hook(hookConfig, 'afterGet')
@@ -113,22 +131,6 @@ function get ({
113131
}
114132

115133
return response
116-
}).then(({metadata, results}) => {
117-
let formatter = rawOutput
118-
? Promise.resolve(results)
119-
: this.formatForOutput(
120-
results,
121-
{
122-
client,
123-
composeOverride: options.compose,
124-
language,
125-
urlFields: options.fields
126-
}
127-
)
128-
129-
return formatter.then(results => {
130-
return {results, metadata}
131-
})
132134
})
133135
}
134136

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dadi/api",
3-
"version": "4.4.4",
3+
"version": "4.4.5",
44
"main": "main.js",
55
"scripts": {
66
"create-client": "cd ../../.. && node ./node_modules/@dadi/api/utils/create-client.js",
@@ -21,7 +21,7 @@
2121
]
2222
},
2323
"dependencies": {
24-
"@dadi/api-validator": "^1.1.2",
24+
"@dadi/api-validator": "^1.2.0",
2525
"@dadi/boot": "^1.1.3",
2626
"@dadi/cache": "^3.0.0",
2727
"@dadi/et": "^2.0.0",

test/acceptance/validation.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ describe('Validation', function () {
8787
res.body.should.be.json
8888
res.body.success.should.be.false
8989
res.body.errors[0].field.should.equal('fieldMinLength')
90-
res.body.errors[0].message.should.equal('is too short')
90+
res.body.errors[0].code.should.equal('ERROR_MIN_LENGTH')
91+
res.body.errors[0].message.should.be.instanceOf(String)
9192

9293
done()
9394
})
@@ -124,7 +125,8 @@ describe('Validation', function () {
124125
res.body.should.be.json
125126
res.body.success.should.be.false
126127
res.body.errors[0].field.should.equal('fieldMaxLength')
127-
res.body.errors[0].message.should.equal('is too long')
128+
res.body.errors[0].code.should.equal('ERROR_MAX_LENGTH')
129+
res.body.errors[0].message.should.be.instanceOf(String)
128130

129131
done()
130132
})
@@ -161,7 +163,8 @@ describe('Validation', function () {
161163
res.body.should.be.json
162164
res.body.success.should.be.false
163165
res.body.errors[0].field.should.equal('fieldRegex')
164-
res.body.errors[0].message.should.equal('should match the pattern ^q+$')
166+
res.body.errors[0].code.should.equal('ERROR_REGEX')
167+
res.body.errors[0].message.should.be.instanceOf(String)
165168

166169
done()
167170
})

0 commit comments

Comments
 (0)