Skip to content

Commit

Permalink
Magnetic - New Components (PipedreamHQ#6017)
Browse files Browse the repository at this point in the history
* wip

* new actions

* new source

* pnpm-lock.yaml

* Add description as extra field

* pnpm-lock.yaml

---------

Co-authored-by: vunguyenhung <[email protected]>
  • Loading branch information
michelle0927 and vunguyenhung authored Apr 17, 2023
1 parent 341a6ad commit adee73e
Show file tree
Hide file tree
Showing 10 changed files with 7,039 additions and 5,748 deletions.
59 changes: 59 additions & 0 deletions components/magnetic/actions/create-contact/create-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import magnetic from "../../magnetic.app.mjs";

export default {
key: "magnetic-create-contact",
name: "Create Contact",
description: "Create a new contact. [See docs here](https://app.magnetichq.com/Magnetic/API.do#cl-contactobject)",
version: "0.0.1",
type: "action",
props: {
magnetic,
firstName: {
type: "string",
label: "First Name",
description: "First name of the new contact",
},
lastName: {
type: "string",
label: "Last Name",
description: "Last name of the new contact",
optional: true,
},
email: {
type: "string",
label: "Email",
description: "Email address of the new contact",
optional: true,
},
company: {
propDefinition: [
magnetic,
"company",
],
},
},
async run({ $ }) {
const data = {
firstName: this.firstName,
lastName: this.lastName,
email: this.email,
company: {
id: this.company,
},
contactCompany: {
id: this.company,
},
};

const response = await this.magnetic.createContact({
data,
$,
});

if (response) {
$.export("$summary", `Successfully created contact with ID ${response.id}`);
}

return response;
},
};
75 changes: 75 additions & 0 deletions components/magnetic/actions/create-grouping/create-grouping.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import magnetic from "../../magnetic.app.mjs";

export default {
key: "magnetic-create-grouping",
name: "Create Opportunity/Job",
description: "Create a new opportunity/job. [See docs here](https://app.magnetichq.com/Magnetic/API.do#ta-f-grouping)",
version: "0.0.1",
type: "action",
props: {
magnetic,
name: {
type: "string",
label: "Name",
description: "Name of the new opportunity/job",
},
description: {
type: "string",
label: "Description",
description: "Description of the new opportunity/job",
optional: true,
},
user: {
propDefinition: [
magnetic,
"user",
],
label: "Owner",
description: "The user who will be the owner of the opportunity/job",
},
contact: {
propDefinition: [
magnetic,
"contact",
],
optional: true,
},
company: {
propDefinition: [
magnetic,
"company",
],
optional: true,
},
},
async run({ $ }) {
const data = {
name: this.name,
extra: this.description,
owner: {
id: this.user,
},
contact: this.contact
? {
id: this.contact,
}
: undefined,
contactCompany: this.company
? {
id: this.company,
}
: undefined,
};

const response = await this.magnetic.createGrouping({
data,
$,
});

if (response) {
$.export("$summary", `Successfully created grouping with ID ${response.id}`);
}

return response;
},
};
98 changes: 98 additions & 0 deletions components/magnetic/actions/create-task/create-task.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import magnetic from "../../magnetic.app.mjs";

export default {
key: "magnetic-create-task",
name: "Create Task",
description: "Create a new task. [See docs here](https://app.magnetichq.com/Magnetic/API.do#ta-taskobject)",
version: "0.0.1",
type: "action",
props: {
magnetic,
name: {
type: "string",
label: "Name",
description: "Name of the new task",
},
description: {
type: "string",
label: "Description",
description: "Description of the new task",
optional: true,
},
grouping: {
propDefinition: [
magnetic,
"grouping",
],
},
user: {
propDefinition: [
magnetic,
"user",
],
optional: true,
},
billable: {
type: "boolean",
label: "Billable",
description: "Whether the time tracked on this task is billable or not",
optional: true,
},
trackedTime: {
type: "integer",
label: "Time Estimate",
description: "The estimated time for the task in minutes",
optional: true,
},
timeMinutes: {
type: "integer",
label: "Tracked Time",
description: "The time in minutes that the Task Owner has already tracked",
optional: true,
},
startDate: {
type: "string",
label: "Start Date",
description: "Start date of the new task in ISO 8601 format",
optional: true,
},
endDate: {
type: "string",
label: "End Date",
description: "End date of the new task in ISO 8601 format",
optional: true,
},
},
async run({ $ }) {
const data = {
task: this.name,
description: this.description,
billable: this.billable,
timeMinutes: this.timeMinutes,
effortMinutes: this.trackedTime,
startDate: this.startDate,
endDate: this.endDate,
grouping: this.grouping
? {
id: this.grouping,
}
: undefined,
user: this.user
? {
id: this.user,
}
: undefined,
};

const response = await this.magnetic.createOrUpdateTask({
data,
$,
});

if (response) {
$.export("$summary", `Successfully created task with ID ${response.id}`);
}

return response;
},
};
43 changes: 43 additions & 0 deletions components/magnetic/actions/find-task/find-task.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import magnetic from "../../magnetic.app.mjs";

export default {
key: "magnetic-find-task",
name: "Find Task",
description: "Search for a task by name or description [See docs here](https://app.magnetichq.com/Magnetic/API.do#ta-taskobject)",
version: "0.0.1",
type: "action",
props: {
magnetic,
searchField: {
type: "string",
label: "Search Field",
description: "Search by either name or description",
options: [
"name",
"description",
],
},
searchValue: {
type: "string",
label: "Search Value",
description: "Text to search for",
},
},
async run({ $ }) {
const response = await this.magnetic.listTasks({
params: {
searchField: this.searchField === "name"
? "task"
: this.searchField,
searchValue: this.searchValue,
},
$,
});
if (response) {
$.export("$summary", `Found ${response.length} task${response.length === 1
? ""
: "s"}`);
}
return response;
},
};
47 changes: 47 additions & 0 deletions components/magnetic/actions/log-time-on-task/log-time-on-task.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import magnetic from "../../magnetic.app.mjs";

export default {
key: "magnetic-log-time-on-task",
name: "Log Time on Task",
description: "Log time on an existing task. [See docs here](https://app.magnetichq.com/Magnetic/API.do#ta-taskobject)",
version: "0.0.1",
type: "action",
props: {
magnetic,
task: {
propDefinition: [
magnetic,
"task",
],
},
trackedTime: {
type: "integer",
label: "Tracked Time",
description: "The time tracked in minutes to add to the task",
},
},
async run({ $ }) {
const task = await this.magnetic.getTask({
params: {
id: this.task,
},
$,
});

const data = {
...task,
timeMinutes: this.trackedTime + task.timeMinutes,
};

const response = await this.magnetic.createOrUpdateTask({
data,
$,
});

if (response) {
$.export("$summary", `Successfully updated task with ID ${response.id}`);
}

return response;
},
};
9 changes: 9 additions & 0 deletions components/magnetic/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const API_PATH = {
CORE_API: "/coreAPI",
TASKS_API: "/tasksAPI",
CLIENTS_API: "/clientsAPI",
};

export default {
API_PATH,
};
Loading

0 comments on commit adee73e

Please sign in to comment.