mirror of
https://github.com/plankanban/planka.git
synced 2025-07-23 15:19:44 +02:00
parent
9ce8b2ab9c
commit
738ed19e7f
20 changed files with 537 additions and 89 deletions
|
@ -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,
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue