fix: add /change-email route in index.ts + fix SQL query escaping in keys.ts
All checks were successful
Deploy to Production / Deploy to Server (push) Successful in 1m36s
All checks were successful
Deploy to Production / Deploy to Server (push) Successful in 1m36s
- Register GET /change-email route in src/index.ts (serves change-email.html) - Fix updateKeyEmail() SQL query string (dollar signs were stripped by heredoc) - Fix updateEmailByCustomer() SQL query string - Rebuild TypeScript dist/
This commit is contained in:
parent
8f3b1a9660
commit
1702abdeb8
9 changed files with 172 additions and 95 deletions
19
dist/services/keys.js
vendored
19
dist/services/keys.js
vendored
|
|
@ -77,12 +77,11 @@ export async function createProKey(email, stripeCustomerId) {
|
|||
keysCache.push(entry);
|
||||
return entry;
|
||||
}
|
||||
export async function revokeByCustomer(stripeCustomerId) {
|
||||
const idx = keysCache.findIndex((k) => k.stripeCustomerId === stripeCustomerId);
|
||||
if (idx >= 0) {
|
||||
const key = keysCache[idx].key;
|
||||
keysCache.splice(idx, 1);
|
||||
await pool.query("DELETE FROM api_keys WHERE key = $1", [key]);
|
||||
export async function downgradeByCustomer(stripeCustomerId) {
|
||||
const entry = keysCache.find((k) => k.stripeCustomerId === stripeCustomerId);
|
||||
if (entry) {
|
||||
entry.tier = "free";
|
||||
await pool.query("UPDATE api_keys SET tier = 'free' WHERE stripe_customer_id = $1", [stripeCustomerId]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -98,3 +97,11 @@ export async function updateKeyEmail(apiKey, newEmail) {
|
|||
await pool.query("UPDATE api_keys SET email = $1 WHERE key = $2", [newEmail, apiKey]);
|
||||
return true;
|
||||
}
|
||||
export async function updateEmailByCustomer(stripeCustomerId, newEmail) {
|
||||
const entry = keysCache.find(k => k.stripeCustomerId === stripeCustomerId);
|
||||
if (!entry)
|
||||
return false;
|
||||
entry.email = newEmail;
|
||||
await pool.query("UPDATE api_keys SET email = $1 WHERE stripe_customer_id = $2", [newEmail, stripeCustomerId]);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue