Files
outline/server/presenters/document.ts
Tom Moor 91d8d27f2d feat: Render diffs in email notifications (#4164)
* deps

* diffCompact

* Diffs in email

* test

* fix: Fade deleted images
fix: Don't include empty paragraphs as context
fix: Allow for same image multiple times and refactor

* Remove target _blank

* fix: Table heading incorrect color
2022-09-24 14:29:11 -07:00

70 lines
1.8 KiB
TypeScript

import { APM } from "@server/logging/tracing";
import { Document } from "@server/models";
import DocumentHelper from "@server/models/helpers/DocumentHelper";
import presentUser from "./user";
type Options = {
isPublic?: boolean;
};
async function present(
document: Document,
options: Options | null | undefined = {}
) {
options = {
isPublic: false,
...options,
};
await document.migrateVersion();
const text = options.isPublic
? await DocumentHelper.attachmentsToSignedUrls(
document.text,
document.teamId
)
: document.text;
const data: Record<string, any> = {
id: document.id,
url: document.url,
urlId: document.urlId,
title: document.title,
text,
tasks: document.tasks,
createdAt: document.createdAt,
createdBy: undefined,
updatedAt: document.updatedAt,
updatedBy: undefined,
publishedAt: document.publishedAt,
archivedAt: document.archivedAt,
deletedAt: document.deletedAt,
teamId: document.teamId,
template: document.template,
templateId: document.templateId,
collaboratorIds: [],
revision: document.revisionCount,
fullWidth: document.fullWidth,
collectionId: undefined,
parentDocumentId: undefined,
lastViewedAt: undefined,
};
if (!!document.views && document.views.length > 0) {
data.lastViewedAt = document.views[0].updatedAt;
}
if (!options.isPublic) {
data.collectionId = document.collectionId;
data.parentDocumentId = document.parentDocumentId;
data.createdBy = presentUser(document.createdBy);
data.updatedBy = presentUser(document.updatedBy);
data.collaboratorIds = document.collaboratorIds;
}
return data;
}
export default APM.traceFunction({
serviceName: "presenter",
spanName: "document",
})(present);