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:
@ -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),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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 () => {
|
||||||
|
Reference in New Issue
Block a user