feat: Return view model from views.create (#1153)

* feat: Return view model from views.create
Towards #1152

* fix: presenter data
This commit is contained in:
Tom Moor
2020-01-11 13:46:13 -08:00
committed by GitHub
parent cd3035a692
commit e38f4996ae
2 changed files with 5 additions and 4 deletions

View File

@ -31,7 +31,7 @@ router.post('views.create', auth(), async ctx => {
const document = await Document.findByPk(documentId, { userId: user.id }); const document = await Document.findByPk(documentId, { userId: user.id });
authorize(user, 'read', document); authorize(user, 'read', document);
await View.increment({ documentId, userId: user.id }); const view = await View.increment({ documentId, userId: user.id });
await Event.create({ await Event.create({
name: 'views.create', name: 'views.create',
@ -43,8 +43,9 @@ router.post('views.create', auth(), async ctx => {
ip: ctx.request.ip, ip: ctx.request.ip,
}); });
view.user = user;
ctx.body = { ctx.body = {
success: true, data: presentView(view),
}; };
}); });

View File

@ -79,7 +79,7 @@ describe('#views.create', async () => {
const body = await res.json(); const body = await res.json();
expect(res.status).toEqual(200); 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 () => { 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(); const body = await res.json();
expect(res.status).toEqual(200); expect(res.status).toEqual(200);
expect(body.success).toBe(true); expect(body.data.count).toBe(1);
}); });
it('should require authentication', async () => { it('should require authentication', async () => {