Compare commits
No commits in common. "97aa41549b9d03c1f1984707fe16f2f5cc2cb873" and "78b858120e867b77767f02b1f6090375527bdc73" have entirely different histories.
97aa41549b
...
78b858120e
@ -154,13 +154,13 @@ function App() {
|
|||||||
<h3>{name}</h3>
|
<h3>{name}</h3>
|
||||||
<Table striped bordered hover>
|
<Table striped bordered hover>
|
||||||
<tbody>
|
<tbody>
|
||||||
{food?.length>0?food.map((f: any, index: number) =>
|
{food.map((f: any, index: number) =>
|
||||||
<tr key={index}>
|
<tr key={index}>
|
||||||
<td>{f.amount}</td>
|
<td>{f.amount}</td>
|
||||||
<td>{f.name}</td>
|
<td>{f.name}</td>
|
||||||
<td>{f.price}</td>
|
<td>{f.price}</td>
|
||||||
</tr>
|
</tr>
|
||||||
):<h1>Hmmmmm podivné.... nic se nevrátilo</h1>}
|
)}
|
||||||
</tbody>
|
</tbody>
|
||||||
</Table>
|
</Table>
|
||||||
</Col>
|
</Col>
|
||||||
|
0
client/src/notifikace.ts
Normal file
0
client/src/notifikace.ts
Normal file
@ -5,10 +5,4 @@
|
|||||||
# Zapne režim mockování jídelních lístků.
|
# Zapne režim mockování jídelních lístků.
|
||||||
# Vhodné pro vývoj o víkendech, svátcích a dalších dnech, pro které podniky nenabízejí obědové menu.
|
# 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.
|
# 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
|
# 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"]}]'
|
|
@ -1,46 +1,41 @@
|
|||||||
/** Notifikace pro gotify*/
|
/** Notifikace pro gotify*/
|
||||||
import axios, {AxiosError, AxiosResponse} from 'axios';
|
import axios, {AxiosError, AxiosResponse} from 'axios';
|
||||||
import {GotifyServer, NotififaceInput, NotifikaceData, UdalostEnum} from "./types";
|
import {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}`));
|
|
||||||
|
|
||||||
const dataPayload = {
|
const url = 'your_URL_here'; // Place your URL here
|
||||||
title: "Luncher",
|
|
||||||
message: `${data.udalost} - spustil:${data.user}`,
|
export const gotifyCall = async (data: NotififaceInput): Promise<void> => {
|
||||||
priority: 7,
|
|
||||||
|
const options = {
|
||||||
|
headers: {"Content-Type": "application/json"},
|
||||||
|
data: {
|
||||||
|
title: "Luncher",
|
||||||
|
message: `${data.udalost} - spustil:${data.user}`,
|
||||||
|
priority: 7,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const headers = {"Content-Type": "application/json"};
|
try {
|
||||||
|
const response = await axios.post(url, options);
|
||||||
const promises = urls.map(url =>
|
response.data = {
|
||||||
axios.post(url, dataPayload, { headers }).then(response => {
|
success: true,
|
||||||
response.data = {
|
message: "Notifikace doručena",
|
||||||
success: true,
|
};
|
||||||
message: "Notifikace doručena",
|
console.log(response)
|
||||||
};
|
} catch (error: unknown) {
|
||||||
return response;
|
if (axios.isAxiosError(error)) {
|
||||||
}).catch(error => {
|
const axiosError = error as AxiosError;
|
||||||
if (axios.isAxiosError(error)) {
|
if (axiosError.response) {
|
||||||
const axiosError = error as AxiosError;
|
axiosError.response.data = {
|
||||||
if (axiosError.response) {
|
success: false,
|
||||||
axiosError.response.data = {
|
message: "fail",
|
||||||
success: false,
|
};
|
||||||
message: "fail",
|
console.log(axiosError.response);
|
||||||
};
|
|
||||||
console.log(error)
|
|
||||||
return axiosError.response;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Handle unknown error without a response
|
}
|
||||||
console.log(error,"unknown error");
|
// Handle unknown error without a response
|
||||||
})
|
console.log("unkown error")
|
||||||
);
|
}
|
||||||
return promises;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Zavolá notifikace na všechny konfigurované způsoby notifikace, přetížení proměných na false pro jednotlivé způsoby je vypne*/
|
/** 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 = [];
|
const notifications = [];
|
||||||
|
|
||||||
if (gotify) {
|
if (gotify) {
|
||||||
const gotifyPromises = await gotifyCall(input, gotifyData);
|
notifications.push(gotifyCall(input));
|
||||||
notifications.push(...gotifyPromises);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Zatím není
|
/* Zatím není
|
||||||
|
@ -191,7 +191,7 @@ export function finishPizzaOrder(login: string) {
|
|||||||
}
|
}
|
||||||
clientData.pizzaDay.state = PizzaDayState.ORDERED;
|
clientData.pizzaDay.state = PizzaDayState.ORDERED;
|
||||||
db.set(today, clientData);
|
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;
|
return clientData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,8 +82,4 @@ export interface NotifikaceData{
|
|||||||
input:NotififaceInput,
|
input:NotififaceInput,
|
||||||
gotify?:boolean,
|
gotify?:boolean,
|
||||||
teams?:boolean,
|
teams?:boolean,
|
||||||
}
|
|
||||||
export interface GotifyServer {
|
|
||||||
server: string;
|
|
||||||
api_keys: string[];
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user