feat: show event for areamanager of cross areal planned user

This commit is contained in:
Max Hohlfeld 2025-08-24 18:40:46 +02:00
parent 4d1ffa206c
commit 465d6b0f0a
6 changed files with 27 additions and 9 deletions

View File

@ -19,6 +19,8 @@ FROM
assignment
JOIN availability ON
assignment.availabilityid = availability.id
JOIN user_ ON
availability.userId = user_.id
JOIN event ON
assignment.eventid = "event".id
JOIN location ON
@ -26,9 +28,9 @@ JOIN location ON
JOIN clothing ON
event.clothing = clothing.id
WHERE
userid = $1
AND event.starttimestamp::date >= $2
AND event.starttimestamp::date <= $3
AND location.areaId != $4
(userid = $1 OR user_.areaId = $2)
AND event.starttimestamp::date >= $3
AND event.starttimestamp::date <= $4
AND location.areaId != $5
ORDER BY
event.starttimestamp;

View File

@ -49,9 +49,12 @@ LEFT JOIN ASSIGNMENT ON
event.id = assignment.eventid
LEFT JOIN availability ON
assignment.availabilityid = availability.id
LEFT JOIN user_ ON
availability.userId = user_.id
WHERE
event.starttimestamp::date = $1
AND (
location.areaId = $2
OR availability.userId = $3
OR user_.areaId = $4
)

View File

@ -168,10 +168,12 @@ impl Event {
date_range: (&NaiveDate, &NaiveDate),
user_id: i32,
area_to_ignore: i32,
area_for_which_user_is_manager: Option<i32>,
) -> Result<Vec<Event>> {
let records = query_file!(
"sql/event/read_all_by_date_range_and_assigned_user_in_other_area.sql",
user_id,
area_for_which_user_is_manager,
date_range.0,
date_range.1,
area_to_ignore

View File

@ -15,12 +15,14 @@ impl EventForCalendar {
date: &NaiveDate,
area: i32,
user: i32,
area_for_which_user_is_manager: Option<i32>,
) -> Result<Vec<EventForCalendar>> {
let records = query_file!(
"sql/event_for_calendar/read_all_by_date_and_area_and_user.sql",
date,
area,
user
user,
area_for_which_user_is_manager
)
.fetch_all(pool)
.await?;

View File

@ -67,20 +67,22 @@ async fn get(
let availabilities_from_user =
Availability::read_all_by_user_and_date(pool.get_ref(), user.id, &date).await?;
//println!("{availabilities_from_user:#?}");
let user_can_create_availability = availabilities_from_user.is_empty()
|| !find_free_date_time_slots(&availabilities_from_user).is_empty();
//println!("{} || {} || {} = {user_can_create_availability}", availabilities_from_user.is_empty(),
// !only_one_availability_exists_and_is_whole_day(&availabilities_from_user),
// !find_free_time_slots(&availabilities_from_user).is_empty());
let area_for_which_user_is_manager = if user.role == Role::Admin || user.role == Role::AreaManager {
Some(user.area_id)
} else {
None
};
let events = EventForCalendar::read_all_by_date_and_area_and_user(
pool.get_ref(),
&date,
query.area.unwrap_or(user.area_id),
user.id,
area_for_which_user_is_manager
)
.await?;

View File

@ -43,11 +43,18 @@ async fn get(
)
.await?;
let area_for_which_user_is_manager = if user.role == Role::Admin || user.role == Role::AreaManager {
Some(user.area_id)
} else {
None
};
let mut foreign_events = Event::read_all_by_date_range_and_assigned_user_in_other_area(
pool.get_ref(),
date_range,
user.id,
user.area_id,
area_for_which_user_is_manager
)
.await?;