Skip to content

Commit

Permalink
added unix timestamps to relations
Browse files Browse the repository at this point in the history
  • Loading branch information
joyja committed Sep 23, 2020
1 parent ddd67aa commit f50add1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/relations.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
} = require('./device')
const { Service, Mqtt, MqttSource, MqttHistory } = require('./service')
const { User } = require('./auth')
const getTime = require('date-fns/getTime')
const getUnixTime = require('date-fns/getUnixTime')
const tag = require('./resolvers/Query/tag')

// This file creates properties and defines methods requiring relationships with other models.
Expand Down Expand Up @@ -317,7 +317,7 @@ Mqtt.prototype.publish = async function () {
})
if (payload.length > 0) {
await this.client.publishDeviceData(`${source.device.name}`, {
timestamp: getTime(new Date()),
timestamp: getUnixTime(new Date()),
metrics: [...payload],
})
}
Expand Down Expand Up @@ -364,7 +364,7 @@ Mqtt.prototype.publishHistory = async function () {
}
})
this.client.publishDeviceData(`${device.name}`, {
timestamp: getTime(new Date()),
timestamp: getUnixTime(new Date()),
metrics: [...payload],
})
}
Expand Down Expand Up @@ -431,7 +431,7 @@ MqttSource.prototype.log = async function (scanClassId) {
return {
id: tag.id,
value: tag.value,
timestamp: getTime(new Date()),
timestamp: getUnixTime(new Date()),
}
}),
]
Expand All @@ -442,7 +442,7 @@ MqttSource.prototype.log = async function (scanClassId) {
this.db.serialize(async () => {
let sql = `INSERT INTO mqttHistory (mqttSource, timestamp)`
sql = `${sql} VALUES (?,?);`
let params = [this.id, getTime(new Date())]
let params = [this.id, getUnixTime(new Date())]
const result = await this.constructor.executeUpdate(sql, params)
hostsDown = this.mqtt.primaryHosts.filter((host) => !host.readyForData)
if (hostsDown.length > 0) {
Expand Down

0 comments on commit f50add1

Please sign in to comment.