personal min and max future booking days
parent
35817e0084
commit
76f2eddd40
|
@ -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"]
|
|
@ -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"
|
|
@ -82,6 +82,7 @@ export async function GetCalendarSettings(req: Request, res: Response) {
|
|||
user_id: userSession.user_id,
|
||||
},
|
||||
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_min_earliest_booking_time",
|
||||
"calendar_using_primary_calendar",
|
||||
|
@ -92,31 +93,62 @@ export async function GetCalendarSettings(req: Request, res: Response) {
|
|||
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({
|
||||
where: {
|
||||
owner_user_id: userSession.user_id,
|
||||
store_id: user.store_id,
|
||||
},
|
||||
attributes: [
|
||||
"owner_user_id", // needed to check if the user is the store owner
|
||||
"calendar_max_future_booking_days",
|
||||
"calendar_min_earliest_booking_time",
|
||||
],
|
||||
});
|
||||
|
||||
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
|
||||
res.status(200).send({
|
||||
status: userGoogleToken.status,
|
||||
settings: user,
|
||||
userSettings: userSettings,
|
||||
});
|
||||
return;
|
||||
}
|
||||
// user is store owner
|
||||
res.status(200).send({
|
||||
status: userGoogleToken.status,
|
||||
storeSettings: store,
|
||||
userSettings: user,
|
||||
storeSettings: {
|
||||
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) {
|
||||
logger.error(error);
|
||||
|
@ -129,9 +161,17 @@ export async function UpdatePersonalCalendarSettings(
|
|||
res: Response
|
||||
) {
|
||||
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" });
|
||||
}
|
||||
|
||||
|
@ -158,6 +198,8 @@ export async function UpdatePersonalCalendarSettings(
|
|||
await User.update(
|
||||
{
|
||||
calendar_using_primary_calendar: calendarUsingPrimaryCalendar,
|
||||
calendar_max_future_booking_days: calendarMaxFutureBookingDays,
|
||||
calendar_min_earliest_booking_time: calendarMinEarliestBookingTime,
|
||||
},
|
||||
{
|
||||
where: {
|
||||
|
|
Loading…
Reference in New Issue