fix: empty comment gets saved
This commit is contained in:
parent
f5c09e3515
commit
1515f50ed9
@ -26,9 +26,14 @@ pub async fn post(
|
|||||||
availability: None,
|
availability: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let comment = form
|
||||||
|
.comment
|
||||||
|
.clone()
|
||||||
|
.and_then(|c| if !c.trim().is_empty() { Some(c) } else { None });
|
||||||
|
|
||||||
let mut changeset = AvailabilityChangeset {
|
let mut changeset = AvailabilityChangeset {
|
||||||
time: (start, end),
|
time: (start, end),
|
||||||
comment: form.comment.clone(),
|
comment,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = changeset.validate_with_context(&context).await {
|
if let Err(e) = changeset.validate_with_context(&context).await {
|
||||||
|
@ -29,6 +29,11 @@ pub async fn post(
|
|||||||
let start = form.startdate.and_time(form.starttime);
|
let start = form.startdate.and_time(form.starttime);
|
||||||
let end = form.enddate.and_time(form.endtime);
|
let end = form.enddate.and_time(form.endtime);
|
||||||
|
|
||||||
|
let comment = form
|
||||||
|
.comment
|
||||||
|
.clone()
|
||||||
|
.and_then(|c| if !c.trim().is_empty() { Some(c) } else { None });
|
||||||
|
|
||||||
let context = AvailabilityContext {
|
let context = AvailabilityContext {
|
||||||
pool: pool.get_ref(),
|
pool: pool.get_ref(),
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
@ -37,7 +42,7 @@ pub async fn post(
|
|||||||
|
|
||||||
let mut changeset = AvailabilityChangeset {
|
let mut changeset = AvailabilityChangeset {
|
||||||
time: (start, end),
|
time: (start, end),
|
||||||
comment: form.comment.clone(),
|
comment,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = changeset.validate_with_context(&context).await {
|
if let Err(e) = changeset.validate_with_context(&context).await {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user