diff --git a/server/api/views.js b/server/api/views.js index 06780f24..f64760b9 100644 --- a/server/api/views.js +++ b/server/api/views.js @@ -31,7 +31,7 @@ router.post('views.create', auth(), async ctx => { const document = await Document.findByPk(documentId, { userId: user.id }); authorize(user, 'read', document); - await View.increment({ documentId, userId: user.id }); + const view = await View.increment({ documentId, userId: user.id }); await Event.create({ name: 'views.create', @@ -43,8 +43,9 @@ router.post('views.create', auth(), async ctx => { ip: ctx.request.ip, }); + view.user = user; ctx.body = { - success: true, + data: presentView(view), }; }); diff --git a/server/api/views.test.js b/server/api/views.test.js index 099d1af4..2325352c 100644 --- a/server/api/views.test.js +++ b/server/api/views.test.js @@ -79,7 +79,7 @@ describe('#views.create', async () => { const body = await res.json(); expect(res.status).toEqual(200); - expect(body.success).toBe(true); + expect(body.data.count).toBe(1); }); it('should allow creating a view record for document in read-only collection', async () => { @@ -100,7 +100,7 @@ describe('#views.create', async () => { const body = await res.json(); expect(res.status).toEqual(200); - expect(body.success).toBe(true); + expect(body.data.count).toBe(1); }); it('should require authentication', async () => {