2025-05-10 02:09:06 +02:00
/ * !
* Copyright ( c ) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License : https : //github.com/plankanban/planka/blob/master/LICENSE.md
* /
const { POSITION _GAP } = require ( '../../../constants' ) ;
2024-04-05 22:40:35 +02:00
2022-12-16 23:48:06 +01:00
module . exports = {
inputs : {
board : {
type : 'ref' ,
required : true ,
} ,
2025-05-10 02:09:06 +02:00
lists : {
type : 'ref' ,
2022-12-16 23:48:06 +01:00
required : true ,
} ,
2025-05-10 02:09:06 +02:00
trelloBoard : {
type : 'json' ,
2024-06-12 00:51:36 +02:00
required : true ,
} ,
2022-12-16 23:48:06 +01:00
} ,
async fn ( inputs ) {
2025-05-10 02:09:06 +02:00
const convertLabelColor = ( trelloLabelColor ) =>
Label . COLORS . find ( ( color ) => color . includes ( trelloLabelColor ) ) || 'desert-sand' ;
const labelIdByTrelloLabelId = { } ;
await Promise . all (
inputs . trelloBoard . labels . map ( async ( trelloLabel , index ) => {
const { id } = await Label . qm . createOne ( {
boardId : inputs . board . id ,
position : POSITION _GAP * ( index + 1 ) ,
name : trelloLabel . name || null ,
color : convertLabelColor ( trelloLabel . color ) ,
} ) ;
labelIdByTrelloLabelId [ trelloLabel . id ] = id ;
} ) ,
) ;
2022-12-16 23:48:06 +01:00
2025-05-10 02:09:06 +02:00
const openedTrelloLists = inputs . trelloBoard . lists . filter ( ( list ) => ! list . closed ) ;
2022-12-16 23:48:06 +01:00
2025-05-10 02:09:06 +02:00
const listIdByTrelloListId = { } ;
await Promise . all (
openedTrelloLists . map ( async ( trelloList ) => {
const { id } = await List . qm . createOne ( {
boardId : inputs . board . id ,
type : List . Types . ACTIVE ,
position : trelloList . pos ,
name : trelloList . name ,
2022-12-16 23:48:06 +01:00
} ) ;
2025-05-10 02:09:06 +02:00
listIdByTrelloListId [ trelloList . id ] = id ;
} ) ,
) ;
const { id : archiveListId } = inputs . lists . find ( ( list ) => list . type === List . Types . ARCHIVE ) ;
const cardIdByTrelloCardId = { } ;
await Promise . all (
inputs . trelloBoard . cards . map ( async ( trelloCard ) => {
const values = {
boardId : inputs . board . id ,
type : Card . Types . PROJECT ,
position : trelloCard . pos ,
name : trelloCard . name ,
description : trelloCard . desc || null ,
dueDate : trelloCard . due ,
2025-07-09 17:45:47 +02:00
isClosed : trelloCard . dueComplete ,
2025-05-10 02:09:06 +02:00
listChangedAt : new Date ( ) . toISOString ( ) ,
} ;
const listId = listIdByTrelloListId [ trelloCard . idList ] ;
if ( trelloCard . closed ) {
Object . assign ( values , {
listId : archiveListId ,
prevListId : listId ,
2022-12-16 23:48:06 +01:00
} ) ;
2025-05-10 02:09:06 +02:00
} else {
values . listId = listId || archiveListId ;
}
const { id } = await Card . qm . createOne ( values ) ;
cardIdByTrelloCardId [ trelloCard . id ] = id ;
return Promise . all (
trelloCard . idLabels . map ( async ( trelloLabelId ) =>
CardLabel . qm . createOne ( {
cardId : id ,
labelId : labelIdByTrelloLabelId [ trelloLabelId ] ,
} ) ,
) ,
) ;
} ) ,
) ;
await Promise . all (
inputs . trelloBoard . checklists . map ( async ( trelloChecklist ) => {
const { id } = await TaskList . qm . createOne ( {
cardId : cardIdByTrelloCardId [ trelloChecklist . idCard ] ,
position : trelloChecklist . pos ,
name : trelloChecklist . name ,
} ) ;
2022-12-16 23:48:06 +01:00
2025-05-10 02:09:06 +02:00
return Promise . all (
trelloChecklist . checkItems . map ( async ( trelloCheckItem ) =>
Task . qm . createOne ( {
taskListId : id ,
position : trelloCheckItem . pos ,
name : trelloCheckItem . name ,
isCompleted : trelloCheckItem . state === 'complete' ,
} ) ,
) ,
) ;
} ) ,
) ;
const trelloCommentActions = inputs . trelloBoard . actions
. filter ( ( action ) => action . type === 'commentCard' )
. reverse ( ) ;
await Promise . all (
trelloCommentActions . map ( async ( trelloAction ) =>
Comment . qm . createOne ( {
cardId : cardIdByTrelloCardId [ trelloAction . data . card . id ] ,
text : ` ${ trelloAction . data . text } \n \n --- \n *Note: imported comment, originally posted by \n ${ trelloAction . memberCreator . fullName } ( ${ trelloAction . memberCreator . username } ) on ${ trelloAction . date } * ` ,
} ) ,
) ,
) ;
2022-12-16 23:48:06 +01:00
} ,
} ;