refactor: documents.batchImport -> collections.import

This commit is contained in:
Tom Moor
2020-12-28 18:51:12 -08:00
parent d79933887d
commit caee7afde2
10 changed files with 72 additions and 72 deletions

View File

@ -2,7 +2,6 @@
import Router from "koa-router";
import Sequelize from "sequelize";
import { subtractDate } from "../../shared/utils/date";
import documentBatchImporter from "../commands/documentBatchImporter";
import documentCreator from "../commands/documentCreator";
import documentImporter from "../commands/documentImporter";
import documentMover from "../commands/documentMover";
@ -1106,44 +1105,6 @@ router.post("documents.unpublish", auth(), async (ctx) => {
};
});
router.post("documents.batchImport", auth(), async (ctx) => {
const { type } = ctx.body;
ctx.assertIn(type, ["outline"], "type must be one of 'outline'");
if (!ctx.is("multipart/form-data")) {
throw new InvalidRequestError("Request type must be multipart/form-data");
}
const file: any = Object.values(ctx.request.files)[0];
ctx.assertPresent(file, "file is required");
if (file.type !== "application/zip") {
throw new InvalidRequestError("File type must be a zip");
}
const user = ctx.state.user;
authorize(user, "batchImport", Document);
const { documents, attachments, collections } = await documentBatchImporter({
file,
user,
type,
ip: ctx.request.ip,
});
ctx.body = {
data: {
attachmentCount: attachments.length,
documentCount: documents.length,
collectionCount: collections.length,
collections: collections.map((collection) =>
presentCollection(collection)
),
},
policies: presentPolicies(user, collections),
};
});
router.post("documents.import", auth(), async (ctx) => {
const { publish, collectionId, parentDocumentId, index } = ctx.body;