Merge remote-tracking branch 'origin/user/reallag'

This commit is contained in:
Martin Berka 2023-06-12 20:30:15 +02:00
commit 07550e7f83
7 changed files with 102 additions and 11 deletions

View File

@ -51,5 +51,7 @@
"last 1 safari version"
]
},
"devDependencies": {}
"devDependencies": {
"prettier": "^2.8.8"
}
}

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

View File

@ -7569,6 +7569,11 @@ prelude-ls@~1.1.2:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
integrity sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==
prettier@^2.8.8:
version "2.8.8"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
pretty-bytes@^5.3.0, pretty-bytes@^5.4.1:
version "5.6.0"
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-5.6.0.tgz#356256f643804773c82f64723fe78c92c62beaeb"

View File

@ -165,4 +165,6 @@ const HOST = process.env.HOST || '0.0.0.0';
server.listen(PORT, () => {
console.log(`Server listening on ${HOST}, port ${PORT}`);
});
});
console.log(process.env.API_KEY)

63
server/src/notifikace.ts Normal file
View File

@ -0,0 +1,63 @@
/** Notifikace pro gotify*/
import axios, {AxiosError, AxiosResponse} from 'axios';
import {NotififaceInput, NotifikaceData, UdalostEnum} from "./types";
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,
},
};
try {
const response = await axios.post(url, options);
response.data = {
success: true,
message: "Notifikace doručena",
};
console.log(response)
} catch (error: unknown) {
if (axios.isAxiosError(error)) {
const axiosError = error as AxiosError;
if (axiosError.response) {
axiosError.response.data = {
success: false,
message: "fail",
};
console.log(axiosError.response);
}
}
// Handle unknown error without a response
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*/
export const callNotifikace = async ({input, teams = true, gotify = true}: NotifikaceData) => {
const notifications = [];
if (gotify) {
notifications.push(gotifyCall(input));
}
/* Zatím není
if (teams) {
notifications.push(teamsCall(input));
}*/
// Add more notifications as necessary
try {
const results = await Promise.all(notifications);
return results;
} catch (error) {
console.error("Error in callNotifikace: ", error);
// Handle the error as needed
}
};

View File

@ -1,7 +1,7 @@
import { ClientData, Locations, Order, Pizza, PizzaDayState, PizzaOrder, PizzaSize } from "./types";
import { db } from "./database";
import { getHumanDate, getIsWeekend } from "./utils";
import { formatDate } from "./utils";
import {ClientData, Locations, Order, Pizza, PizzaDayState, PizzaOrder, PizzaSize, UdalostEnum} from "./types";
import {db} from "./database";
import {formatDate, getHumanDate, getIsWeekend} from "./utils";
import {callNotifikace} from "./notifikace";
/** Vrátí dnešní datum, případně fiktivní datum pro účely vývoje a testování. */
function getToday(): Date {
@ -36,6 +36,7 @@ export function createPizzaDay(creator: string): ClientData {
}
const data: ClientData = { pizzaDay: { state: PizzaDayState.CREATED, creator, orders: [] }, ...clientData };
db.set(today, data);
callNotifikace({input:{udalost:UdalostEnum.ZAHAJENA_PIZZA,user:creator}})
return data;
}
@ -95,7 +96,7 @@ export function addPizzaOrder(login: string, pizza: Pizza, size: PizzaSize) {
/**
* Odstraní danou objednávku pizzy.
*
*
* @param login login uživatele
* @param pizzaOrder objednávka pizzy
*/
@ -126,7 +127,7 @@ export function removePizzaOrder(login: string, pizzaOrder: PizzaOrder) {
/**
* Uzamkne možnost editovat objednávky pizzy.
*
*
* @param login login uživatele
* @returns aktuální data pro uživatele
*/
@ -149,7 +150,7 @@ export function lockPizzaDay(login: string) {
/**
* Odekmne možnost editovat objednávky pizzy.
*
*
* @param login login uživatele
* @returns aktuální data pro uživatele
*/
@ -172,7 +173,7 @@ export function unlockPizzaDay(login: string) {
/**
* Nastaví stav pizza day na "pizzy objednány".
*
*
* @param login login uživatele
* @returns aktuální data pro uživatele
*/
@ -190,12 +191,13 @@ export function finishPizzaOrder(login: string) {
}
clientData.pizzaDay.state = PizzaDayState.ORDERED;
db.set(today, clientData);
callNotifikace({input:{udalost:UdalostEnum.ZAHAJENA_PIZZA,user:clientData?.pizzaDay?.creator}})
return clientData;
}
/**
* Nastaví stav pizza day na "pizzy doručeny".
*
*
* @param login login uživatele
* @returns aktuální data pro uživatele
*/

View File

@ -1,3 +1,5 @@
import exp from "constants";
export interface Choices {
[location: string]: string[],
}
@ -65,4 +67,19 @@ export enum Locations {
VLASTNI = 'Mám vlastní',
OBJEDNAVAM = 'Objednávám',
NEOBEDVAM = 'Neobědvám',
}
export enum UdalostEnum{
ZAHAJENA_PIZZA="Zahájen pizza day",
OBJEDNANA_PIZZA="Objednána pizza"
}
export interface NotififaceInput{
udalost:UdalostEnum,
user:string,
}
export interface NotifikaceData{
input:NotififaceInput,
gotify?:boolean,
teams?:boolean,
}