n8n-nodes-cativa
Version:
This is an n8n community node to communicate with Cativa.
76 lines • 3.77 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resourceUser = void 0;
const GenericFunctions_1 = require("../GenericFunctions");
async function resourceUser(operation, i) {
const credentials = (await this.getCredentials('cativaApi'));
const headers = {
Authorization: `${credentials.apiKey}`,
};
let responseData;
if (operation === 'getUser') {
let endpoint = 'https://backoffice.cativalab.digital/api/user/{{userId}}';
const userId = this.getNodeParameter('userId', i);
endpoint = endpoint.replace('{{userId}}', userId);
responseData = await GenericFunctions_1.apiRequest.call(this, 'GET', endpoint, {}, {}, headers);
}
else if (operation === 'createUser') {
const endpoint = 'https://backoffice.cativalab.digital/api/user';
const body = {
firstName: this.getNodeParameter('firstName', i, null),
lastName: this.getNodeParameter('lastName', i, null),
email: this.getNodeParameter('email', i, null),
password: this.getNodeParameter('password', i, null),
};
responseData = await GenericFunctions_1.apiRequest.call(this, 'POST', endpoint, body, {}, headers);
}
else if (operation === 'inviteUser') {
const endpoint = 'https://backoffice.cativalab.digital/api/customer/userInvite';
const body = {
name: this.getNodeParameter('firstName', i, null),
email: this.getNodeParameter('email', i, null),
needEmailConfirmation: this.getNodeParameter('needEmailConfirmation', i, null),
};
responseData = await GenericFunctions_1.apiRequest.call(this, 'POST', endpoint, body, {}, headers);
}
else if (operation === 'banUser') {
let endpoint = 'https://backoffice.cativalab.digital/api/user/email/{{email}}/status';
const email = this.getNodeParameter('email', i);
endpoint = endpoint.replace('{{email}}', email);
const body = {
status: 4,
};
responseData = await GenericFunctions_1.apiRequest.call(this, 'PUT', endpoint, body, {}, headers);
}
else if (operation === 'unbanUser') {
let endpoint = 'https://backoffice.cativalab.digital/api/user/email/{{email}}/status';
const email = this.getNodeParameter('email', i);
endpoint = endpoint.replace('{{email}}', email);
const body = {
status: 1,
};
responseData = await GenericFunctions_1.apiRequest.call(this, 'PUT', endpoint, body, {}, headers);
}
else if (operation === 'sendPrivateMessage') {
let endpoint = 'https://social-api.cativalab.digital/v1.1/chat/email/{{email}}';
const email = this.getNodeParameter('email', i);
endpoint = endpoint.replace('{{email}}', email);
const body = {
content: this.getNodeParameter('content', i, null),
};
responseData = await GenericFunctions_1.apiRequest.call(this, 'POST', endpoint, body, {}, headers);
}
else if (operation === 'sendPushNotification') {
let endpoint = 'https://backoffice.cativalab.digital/api/pushNotification/email/{{email}}';
const email = this.getNodeParameter('email', i);
endpoint = endpoint.replace('{{email}}', email);
const body = {
title: this.getNodeParameter('title', i, null),
description: this.getNodeParameter('description', i, null),
};
responseData = await GenericFunctions_1.apiRequest.call(this, 'POST', endpoint, body, {}, headers);
}
return responseData;
}
exports.resourceUser = resourceUser;
//# sourceMappingURL=UserMethods.js.map