v.1.0.0. initial push of license-lib
This commit is contained in:
21
server/models/license.js
Normal file
21
server/models/license.js
Normal 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 };
|
Reference in New Issue
Block a user