1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-23 15:19:44 +02:00

feat: Trello board JSON import (#352)

Closes #27, closes #105
This commit is contained in:
Christoph Enne 2022-12-16 23:48:06 +01:00 committed by GitHub
parent 9ce8b2ab9c
commit 738ed19e7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 537 additions and 89 deletions

View file

@ -1,7 +1,16 @@
const util = require('util');
const { v4: uuid } = require('uuid');
const Errors = {
PROJECT_NOT_FOUND: {
projectNotFound: 'Project not found',
},
NO_IMPORT_FILE_WAS_UPLOADED: {
noImportFileWasUploaded: 'No import file was uploaded',
},
INVALID_IMPORT_FILE: {
invalidImportFile: 'Invalid import file',
},
};
module.exports = {
@ -24,12 +33,26 @@ module.exports = {
type: 'string',
required: true,
},
importType: {
type: 'string',
isIn: Object.values(Board.ImportTypes),
},
requestId: {
type: 'string',
isNotEmptyString: true,
},
},
exits: {
projectNotFound: {
responseType: 'notFound',
},
noImportFileWasUploaded: {
responseType: 'unprocessableEntity',
},
uploadError: {
responseType: 'unprocessableEntity',
},
},
async fn(inputs) {
@ -49,10 +72,42 @@ module.exports = {
const values = _.pick(inputs, ['type', 'position', 'name']);
let boardImport;
if (inputs.importType && Object.values(Board.ImportTypes).includes(inputs.importType)) {
const upload = util.promisify((options, callback) =>
this.req.file('importFile').upload(options, (error, files) => callback(error, files)),
);
let files;
try {
files = await upload({
saveAs: uuid(),
maxBytes: null,
});
} catch (error) {
return exits.uploadError(error.message); // TODO: add error
}
if (files.length === 0) {
throw Errors.NO_IMPORT_FILE_WAS_UPLOADED;
}
const file = _.last(files);
if (inputs.importType === Board.ImportTypes.TRELLO) {
boardImport = {
type: inputs.importType,
board: await sails.helpers.boards.processUploadedTrelloImportFile(file),
};
}
}
const { board, boardMembership } = await sails.helpers.boards.createOne(
values,
boardImport,
currentUser,
project,
inputs.requestId,
this.req,
);