[chore] added prettier

This commit is contained in:
Jori Lallo
2017-04-26 21:47:03 -07:00
parent fcdeb67bc5
commit 08b1609440
53 changed files with 1983 additions and 928 deletions

View File

@ -12,7 +12,7 @@ import { Document, Atlas } from '../models';
const router = new Router();
const getDocumentForId = async (id) => {
const getDocumentForId = async id => {
try {
let document;
if (isUUID(id)) {
@ -38,7 +38,7 @@ const getDocumentForId = async (id) => {
};
// FIXME: This really needs specs :/
router.post('documents.info', auth(), async (ctx) => {
router.post('documents.info', auth(), async ctx => {
const { id } = ctx.body;
ctx.assertPresent(id, 'id is required');
const document = await getDocumentForId(id);
@ -69,7 +69,7 @@ router.post('documents.info', auth(), async (ctx) => {
}
});
router.post('documents.search', auth(), async (ctx) => {
router.post('documents.search', auth(), async ctx => {
const { query } = ctx.body;
ctx.assertPresent(query, 'query is required');
@ -78,12 +78,16 @@ router.post('documents.search', auth(), async (ctx) => {
const documents = await Document.searchForUser(user, query);
const data = [];
await Promise.all(documents.map(async (document) => {
data.push(await presentDocument(ctx, document, {
includeCollection: true,
includeCollaborators: true,
}));
}));
await Promise.all(
documents.map(async document => {
data.push(
await presentDocument(ctx, document, {
includeCollection: true,
includeCollaborators: true,
})
);
})
);
ctx.body = {
pagination: ctx.state.pagination,
@ -91,14 +95,8 @@ router.post('documents.search', auth(), async (ctx) => {
};
});
router.post('documents.create', auth(), async (ctx) => {
const {
collection,
title,
text,
parentDocument,
} = ctx.body;
router.post('documents.create', auth(), async ctx => {
const { collection, title, text, parentDocument } = ctx.body;
ctx.assertPresent(collection, 'collection is required');
ctx.assertPresent(title, 'title is required');
ctx.assertPresent(text, 'text is required');
@ -115,7 +113,7 @@ router.post('documents.create', auth(), async (ctx) => {
const document = await (() => {
return new Promise(resolve => {
lock(ownerCollection.id, 10000, async (done) => {
lock(ownerCollection.id, 10000, async done => {
// FIXME: should we validate the existance of parentDocument?
let parentDocumentObj = {};
if (parentDocument && ownerCollection.type === 'atlas') {
@ -158,12 +156,8 @@ router.post('documents.create', auth(), async (ctx) => {
};
});
router.post('documents.update', auth(), async (ctx) => {
const {
id,
title,
text,
} = ctx.body;
router.post('documents.update', auth(), async ctx => {
const { id, title, text } = ctx.body;
ctx.assertPresent(id, 'id is required');
ctx.assertPresent(title, 'title is required');
ctx.assertPresent(text, 'text is required');
@ -171,7 +165,8 @@ router.post('documents.update', auth(), async (ctx) => {
const user = ctx.state.user;
const document = await getDocumentForId(id);
if (!document || document.teamId !== user.teamId) throw httpErrors.BadRequest();
if (!document || document.teamId !== user.teamId)
throw httpErrors.BadRequest();
// Update document
document.title = title;
@ -194,23 +189,22 @@ router.post('documents.update', auth(), async (ctx) => {
};
});
router.post('documents.delete', auth(), async (ctx) => {
const {
id,
} = ctx.body;
router.post('documents.delete', auth(), async ctx => {
const { id } = ctx.body;
ctx.assertPresent(id, 'id is required');
const user = ctx.state.user;
const document = await getDocumentForId(id);
const collection = await Atlas.findById(document.atlasId);
if (!document || document.teamId !== user.teamId) throw httpErrors.BadRequest();
if (!document || document.teamId !== user.teamId)
throw httpErrors.BadRequest();
// TODO: Add locking
if (collection.type === 'atlas') {
// Don't allow deletion of root docs
if (!document.parentDocumentId) {
throw httpErrors.BadRequest('Unable to delete atlas\'s root document');
throw httpErrors.BadRequest("Unable to delete atlas's root document");
}
// Delete all chilren