Saving and fetching of documents

This commit is contained in:
Jori Lallo
2016-05-19 20:46:34 -07:00
parent 58e588a6fd
commit 4430a3129e
14 changed files with 332 additions and 16 deletions

View File

@ -1,3 +1,5 @@
var marked = require('marked');
export function presentUser(user) {
return {
id: user.id,
@ -15,7 +17,7 @@ export function presentTeam(team) {
};
}
export function presentAtlas(atlas) {
export function presentAtlas(atlas, includeRecentDocuments=true) {
return {
id: atlas.id,
name: atlas.name,
@ -23,4 +25,24 @@ export function presentAtlas(atlas) {
type: atlas.type,
recentDocuments: atlas.getRecentDocuments(),
}
}
}
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();
data.atlas = presentAtlas(atlas, false);
}
return data;
}