feat(trello): add create card action
This commit is contained in:
189
packages/backend/src/apps/trello/actions/create-card/index.ts
Normal file
189
packages/backend/src/apps/trello/actions/create-card/index.ts
Normal file
@@ -0,0 +1,189 @@
|
||||
import { IJSONArray, IJSONObject } from '@automatisch/types';
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Create card',
|
||||
key: 'createCard',
|
||||
description: 'Creates a new card within a specified board and list.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Board',
|
||||
key: 'boardId',
|
||||
type: 'dropdown' as const,
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listBoards',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'List',
|
||||
key: 'listId',
|
||||
type: 'dropdown' as const,
|
||||
required: true,
|
||||
dependsOn: ['parameters.boardId'],
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listBoardLists',
|
||||
},
|
||||
{
|
||||
name: 'parameters.boardId',
|
||||
value: '{parameters.boardId}',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Name',
|
||||
key: 'name',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: true,
|
||||
description: '',
|
||||
},
|
||||
{
|
||||
label: 'Description',
|
||||
key: 'description',
|
||||
type: 'string' as const,
|
||||
required: false,
|
||||
variables: true,
|
||||
description: '',
|
||||
},
|
||||
|
||||
{
|
||||
label: 'Label',
|
||||
key: 'label',
|
||||
type: 'dropdown' as const,
|
||||
required: false,
|
||||
dependsOn: ['parameters.boardId'],
|
||||
description: 'Select a color tag to attach to the card.',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listBoardLabels',
|
||||
},
|
||||
{
|
||||
name: 'parameters.boardId',
|
||||
value: '{parameters.boardId}',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Card Position',
|
||||
key: 'cardPosition',
|
||||
type: 'dropdown' as const,
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
options: [
|
||||
{
|
||||
label: 'top',
|
||||
value: 'top',
|
||||
},
|
||||
{
|
||||
label: 'bottom',
|
||||
value: 'bottom',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Members',
|
||||
key: 'memberIds',
|
||||
type: 'dynamic' as const,
|
||||
required: false,
|
||||
description: '',
|
||||
fields: [
|
||||
{
|
||||
label: 'Member',
|
||||
key: 'memberId',
|
||||
type: 'dropdown' as const,
|
||||
required: false,
|
||||
dependsOn: ['parameters.boardId'],
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listMembers',
|
||||
},
|
||||
{
|
||||
name: 'parameters.boardId',
|
||||
value: '{parameters.boardId}',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Due Date',
|
||||
key: 'dueDate',
|
||||
type: 'string' as const,
|
||||
required: false,
|
||||
variables: true,
|
||||
description: 'Format: mm-dd-yyyy HH:mm:ss or yyyy-MM-dd HH:mm:ss.',
|
||||
},
|
||||
{
|
||||
label: 'URL Attachment',
|
||||
key: 'urlSource',
|
||||
type: 'string' as const,
|
||||
required: false,
|
||||
variables: true,
|
||||
description: 'A URL to attach to the card.',
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const {
|
||||
listId,
|
||||
name,
|
||||
description,
|
||||
cardPosition,
|
||||
dueDate,
|
||||
label,
|
||||
urlSource,
|
||||
} = $.step.parameters;
|
||||
|
||||
const memberIds = $.step.parameters.memberIds as IJSONArray;
|
||||
const idMembers = memberIds.map(
|
||||
(memberId: IJSONObject) => memberId.memberId
|
||||
);
|
||||
|
||||
const fields = {
|
||||
name,
|
||||
desc: description,
|
||||
idList: listId,
|
||||
pos: cardPosition,
|
||||
due: dueDate,
|
||||
idMembers: idMembers.join(','),
|
||||
idLabels: label,
|
||||
urlSource,
|
||||
};
|
||||
|
||||
const response = await $.http.post('/1/cards', fields);
|
||||
|
||||
$.setActionItem({ raw: response.data });
|
||||
},
|
||||
});
|
3
packages/backend/src/apps/trello/actions/index.ts
Normal file
3
packages/backend/src/apps/trello/actions/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import createCard from './create-card';
|
||||
|
||||
export default [createCard];
|
@@ -5,6 +5,8 @@ const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
requestConfig.headers.Authorization = `OAuth oauth_consumer_key="${$.auth.data.apiKey}", oauth_token="${$.auth.data.token}"`;
|
||||
}
|
||||
|
||||
requestConfig.headers.Accept = 'application/json';
|
||||
|
||||
return requestConfig;
|
||||
};
|
||||
|
||||
|
6
packages/backend/src/apps/trello/dynamic-data/index.ts
Normal file
6
packages/backend/src/apps/trello/dynamic-data/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import listBoardLabels from './list-board-labels';
|
||||
import listBoardLists from './list-board-lists';
|
||||
import listBoards from './list-boards';
|
||||
import listMembers from './listMembers';
|
||||
|
||||
export default [listBoardLabels, listBoardLists, listBoards, listMembers];
|
@@ -0,0 +1,39 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default {
|
||||
name: 'List board labels',
|
||||
key: 'listBoardLabels',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const boardLabels: {
|
||||
data: IJSONObject[];
|
||||
} = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
const boardId = $.step.parameters.boardId;
|
||||
|
||||
if (!boardId) {
|
||||
return boardLabels;
|
||||
}
|
||||
|
||||
const params = {
|
||||
fields: 'color',
|
||||
};
|
||||
|
||||
const { data } = await $.http.get(`/1/boards/${boardId}/labels`, {
|
||||
params,
|
||||
});
|
||||
|
||||
if (data?.length) {
|
||||
for (const boardLabel of data) {
|
||||
boardLabels.data.push({
|
||||
value: boardLabel.id,
|
||||
name: boardLabel.color,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return boardLabels;
|
||||
},
|
||||
};
|
@@ -0,0 +1,33 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default {
|
||||
name: 'List board lists',
|
||||
key: 'listBoardLists',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const boards: {
|
||||
data: IJSONObject[];
|
||||
} = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
const boardId = $.step.parameters.boardId;
|
||||
|
||||
if (!boardId) {
|
||||
return boards;
|
||||
}
|
||||
|
||||
const { data } = await $.http.get(`/1/boards/${boardId}/lists`);
|
||||
|
||||
if (data?.length) {
|
||||
for (const list of data) {
|
||||
boards.data.push({
|
||||
value: list.id,
|
||||
name: list.name,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return boards;
|
||||
},
|
||||
};
|
@@ -0,0 +1,27 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default {
|
||||
name: 'List boards',
|
||||
key: 'listBoards',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const boards: {
|
||||
data: IJSONObject[];
|
||||
} = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
const { data } = await $.http.get(`/1/members/me/boards`);
|
||||
|
||||
if (data?.length) {
|
||||
for (const board of data) {
|
||||
boards.data.push({
|
||||
value: board.id,
|
||||
name: board.name,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return boards;
|
||||
},
|
||||
};
|
@@ -0,0 +1,33 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default {
|
||||
name: 'List members',
|
||||
key: 'listMembers',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const members: {
|
||||
data: IJSONObject[];
|
||||
} = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
const boardId = $.step.parameters.boardId;
|
||||
|
||||
if (!boardId) {
|
||||
return members;
|
||||
}
|
||||
|
||||
const { data } = await $.http.get(`/1/boards/${boardId}/members`);
|
||||
|
||||
if (data?.length) {
|
||||
for (const member of data) {
|
||||
members.data.push({
|
||||
value: member.id,
|
||||
name: member.fullName,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return members;
|
||||
},
|
||||
};
|
@@ -1,6 +1,8 @@
|
||||
import defineApp from '../../helpers/define-app';
|
||||
import addAuthHeader from './common/add-auth-header';
|
||||
import auth from './auth';
|
||||
import actions from './actions';
|
||||
import dynamicData from './dynamic-data';
|
||||
|
||||
export default defineApp({
|
||||
name: 'Trello',
|
||||
@@ -13,4 +15,6 @@ export default defineApp({
|
||||
primaryColor: '0079bf',
|
||||
beforeRequest: [addAuthHeader],
|
||||
auth,
|
||||
actions,
|
||||
dynamicData,
|
||||
});
|
||||
|
Reference in New Issue
Block a user