summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Model/Traewelling.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-10-01 19:36:35 +0200
committerDaniel Friesel <derf@finalrewind.org>2020-10-01 19:36:35 +0200
commit07e0f8970681422a48fec9da5d14ad2a2b3735bd (patch)
tree9fa0a9e5492eae9f048bd607935c2906859ad9b9 /lib/Travelynx/Model/Traewelling.pm
parent590d3de51891705730eca92527f0d4f651570a29 (diff)
allow checking into traewelling
Diffstat (limited to 'lib/Travelynx/Model/Traewelling.pm')
-rw-r--r--lib/Travelynx/Model/Traewelling.pm32
1 files changed, 22 insertions, 10 deletions
diff --git a/lib/Travelynx/Model/Traewelling.pm b/lib/Travelynx/Model/Traewelling.pm
index 7f08b0d..eb7201f 100644
--- a/lib/Travelynx/Model/Traewelling.pm
+++ b/lib/Travelynx/Model/Traewelling.pm
@@ -146,16 +146,16 @@ sub set_latest_pull_status_id {
);
}
-sub set_latest_push_status_id {
+sub set_latest_push_ts {
my ( $self, %opt ) = @_;
- my $uid = $opt{uid};
- my $status_id = $opt{status_id};
- my $db = $opt{db} // $self->{pg}->db;
+ my $uid = $opt{uid};
+ my $ts = $opt{ts};
+ my $db = $opt{db} // $self->{pg}->db;
my $res_h
= $db->select( 'traewelling', 'data', { user_id => $uid } )->expand->hash;
- $res_h->{data}{latest_push_status_id} = $status_id;
+ $res_h->{data}{latest_push_ts} = $ts;
$db->update(
'traewelling',
@@ -181,12 +181,24 @@ sub set_sync {
);
}
-sub get_push_accounts {
+sub get_pushable_accounts {
my ($self) = @_;
- my $res = $self->{pg}->db->select(
- 'traewelling',
- [ 'user_id', 'token', 'data' ],
- { push_sync => 1 }
+ my $now = $self->now->epoch;
+ my $res = $self->{pg}->db->query(
+ qq{select t.user_id as uid, t.token as token, t.data as data,
+ i.checkin_station_id as dep_eva, i.checkout_station_id as arr_eva,
+ i.data as journey_data, i.train_type as train_type,
+ i.train_line as train_line, i.train_no as train_no,
+ extract(epoch from i.checkin_time) as checkin_ts
+ from traewelling as t
+ join in_transit as i on t.user_id = i.user_id
+ where t.push_sync = True
+ and i.checkout_station_id is not null
+ and i.cancelled = False
+ and (extract(epoch from i.sched_departure) > ?
+ or extract(epoch from i.real_departure) > ?)
+ and extract(epoch from i.sched_departure) < ?
+ }, $now - 300, $now - 300, $now + 600
);
return $res->expand->hashes->each;
}