Moar
This commit is contained in:
parent
f90d170497
commit
f08ca8d460
14
index.js
14
index.js
|
@ -1,13 +1,13 @@
|
||||||
require('./init');
|
require('./init');
|
||||||
var app = require('./server').default;
|
const app = require('./server').default;
|
||||||
var http = require('http');
|
const http = require('http');
|
||||||
|
|
||||||
var server = http.createServer(app.callback());
|
const server = http.createServer(app.callback());
|
||||||
server.listen(process.env.PORT || '3000');
|
server.listen(process.env.PORT || '3000');
|
||||||
server.on('error', (err) => {
|
server.on('error', err => {
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
server.on('listening', () => {
|
server.on('listening', () => {
|
||||||
var address = server.address();
|
const address = server.address();
|
||||||
console.log('Listening on %s%s', address.address, address.port);
|
console.log(`Listening on http://localhost:${address.port}`);
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,7 +5,7 @@ import httpErrors from 'http-errors';
|
||||||
import auth from './middlewares/authentication';
|
import auth from './middlewares/authentication';
|
||||||
import pagination from './middlewares/pagination';
|
import pagination from './middlewares/pagination';
|
||||||
import { presentDocument } from '../presenters';
|
import { presentDocument } from '../presenters';
|
||||||
import { User, Document, Collection, Star, View } from '../models';
|
import { Document, Collection, Star, View } from '../models';
|
||||||
|
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
router.post('documents.list', auth(), pagination(), async ctx => {
|
router.post('documents.list', auth(), pagination(), async ctx => {
|
||||||
|
@ -118,7 +118,6 @@ router.post('documents.search', auth(), async ctx => {
|
||||||
documents.map(async document => {
|
documents.map(async document => {
|
||||||
data.push(
|
data.push(
|
||||||
await presentDocument(ctx, document, {
|
await presentDocument(ctx, document, {
|
||||||
includeCollection: true,
|
|
||||||
includeCollaborators: true,
|
includeCollaborators: true,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -206,9 +205,7 @@ router.post('documents.create', auth(), async ctx => {
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
data: await presentDocument(ctx, newDocument, {
|
data: await presentDocument(ctx, newDocument, {
|
||||||
includeCollection: true,
|
|
||||||
includeCollaborators: true,
|
includeCollaborators: true,
|
||||||
collection: ownerCollection,
|
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -236,9 +233,7 @@ router.post('documents.update', auth(), async ctx => {
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
data: await presentDocument(ctx, document, {
|
data: await presentDocument(ctx, document, {
|
||||||
includeCollection: true,
|
|
||||||
includeCollaborators: true,
|
includeCollaborators: true,
|
||||||
collection: collection,
|
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -279,7 +274,6 @@ router.post('documents.move', auth(), async ctx => {
|
||||||
|
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
data: await presentDocument(ctx, document, {
|
data: await presentDocument(ctx, document, {
|
||||||
includeCollection: true,
|
|
||||||
includeCollaborators: true,
|
includeCollaborators: true,
|
||||||
collection: collection,
|
collection: collection,
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { Star, User, Document, View } from '../models';
|
import { User, Document, View } from '../models';
|
||||||
import presentUser from './user';
|
import presentUser from './user';
|
||||||
import presentCollection from './collection';
|
import presentCollection from './collection';
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@ async function present(ctx: Object, document: Document, options: Object = {}) {
|
||||||
text: document.text,
|
text: document.text,
|
||||||
html: document.html,
|
html: document.html,
|
||||||
preview: document.preview,
|
preview: document.preview,
|
||||||
collection: presentCollection(ctx, document.collection),
|
|
||||||
createdAt: document.createdAt,
|
createdAt: document.createdAt,
|
||||||
createdBy: presentUser(ctx, document.createdBy),
|
createdBy: presentUser(ctx, document.createdBy),
|
||||||
updatedAt: document.updatedAt,
|
updatedAt: document.updatedAt,
|
||||||
|
@ -27,9 +26,14 @@ async function present(ctx: Object, document: Document, options: Object = {}) {
|
||||||
team: document.teamId,
|
team: document.teamId,
|
||||||
collaborators: [],
|
collaborators: [],
|
||||||
starred: !!document.starred,
|
starred: !!document.starred,
|
||||||
|
collection: undefined,
|
||||||
views: undefined,
|
views: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (options.includeCollection) {
|
||||||
|
data.collection = presentCollection(ctx, document.collection);
|
||||||
|
}
|
||||||
|
|
||||||
if (options.includeViews) {
|
if (options.includeViews) {
|
||||||
data.views = await View.sum('count', {
|
data.views = await View.sum('count', {
|
||||||
where: { documentId: document.id },
|
where: { documentId: document.id },
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
function present(ctx, team) {
|
// @flow
|
||||||
|
import { Team } from '../models';
|
||||||
|
|
||||||
|
function present(ctx: Object, team: Team) {
|
||||||
ctx.cache.set(team.id, team);
|
ctx.cache.set(team.id, team);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Reference in New Issue