Skip to content

Commit

Permalink
Merge pull request #6 from Konecty/konecty-save
Browse files Browse the repository at this point in the history
Create new nodes for Konecty Integration
  • Loading branch information
silveirado authored Aug 28, 2019
2 parents aa09454 + e5bccc5 commit 79b3717
Show file tree
Hide file tree
Showing 22 changed files with 2,805 additions and 405 deletions.
38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
Running node module locally:
![Konecty](logo-konecty.png)

In the directory containing the node’s package.json file, run: sudo npm link
# Konecty Integration Nodes

In your node-red user directory, typically ~/.node-red run: npm link node-red-contrib-konecty
With these nodes, you can visually create full-featured flows to improve your business.


## Getting started

Install [Node-RED](http://nodered.org/docs/getting-started/installation), if you don't get it done before

```
$ sudo npm install -g node-red
```

Then go to the node-red directory `~/.node-red` and install the package

```
$ cd ~/.node-red
$ npm install node-red-contrib-konecty
```

Then run

```
node-red
```

# Credits

Thanks to our core team
[Derotino Silveira](https://github.com/silveirado),
[Marcus de Moura](https://github.com/marcusdemoura),
[Leonardo Viva](https://github.com/7sete7),
[Vinícius Freitas](https://github.com/viniciustinga)

A special thanks for [Luciano Costa](https://github.com/lucianocosta) for your help to make this possible, and our awesome [contributors](https://github.com/Konecty/node-red-contrib-konecty/graphs/contributors).
163 changes: 163 additions & 0 deletions api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
const axios = require('axios');

module.exports = ({ host, key }) => ({
async getDocuments() {
const { data } = await axios.get(`${host}/rest/menu/documents`, {
headers: {
Authorization: key
}
});
return data;
},
async getDocument(id) {
const { data } = await axios.get(`${host}/rest/menu/documents/${id}`, {
headers: {
Authorization: key
}
});
return data;
},
async getMenu(id) {
const { data } = await axios.get(`${host}/rest/menu/list`, {
headers: {
Authorization: key
}
});
return data;
},
async getSuggestions(document, field, search) {
const { data } = await axios.get(`${host}/rest/data/${document}/lookup/${field}`, {
headers: {
Authorization: key
},
params: {
page: 1,
start: 0,
limit: 10,
search
}
});
return data;
},
async getIdFromCode(document, code) {
const { data } = await axios.get(`${host}/rest/data/${document}/find`, {
headers: {
Authorization: key
},
params: {
limit: 1,
filter: { match: 'and', conditions: [{ term: 'code', operator: 'equals', value: Number(code) }] },
fields: '_id, _updatedAt'
}
});
if (data.success === true && data.total === 1) {
const {
data: [{ _id, _updatedAt }]
} = data;
return { _id, _updatedAt: { $date: _updatedAt } };
}
return {};
},
async getIdFromId(document, id) {
const { data } = await axios.get(`${host}/rest/data/${document}/${id}`, {
headers: {
Authorization: key
},
params: {
fields: '_id, _updatedAt'
}
});
if (data.success === true && data.total === 1) {
const {
data: [{ _id, _updatedAt }]
} = data;
return { _id, _updatedAt: { $date: _updatedAt } };
}
return {};
},
async update(document, ids, data) {
const { data: result } = await axios.put(
`${host}/rest/data/${document}`,
{
data,
ids
},
{
headers: {
Authorization: key
}
}
);

return result;
},
async create(document, body) {
const { data: result } = await axios.post(`${host}/rest/data/${document}`, body, {
headers: {
Authorization: key
}
});

return result;
},
async getSuggestionsForDocument(document, field, search) {
const { data } = await axios.get(`${host}/rest/data/${document}/find`, {
headers: {
Authorization: key
},
params: {
limit: 20,
filter: { match: 'and', conditions: [{ term: field, operator: 'contains', value: search }] },
fields: `_id, ${field}`,
sort: [{ property: field, direction: 'ASC' }]
}
});
return data;
},
async getNextOnQueue(queueId) {
const { data } = await axios.get(`${host}/rest/data/Queue/queue/next/${queueId}`, {
headers: {
Authorization: key
}
});
return data;
},
async createContact(contactData) {
const { data } = await axios.post(
`${host}/rest/process/submit`,
{
data: [
{
name: 'contact',
data: contactData
}
]
},
{
headers: {
Authorization: key
}
}
);
return data;
},
async createOpportunity(opportunityData) {
const { data } = await axios.post(
`${host}/rest/process/submit`,
{
data: [
{
name: 'opportunity',
data: opportunityData
}
]
},
{
headers: {
Authorization: key
}
}
);
return data;
}
});
Binary file added icons/konecty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 79b3717

Please sign in to comment.