v.1.0.0. initial push of license-lib

This commit is contained in:
2025-03-19 09:37:30 -05:00
commit b22a1c973c
20 changed files with 433 additions and 0 deletions

21
server/models/license.js Normal file
View File

@ -0,0 +1,21 @@
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 };