<commit_before>const path = require('path')
const db = require('./db')

function pair (token, deviceId) {
  const sql = `delete from pairing_tokens
    where token=$1
    returning created < now() - interval '1 hour' as expired`
  return db.one(sql, [token])
  .then(r => {
    if (r.expired) return false

    const pairSql = 'insert into paired_devices (device_id) values ($1)'
    return db.none(pairSql, [deviceId])
    .then(() => true)
  })
}

function isPaired (deviceId) {
  const sql = 'select device_id from paired_devices where device_id=$1'

  return db.one(sql, [deviceId])
  .then(() => true)
}

module.exports = {totem, pair, unpair, isPaired}<commit_msg>move pair stuff to lamassu-admin-server<commit_after>const db = require('./db')

function pair (token, deviceId) {
  const sql = `delete from pairing_tokens
    where token=$1
    returning created < now() - interval '1 hour' as expired`
  return db.one(sql, [token])
  .then(r => {
    if (r.expired) return false

    const pairSql = 'insert into paired_devices (device_id) values ($1)'
    return db.none(pairSql, [deviceId])
    .then(() => true)
  })
}

function isPaired (deviceId) {
  const sql = 'select device_id from paired_devices where device_id=$1'

  return db.one(sql, [deviceId])
  .then(() => true)
}

module.exports = {pair, isPaired}
{'fraction_non_alphanumeric': 0.14296520423600606, 'fraction_numerical': 0.006051437216338881, 'mean_word_length': 3.810909090909091, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1587234', 'n_tokens_mistral': 450, 'n_tokens_neox': 437, 'n_words': 132}