@ -43,35 +43,36 @@ router.get("/api/push/:pushToken", async (request, response) => {
const tagKeys = Object . keys ( requestTags )
const tagKeys = Object . keys ( requestTags )
if ( tagKeys . length > 0 ) {
if ( tagKeys . length > 0 ) {
// Request has additional tags. Fetch all tags for this monitor.
// Request has additional tags. Fetch all tags for this monitor.
const dbTags = await trx . getAll ( "SELECT tag.id, tag.name FROM tag JOIN monitor_tag ON monitor_tag.tag_id = tag.id AND monitor_tag.monitor_id = ?" , [ monitor . id ] ) ;
// For multiple tags with same name, get the oldest one.
const monitorTags = await trx . getAll ( "SELECT tag.name, MIN(monitor_tag.id) id FROM monitor_tag JOIN tag ON tag.id = monitor_tag.tag_id AND monitor_tag.monitor_id = ? GROUP BY tag.name ORDER BY 1" , [ monitor . id ] ) ;
// Update monitor_tag, ignoring non-existing request tags.
// Update monitor_tag, ignoring non-existing request tags.
db Tags
monitor Tags
. filter ( tag => tagKeys . includes ( tag . name ) )
. filter ( m t => tagKeys . includes ( m t. name ) )
. forEach ( async tag => {
. forEach ( async m t => {
const tagValue = requestTags [ tag . name ] ;
const tagValue = requestTags [ m t. name ] ;
await trx . exec ( "UPDATE monitor_tag SET value = ? WHERE tag_id = ? AND monitor_ id = ?" , [
await trx . exec ( "UPDATE monitor_tag SET value = ? WHERE id = ?" , [
tagValue ,
tagValue ,
tag . id ,
mt . id
monitor . id ,
] ) ;
] ) ;
// FixMe: Not working. What to emit here?
// FixMe: Not working. What to emit here?
io . to ( monitor . user_id ) . emit ( "addMonitorTag" , tag . id , monitor . id , tagValue ) ;
io . to ( monitor . user_id ) . emit ( "addMonitorTag" , m t. id , monitor . id , tagValue ) ;
} ) ;
} ) ;
}
}
// FixMe: Bean returned by trx.dispense() has no .toJSON() method (!?).
let status = UP ;
let status = UP ;
if ( monitor . isUpsideDown ( ) ) {
// FixMe: monitor.isUpsideDown is not a function (?)
status = flipStatus ( status ) ;
//if (monitor.isUpsideDown()) {
}
// status = flipStatus(status);
//}
let isFirstBeat = true ;
let isFirstBeat = true ;
let previousStatus = status ;
let previousStatus = status ;
let duration = 0 ;
let duration = 0 ;
// FixMe: Bean returned by trx.dispense() has no .toJSON() method (!?).
let bean = R . dispense ( "heartbeat" ) ; // Should be trx.dispense();
let bean = R . dispense ( "heartbeat" ) ; // Should be trx.dispense();
bean . time = R . isoDateTime ( dayjs . utc ( ) ) ;
bean . time = R . isoDateTime ( dayjs . utc ( ) ) ;