Skip to content
This repository was archived by the owner on Jul 8, 2020. It is now read-only.

Commit 5a84264

Browse files
committed
Allow campaigns to be fetched with their related domain
1 parent 2a1e1bb commit 5a84264

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/campaign/campaign.js

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ module.exports = function (bookshelf) {
2828

2929
organization: function () {
3030
return this.belongsTo('Organization');
31+
},
32+
33+
domain: function () {
34+
return this.belongsTo('Domain');
3135
}
3236

3337
}));

src/campaign/routes.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@ module.exports = function (server) {
2121
handler: function (request, reply) {
2222
Campaign
2323
.where({id: request.params.id})
24-
.fetch({require: true})
24+
.fetch({
25+
require: true,
26+
withRelated: request.query.expand
27+
})
2528
.then(reply)
2629
.catch(reply);
2730
},
2831
config: {
2932
validate: {
3033
params: {
3134
id: Joi.string().guid()
35+
},
36+
query: {
37+
expand: Joi.array().includes(Joi.string())
3238
}
3339
},
3440
cache: {

test/integration/specs/campaigns.js

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ module.exports = function (server) {
3434
});
3535
});
3636

37+
it('can get the campaign with the domain', function () {
38+
return server.injectThen('/campaigns/' + campaign.id + '?expand[]=domain')
39+
.then(function (response) {
40+
expect(response.statusCode).to.equal(200);
41+
expect(JSON.parse(response.payload))
42+
.to.have.deep.property('domain.id')
43+
.with.length(36);
44+
});
45+
});
46+
3747
it('responds with a 400 for non-uuid', function () {
3848
return server.injectThen('/campaigns/1')
3949
.then(function (response) {

0 commit comments

Comments
 (0)