This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/server/presenters.js

79 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-05-20 07:33:52 +00:00
import marked from 'marked';
2016-05-20 06:53:07 +00:00
import Document from './models/Document';
2016-05-20 03:46:34 +00:00
2016-04-29 05:25:37 +00:00
export function presentUser(user) {
2016-05-20 06:53:07 +00:00
return new Promise(async (resolve, reject) => {
resolve({
id: user.id,
name: user.name,
username: user.username,
email: user.email,
avatarUrl: user.slackData.profile.image_192,
});
});
2016-04-29 05:25:37 +00:00
}
export function presentTeam(team) {
2016-05-20 06:53:07 +00:00
return new Promise(async (resolve, reject) => {
resolve({
id: team.id,
name: team.name,
});
});
2016-04-29 05:25:37 +00:00
}
2016-05-07 18:52:08 +00:00
2016-05-20 06:53:07 +00:00
export function presentAtlas(atlas, includeRecentDocuments=false) {
return new Promise(async (resolve, reject) => {
const data = {
id: atlas.id,
name: atlas.name,
description: atlas.description,
type: atlas.type,
}
if (includeRecentDocuments) {
const documents = await Document.findAll({
where: {
atlasId: atlas.id,
},
limit: 10,
2016-05-20 07:33:52 +00:00
order: [
['updatedAt', 'DESC'],
],
2016-05-20 06:53:07 +00:00
});
let recentDocuments = [];
await Promise.all(documents.map(async (document) => {
recentDocuments.push(await presentDocument(document));
}))
data.recentDocuments = recentDocuments;
}
resolve(data);
});
2016-05-20 03:46:34 +00:00
}
export async function presentDocument(document, includeAtlas=false) {
const data = {
id: document.id,
title: document.title,
text: document.text,
html: marked(document.text),
createdAt: document.createdAt,
updatedAt: document.updatedAt,
atlas: document.atlaId,
team: document.teamId,
}
if (includeAtlas) {
const atlas = await document.getAtlas();
2016-05-20 06:53:07 +00:00
data.atlas = await presentAtlas(atlas, false);
2016-05-22 14:25:13 +00:00
const user = await document.getUser();
data.user = await presentUser(user, false);
2016-05-20 03:46:34 +00:00
}
return data;
}