Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions components/dealcloud/actions/common/common-create-update.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { convertFieldsToProps } from "../../common/utils.mjs";
import dealcloud from "../../dealcloud.app.mjs";

export default {
methods: {
convertFieldsToProps,
isUpdate() {
return false;
},
getEntryId() {
return -1;
},
getRequestData(props) {
return {
storeRequests: Object.entries(props).map(([
key,
value,
]) => {
const fieldId = Number(key.split("_")[1]);
return {
entryId: this.getEntryId(),
fieldId,
ignoreNearDups: this.ignoreNearDups,
value,
};
}),
};
},
},
props: {
dealcloud,
entryTypeId: {
propDefinition: [
dealcloud,
"entryTypeId",
],
reloadProps: true,
},
ignoreNearDups: {
propDefinition: [
dealcloud,
"ignoreNearDups",
],
},
},
async additionalProps() {
const props = {};
if (!this.entryTypeId) {
return props;
}
const fields = await this.dealcloud.getEntryTypeFields({
entryTypeId: this.entryTypeId,
});
return this.convertFieldsToProps(fields);
},
};

40 changes: 40 additions & 0 deletions components/dealcloud/actions/create-record/create-record.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import commonCreateUpdate from "../common/common-create-update.mjs";

export default {
...commonCreateUpdate,
key: "dealcloud-create-record",
name: "Create Record",
description: "Creates a new record (entry) in DealCloud. [See the documentation](https://api.docs.dealcloud.com/docs/data/cells/postput)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: false,
},
async run({ $ }) {
/* eslint-disable no-unused-vars */
const {
dealcloud,
entryTypeId,
ignoreNearDups,
convertFieldsToProps,
isUpdate,
getEntryId,
getRequestData,
...props
} = this;
/* eslint-enable no-unused-vars */

const response = await dealcloud.createEntry({
$,
entryTypeId,
data: this.getRequestData(props),
});

$.export("$summary", "Successfully created record");
// add id to summary when we know the response schema
return response;
},
};

51 changes: 51 additions & 0 deletions components/dealcloud/actions/delete-records/delete-records.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { checkIdArray } from "../../common/utils.mjs";
import app from "../../dealcloud.app.mjs";

export default {
key: "dealcloud-delete-records",
name: "Delete Record(s)",
description: "Deletes one or more records (entries) from DealCloud. [See the documentation](https://api.docs.dealcloud.com/docs/data/delete)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: true,
openWorldHint: true,
readOnlyHint: false,
},
props: {
app,
entryTypeId: {
propDefinition: [
app,
"entryTypeId",
],
},
entryIds: {
propDefinition: [
app,
"entryId",
({ entryTypeId }) => ({
entryTypeId,
}),
],
type: "integer[]",
label: "Record ID(s)",
description: "The ID(s) of one or more records (entries) to delete.",
},
},
async run({ $ }) {
const entryIds = checkIdArray(this.entryIds).map(Number);
const response = await this.app.deleteEntry({
$,
entryTypeId: this.entryTypeId,
data: entryIds,
});

const count = response.length;
$.export("$summary", `Successfully deleted ${count} record${count === 1
? ""
: "s"}`);
return response;
},
};

55 changes: 55 additions & 0 deletions components/dealcloud/actions/get-records/get-records.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { checkIdArray } from "../../common/utils.mjs";
import dealcloud from "../../dealcloud.app.mjs";

export default {
key: "dealcloud-get-records",
name: "Get Record(s)",
description: "Retrieves one or more records (entries) from DealCloud. [See the documentation](https://api.docs.dealcloud.com/docs/data/rows/get)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: true,
},
props: {
dealcloud,
entryTypeId: {
propDefinition: [
dealcloud,
"entryTypeId",
],
},
entryIds: {
propDefinition: [
dealcloud,
"entryId",
({ entryTypeId }) => ({
entryTypeId,
}),
],
type: "integer[]",
label: "Record ID(s)",
description: "The ID(s) of one or more records (entries) to retrieve.",
},
},
async run({ $ }) {
const entryIds = checkIdArray(this.entryIds);
const response = await this.dealcloud.queryEntries({
$,
entryTypeId: this.entryTypeId,
params: {
query: `{entryid: {$in:[${entryIds.join()}]}}`,
resolveReferenceUrls: true,
wrapIntoArrays: true,
},
});

const count = response.length;
$.export("$summary", `Successfully retrieved ${count} record${count === 1
? ""
: "s"}`);
return response;
},
};

69 changes: 69 additions & 0 deletions components/dealcloud/actions/update-record/update-record.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import commonCreateUpdate from "../common/common-create-update.mjs";

const {
props: {
dealcloud, entryTypeId, ignoreNearDups,
},
} = commonCreateUpdate;

export default {
...commonCreateUpdate,
key: "dealcloud-update-record",
name: "Update Record",
description: "Updates a record (entry) in DealCloud. [See the documentation](https://api.docs.dealcloud.com/docs/data/cells/postput)",
version: "0.0.1",
type: "action",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: false,
},
props: {
dealcloud,
entryTypeId,
entryId: {
propDefinition: [
dealcloud,
"entryId",
({ entryTypeId }) => ({
entryTypeId,
}),
],
},
ignoreNearDups,
},
methods: {
...commonCreateUpdate.methods,
isUpdate() {
return true;
},
getEntryId() {
return this.entryId;
},
},
async run({ $ }) {
/* eslint-disable no-unused-vars */
const {
dealcloud,
entryTypeId,
entryId,
ignoreNearDups,
convertFieldsToProps,
isUpdate,
getEntryId,
getRequestData,
...props
} = this;
/* eslint-enable no-unused-vars */

const response = await dealcloud.updateEntry({
$,
entryTypeId,
data: this.getRequestData(props),
});

$.export("$summary", "Successfully updated record");
return response;
},
};

Loading
Loading