personal min and max future booking days

main
alex 2024-02-03 09:24:52 +01:00
parent 35817e0084
commit 76f2eddd40
3 changed files with 84 additions and 7 deletions

13
Dockerfile Normal file
View File

@ -0,0 +1,13 @@
FROM node:20
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npx tsc
EXPOSE 3000
CMD ["node", "build/server.js"]

22
build-docker.sh Executable file
View File

@ -0,0 +1,22 @@
DOCKER_REGISTRY_URL="dockreg.ex.umbach.dev"
DOCKER_IMAGE_NAME="zeitadler-dashboard-backend"
# only allow to run this script as root
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
# rm images
docker image rm $DOCKER_IMAGE_NAME
# build images
docker build -t $DOCKER_IMAGE_NAME .
# tag images
docker image tag $DOCKER_IMAGE_NAME:latest $DOCKER_REGISTRY_URL/$DOCKER_IMAGE_NAME:latest
# push to self-hosted docker registry
docker push $DOCKER_REGISTRY_URL/$DOCKER_IMAGE_NAME
echo "Uploaded $DOCKER_IMAGE_NAME to $DOCKER_REGISTRY_URL"

View File

@ -82,6 +82,7 @@ export async function GetCalendarSettings(req: Request, res: Response) {
user_id: userSession.user_id, user_id: userSession.user_id,
}, },
attributes: [ attributes: [
"store_id", // needed if the user is not a store owner to get the max and min booking days from the store
"calendar_max_future_booking_days", "calendar_max_future_booking_days",
"calendar_min_earliest_booking_time", "calendar_min_earliest_booking_time",
"calendar_using_primary_calendar", "calendar_using_primary_calendar",
@ -92,31 +93,62 @@ export async function GetCalendarSettings(req: Request, res: Response) {
return res.status(401).send({ err: "unauthorized" }); return res.status(401).send({ err: "unauthorized" });
} }
// check if user has a store let userSettings = {
calendar_using_primary_calendar: user.calendar_using_primary_calendar,
calendar_max_future_booking_days: user.calendar_max_future_booking_days,
calendar_min_earliest_booking_time:
user.calendar_min_earliest_booking_time,
};
const store = await Store.findOne({ const store = await Store.findOne({
where: { where: {
owner_user_id: userSession.user_id, store_id: user.store_id,
}, },
attributes: [ attributes: [
"owner_user_id", // needed to check if the user is the store owner
"calendar_max_future_booking_days", "calendar_max_future_booking_days",
"calendar_min_earliest_booking_time", "calendar_min_earliest_booking_time",
], ],
}); });
if (!store) { if (!store) {
return res.status(401).send({ err: "unauthorized" });
}
// if the user has not set the calendar settings yet, set them to the values from the store
if (
user.calendar_max_future_booking_days === null ||
user.calendar_min_earliest_booking_time === null
) {
userSettings = {
...userSettings,
calendar_max_future_booking_days:
store.calendar_max_future_booking_days,
calendar_min_earliest_booking_time:
store.calendar_min_earliest_booking_time,
};
}
// check if user has a store
if (store.owner_user_id !== userSession.user_id) {
// user is not store owner - means he is an employee // user is not store owner - means he is an employee
res.status(200).send({ res.status(200).send({
status: userGoogleToken.status, status: userGoogleToken.status,
settings: user, userSettings: userSettings,
}); });
return; return;
} }
// user is store owner // user is store owner
res.status(200).send({ res.status(200).send({
status: userGoogleToken.status, status: userGoogleToken.status,
storeSettings: store, storeSettings: {
userSettings: user, calendar_max_future_booking_days:
store.calendar_max_future_booking_days,
calendar_min_earliest_booking_time:
store.calendar_min_earliest_booking_time,
},
userSettings: userSettings,
}); });
} catch (error) { } catch (error) {
logger.error(error); logger.error(error);
@ -129,9 +161,17 @@ export async function UpdatePersonalCalendarSettings(
res: Response res: Response
) { ) {
try { try {
const { calendarUsingPrimaryCalendar } = req.body; const {
calendarUsingPrimaryCalendar,
calendarMaxFutureBookingDays,
calendarMinEarliestBookingTime,
} = req.body;
if (calendarUsingPrimaryCalendar === undefined) { if (
calendarUsingPrimaryCalendar === undefined ||
calendarMaxFutureBookingDays === undefined ||
calendarMinEarliestBookingTime === undefined
) {
return res.status(400).send({ err: "invalid request" }); return res.status(400).send({ err: "invalid request" });
} }
@ -158,6 +198,8 @@ export async function UpdatePersonalCalendarSettings(
await User.update( await User.update(
{ {
calendar_using_primary_calendar: calendarUsingPrimaryCalendar, calendar_using_primary_calendar: calendarUsingPrimaryCalendar,
calendar_max_future_booking_days: calendarMaxFutureBookingDays,
calendar_min_earliest_booking_time: calendarMinEarliestBookingTime,
}, },
{ {
where: { where: {