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:
@@ -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: {
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
// @flow
|
||||
import { View, User } from '../models';
|
||||
import { View } from '../models';
|
||||
import { presentUser } from '../presenters';
|
||||
|
||||
async function present(ctx: Object, view: View) {
|
||||
let data = {
|
||||
function present(ctx: Object, view: View) {
|
||||
return {
|
||||
id: view.id,
|
||||
documentId: view.documentId,
|
||||
count: view.count,
|
||||
user: undefined,
|
||||
firstViewedAt: view.createdAt,
|
||||
lastViewedAt: view.updatedAt,
|
||||
user: presentUser(ctx, view.user),
|
||||
};
|
||||
const user = await ctx.cache.get(
|
||||
view.userId,
|
||||
async () => await User.findById(view.userId)
|
||||
);
|
||||
data.user = await presentUser(ctx, user);
|
||||
return data;
|
||||
}
|
||||
|
||||
export default present;
|
||||
|
||||
Reference in New Issue
Block a user