Display document views (#849)

* Display who has viewed a document in the header

* Add overflow, display of WHEN last viewed
Cleanup old document attributes
Add firstViewedAt, lastViewedAt to API response

* Cleanup

* Added: API documentation for views endpoints

* Include views for deleted users
This commit is contained in:
Tom Moor
2019-01-08 22:49:20 -08:00
committed by GitHub
parent 11b0ac0c66
commit c78bf3c4bf
14 changed files with 216 additions and 123 deletions

View File

@ -32,8 +32,6 @@ async function present(ctx: Object, document: Document, options: ?Options) {
updatedAt: document.updatedAt,
updatedBy: undefined,
publishedAt: document.publishedAt,
firstViewedAt: undefined,
lastViewedAt: undefined,
team: document.teamId,
collaborators: [],
starred: !!(document.starred && document.starred.length),
@ -41,7 +39,6 @@ async function present(ctx: Object, document: Document, options: ?Options) {
pinned: undefined,
collectionId: undefined,
collection: undefined,
views: undefined,
};
if (!options.isPublic) {
@ -54,12 +51,6 @@ async function present(ctx: Object, document: Document, options: ?Options) {
data.collection = await presentCollection(ctx, document.collection);
}
if (document.views && document.views.length === 1) {
data.views = document.views[0].count;
data.firstViewedAt = document.views[0].createdAt;
data.lastViewedAt = document.views[0].updatedAt;
}
// This could be further optimized by using ctx.cache
data.collaborators = await User.findAll({
where: {