Compare commits

..

No commits in common. "97aa41549b9d03c1f1984707fe16f2f5cc2cb873" and "78b858120e867b77767f02b1f6090375527bdc73" have entirely different histories.

6 changed files with 37 additions and 53 deletions

View File

@ -154,13 +154,13 @@ function App() {
<h3>{name}</h3>
<Table striped bordered hover>
<tbody>
{food?.length>0?food.map((f: any, index: number) =>
{food.map((f: any, index: number) =>
<tr key={index}>
<td>{f.amount}</td>
<td>{f.name}</td>
<td>{f.price}</td>
</tr>
):<h1>Hmmmmm podivné.... nic se nevrátilo</h1>}
)}
</tbody>
</Table>
</Col>

0
client/src/notifikace.ts Normal file
View File

View File

@ -6,9 +6,3 @@
# Vhodné pro vývoj o víkendech, svátcích a dalších dnech, pro které podniky nenabízejí obědové menu.
# V tomto režimu vrací server vždy falešné datum (pracovní den) a Food API pevně nadefinovanou, smyšlenou nabídku jídel.
# MOCK_DATA=true
# Určuje servery Gotify a příslušné klíče API.
# Formát je pole objektů, kde každý objekt obsahuje adresu serveru a pole klíčů API.
# To je užitečné pro odesílání upozornění na různé servery Gotify s různými klíči API.
# Struktura dat je ve formátu JSON a je uložena jako řetězec.
# GOTIFY_SERVERS_AND_KEYS='[{"server":"https://notification.server.eu", "api_keys":["key1", "key2"]},{"server":"https://notification.server2.eu", "api_keys":["key3", "key4"]}]'

View File

@ -1,30 +1,28 @@
/** Notifikace pro gotify*/
import axios, {AxiosError, AxiosResponse} from 'axios';
import {GotifyServer, NotififaceInput, NotifikaceData, UdalostEnum} from "./types";
import dotenv from 'dotenv';
dotenv.config()
const gotifyDataRaw = process.env.GOTIFY_SERVERS_AND_KEYS || "{}";
const gotifyData: GotifyServer[] = JSON.parse(gotifyDataRaw);
export const gotifyCall = async (data: NotififaceInput, gotifyServers: GotifyServer[]): Promise<any[]> => {
const urls = gotifyServers.flatMap(gotifyServer =>
gotifyServer.api_keys.map(apiKey => `${gotifyServer.server}/message?token=${apiKey}`));
import {NotififaceInput, NotifikaceData, UdalostEnum} from "./types";
const dataPayload = {
const url = 'your_URL_here'; // Place your URL here
export const gotifyCall = async (data: NotififaceInput): Promise<void> => {
const options = {
headers: {"Content-Type": "application/json"},
data: {
title: "Luncher",
message: `${data.udalost} - spustil:${data.user}`,
priority: 7,
},
};
const headers = {"Content-Type": "application/json"};
const promises = urls.map(url =>
axios.post(url, dataPayload, { headers }).then(response => {
try {
const response = await axios.post(url, options);
response.data = {
success: true,
message: "Notifikace doručena",
};
return response;
}).catch(error => {
console.log(response)
} catch (error: unknown) {
if (axios.isAxiosError(error)) {
const axiosError = error as AxiosError;
if (axiosError.response) {
@ -32,15 +30,12 @@ export const gotifyCall = async (data: NotififaceInput, gotifyServers: GotifySer
success: false,
message: "fail",
};
console.log(error)
return axiosError.response;
console.log(axiosError.response);
}
}
// Handle unknown error without a response
console.log(error,"unknown error");
})
);
return promises;
console.log("unkown error")
}
};
/** Zavolá notifikace na všechny konfigurované způsoby notifikace, přetížení proměných na false pro jednotlivé způsoby je vypne*/
@ -48,8 +43,7 @@ export const callNotifikace = async ({input, teams = true, gotify = true}: Notif
const notifications = [];
if (gotify) {
const gotifyPromises = await gotifyCall(input, gotifyData);
notifications.push(...gotifyPromises);
notifications.push(gotifyCall(input));
}
/* Zatím není

View File

@ -191,7 +191,7 @@ export function finishPizzaOrder(login: string) {
}
clientData.pizzaDay.state = PizzaDayState.ORDERED;
db.set(today, clientData);
callNotifikace({input:{udalost:UdalostEnum.OBJEDNANA_PIZZA,user:clientData?.pizzaDay?.creator}})
callNotifikace({input:{udalost:UdalostEnum.ZAHAJENA_PIZZA,user:clientData?.pizzaDay?.creator}})
return clientData;
}

View File

@ -83,7 +83,3 @@ export interface NotifikaceData{
gotify?:boolean,
teams?:boolean,
}
export interface GotifyServer {
server: string;
api_keys: string[];
}