This commit is contained in:
Magnus Åhall 2024-04-05 08:59:59 +02:00
parent 49fd943110
commit 48c1227d9f
2 changed files with 31 additions and 26 deletions

View File

@ -67,7 +67,7 @@ func logCallback(e WrappedError.Error) { // {{{
Month int Month int
Day int Day int
Time string Time string
Error any Error error
}{now.Year(), int(now.Month()), now.Day(), now.Format("15:04:05"), e} }{now.Year(), int(now.Month()), now.Day(), now.Format("15:04:05"), e}
j, _ := json.Marshal(out) j, _ := json.Marshal(out)

View File

@ -192,37 +192,42 @@ func ExpiredSchedules() (schedules []Schedule) { // {{{
func FutureSchedules(userID int) (schedules []Schedule, err error) {// {{{ func FutureSchedules(userID int) (schedules []Schedule, err error) {// {{{
schedules = []Schedule{} schedules = []Schedule{}
res, err := service.Db.Conn.Queryx(` res := service.Db.Conn.QueryRow(`
WITH schedule_events AS (
SELECT SELECT
id, s.id,
user_id, s.user_id,
node_id, to_jsonb(n.*) AS node,
schedule_uuid, s.schedule_uuid,
time, (time - MAKE_INTERVAL(mins => s.remind_minutes)) AT TIME ZONE u.timezone AS time,
description s.description,
FROM schedule s.acknowledged
FROM schedule s
INNER JOIN public.user u ON s.user_id = u.id
INNER JOIN node n ON s.node_id = n.id
WHERE WHERE
user_id = $1 AND s.user_id=$1 AND
time >= NOW() AND time >= NOW() AND
NOT acknowledged NOT acknowledged
ORDER BY )
time ASC SELECT
COALESCE(jsonb_agg(s.*), '[]'::jsonb)
FROM schedule_events s
`, `,
userID, userID,
) )
var j []byte
err = res.Scan(&j)
if err != nil { if err != nil {
err = werr.Wrap(err).WithCode("002-000B") err = werr.Wrap(err).WithCode("002-000B").WithData(userID)
return return
} }
defer res.Close()
for res.Next() { err = json.Unmarshal(j, &schedules)
s := Schedule{} if err != nil {
if err = res.Scan(&s.ID, &s.UserID, &s.Node.ID, &s.ScheduleUUID, &s.Time, &s.Description); err != nil { err = werr.Wrap(err).WithCode("002-0010").WithData(string(j)).Log()
err = werr.Wrap(err).WithCode("002-000C")
return return
} }
schedules = append(schedules, s)
}
return return
}// }}} }// }}}