import { subMinutes } from "date-fns"; import knex from "../knex"; import env from "../env"; export const add = async (ipToAdd: string) => { const ip = ipToAdd.toLowerCase(); const currentIP = await knex("ips") .where("ip", ip) .first(); if (currentIP) { const currentDate = new Date().toISOString(); await knex("ips") .where({ ip }) .update({ created_at: currentDate, updated_at: currentDate }); } else { await knex("ips").insert({ ip }); } return ip; }; export const clear = async () => knex("ips") .where( "created_at", "<", subMinutes(new Date(), env.NON_USER_COOLDOWN).toISOString() ) .delete();