22 lines
704 B
JavaScript

const { adminPool, readerPool } = require('../database');
const saveLicense = async (userId, hashedKey, licenseType, tier, validUntil = null) => {
const sql = `
INSERT INTO licenses (user_id, hashed_key, license_type, tier, valid_until, created_at)
VALUES (?, ?, ?, ?, ?, NOW())
`;
const [result] = await adminPool.execute(sql, [userId, hashedKey, licenseType, tier, validUntil]);
return result.insertId;
};
const getLicense = async (userId) => {
const sql = `
SELECT hashed_key, license_type, tier, valid_until
FROM licenses WHERE user_id = ?
`;
const [rows] = await readerPool.execute(sql, [userId]);
return rows[0];
};
module.exports = { saveLicense, getLicense };