Api Credentials ophalen via route, Postcodes capslock maken + aan elkaar, BV infix toevoegen aan Bestteling URL
This commit is contained in:
@@ -6,17 +6,14 @@
|
||||
/* global document, Office */
|
||||
import axios from "axios";
|
||||
|
||||
const api_tokens = {
|
||||
prod: "Uvk3eiHf2NB8ahRC1ijXp0N1YrrhZ1eakIG9gTA0",
|
||||
};
|
||||
|
||||
// axios conf
|
||||
axios.defaults.headers.common["api-key"] = api_tokens.prod;
|
||||
axios.defaults.headers.common["api-language"] = "nl";
|
||||
|
||||
// url = https://backoffice.sociale-controle.nl
|
||||
const localApiUrl = "https://backoffice.sociale-controle.nl/api/zoek_bestelling";
|
||||
const orderUrlEdit = "https://backoffice.sociale-controle.nl/bestellingen/edit/";
|
||||
const orderUrlIndex = "https://backoffice.sociale-controle.nl/bestellingen";
|
||||
const apiCredentialUrl = "https://backoffice.sociale-controle.nl/api/api_credentials";
|
||||
|
||||
Office.onReady((info) => {
|
||||
if (info.host === Office.HostType.Outlook) {
|
||||
@@ -55,6 +52,19 @@ export async function run() {
|
||||
showResults(results);
|
||||
}
|
||||
|
||||
async function getApiCredential() {
|
||||
let key = [];
|
||||
|
||||
await axios
|
||||
.get(apiCredentialUrl)
|
||||
.then(function (res) {
|
||||
key = res.data.key ?? "";
|
||||
})
|
||||
.catch((err) => err);
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
// Animation function for loader on button
|
||||
function loadAnimation(animate) {
|
||||
const loadButton = document.getElementById("run");
|
||||
@@ -78,9 +88,14 @@ function loadAnimation(animate) {
|
||||
async function search(searchInfo) {
|
||||
let results = [];
|
||||
|
||||
let key = await getApiCredential();
|
||||
|
||||
await axios
|
||||
.get(localApiUrl, {
|
||||
params: searchInfo,
|
||||
headers: {
|
||||
"api-key": key,
|
||||
},
|
||||
})
|
||||
.then(function (res) {
|
||||
results = res.data.results ?? [];
|
||||
@@ -107,8 +122,11 @@ function getInitials(name) {
|
||||
|
||||
function getPostalCodesFromText(emailBody) {
|
||||
const regex = /\b\d{4}\s?[A-Z]{2}\b/g;
|
||||
let postalCodes = emailBody.match(regex);
|
||||
|
||||
return btoa(emailBody.match(regex));
|
||||
let postalCodesWithoutWhiteSpaces = postalCodes.map((i) => i.replace(/\s/g, "").toUpperCase());
|
||||
|
||||
return btoa(postalCodesWithoutWhiteSpaces);
|
||||
}
|
||||
|
||||
function showResults(results) {
|
||||
@@ -117,15 +135,15 @@ function showResults(results) {
|
||||
|
||||
if (results.length > 0) {
|
||||
results.forEach((result) => {
|
||||
resultDiv.innerHTML += resultsFoundButton(result.id, result.lastname);
|
||||
resultDiv.innerHTML += resultsFoundButton(result.id, result.lastname, result.url_infix);
|
||||
});
|
||||
} else {
|
||||
resultDiv.innerHTML = noResultsFoundButton();
|
||||
}
|
||||
}
|
||||
|
||||
function resultsFoundButton(id, customer) {
|
||||
return `<button type="button" target="_blank" onclick="location.href='${orderUrlEdit}${id}'" class="result-button" style="text-decoration: none;">
|
||||
function resultsFoundButton(id, customer, urlInfix) {
|
||||
return `<button type="button" target="_blank" onclick="location.href='${orderUrlEdit}${id}?bv=${urlInfix}'" class="result-button" style="text-decoration: none;">
|
||||
<span class="btn-text" style="display: block;">Order ID: ${id} - ${customer}</span>
|
||||
</button>`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user