Skip to content

Commit

Permalink
patch query
Browse files Browse the repository at this point in the history
  • Loading branch information
hijiki51 committed Nov 12, 2023
1 parent 598b7d8 commit 5096b32
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions ghost/core/core/server/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -1399,15 +1399,15 @@ Post = ghostBookshelf.Model.extend({
modelOrCollection.query('columns', 'posts.*', (qb) => {
qb.count('members_created_events.id')
.from('members_created_events')
.whereRaw('posts.id = members_created_events.attribution_id')
.whereRaw('`posts`.id = members_created_events.attribution_id')
.as('count__signups');
});
},
paid_conversions(modelOrCollection) {
modelOrCollection.query('columns', 'posts.*', (qb) => {
qb.count('members_subscription_created_events.id')
.from('members_subscription_created_events')
.whereRaw('posts.id = members_subscription_created_events.attribution_id')
.whereRaw('`posts`.id = members_subscription_created_events.attribution_id')
.as('count__paid_conversions');
});
},
Expand All @@ -1419,15 +1419,14 @@ Post = ghostBookshelf.Model.extend({
qb.count('*')
.from('k')
.with('k', (q) => {
q.select('member_id')
q.select('member_id','attribution_id')
.from('members_subscription_created_events')
.whereRaw('posts.id = members_subscription_created_events.attribution_id')
.union(function () {
this.select('member_id')
.from('members_created_events')
.whereRaw('posts.id = members_created_events.attribution_id');
this.select('member_id','attribution_id')
.from('members_created_events');
});
})
.whereRaw('`k`.attribution_id = `posts`.id')
.as('count__conversions');
});
},
Expand All @@ -1436,31 +1435,31 @@ Post = ghostBookshelf.Model.extend({
qb.countDistinct('members_click_events.member_id')
.from('members_click_events')
.join('redirects', 'members_click_events.redirect_id', 'redirects.id')
.whereRaw('posts.id = redirects.post_id')
.whereRaw('`posts`.id = redirects.post_id')
.as('count__clicks');
});
},
sentiment(modelOrCollection) {
modelOrCollection.query('columns', 'posts.*', (qb) => {
qb.select(qb.client.raw('COALESCE(ROUND(AVG(score) * 100), 0)'))
.from('members_feedback')
.whereRaw('posts.id = members_feedback.post_id')
.whereRaw('`posts`.id = members_feedback.post_id')
.as('count__sentiment');
});
},
negative_feedback(modelOrCollection) {
modelOrCollection.query('columns', 'posts.*', (qb) => {
qb.count('*')
.from('members_feedback')
.whereRaw('posts.id = members_feedback.post_id AND members_feedback.score = 0')
.whereRaw('`posts`.id = members_feedback.post_id AND members_feedback.score = 0')
.as('count__negative_feedback');
});
},
positive_feedback(modelOrCollection) {
modelOrCollection.query('columns', 'posts.*', (qb) => {
qb.sum('score')
.from('members_feedback')
.whereRaw('posts.id = members_feedback.post_id')
.whereRaw('`posts`.id = members_feedback.post_id')
.as('count__positive_feedback');
});
}
Expand Down

0 comments on commit 5096b32

Please sign in to comment.