write interval to db. validate interval

This commit is contained in:
jude 2020-09-15 15:13:41 +01:00
parent 9287fb5416
commit 980a8d2a9c

View File

@ -754,6 +754,13 @@ async fn create_reminder(
if content.len() == 0 { if content.len() == 0 {
Err(ReminderError::NotEnoughArgs) Err(ReminderError::NotEnoughArgs)
} }
// todo replace numbers with configurable values
else if interval.map_or(false, |inner| inner < 800) {
Err(ReminderError::ShortInterval)
}
else if interval.map_or(false, |inner| inner > 60*60*24*365*50) {
Err(ReminderError::LongInterval)
}
else { else {
match time_parser.timestamp() { match time_parser.timestamp() {
Ok(time) => { Ok(time) => {
@ -774,12 +781,12 @@ INSERT INTO messages (content) VALUES (?)
sqlx::query!( sqlx::query!(
" "
INSERT INTO reminders (uid, message_id, channel_id, time, method, set_by) VALUES INSERT INTO reminders (uid, message_id, channel_id, time, `interval`, method, set_by) VALUES
(?, (?,
(SELECT id FROM messages WHERE content = ? ORDER BY id DESC LIMIT 1), (SELECT id FROM messages WHERE content = ? ORDER BY id DESC LIMIT 1),
?, ?, 'remind', ?, ?, ?, 'remind',
(SELECT id FROM users WHERE user = ? LIMIT 1)) (SELECT id FROM users WHERE user = ? LIMIT 1))
", generate_uid(), content, db_channel_id, time as u32, user_id) ", generate_uid(), content, db_channel_id, time as u32, interval, user_id)
.execute(pool) .execute(pool)
.await .await
.unwrap(); .unwrap();