Actualizar server.js
This commit is contained in:
14
server.js
14
server.js
@@ -2836,7 +2836,7 @@ app.post("/config/company", authMiddleware, async (req, res) => {
|
||||
if (check.rowCount > 0) return res.status(400).json({ ok: false, error: "Ese enlace ya está en uso por otra empresa" });
|
||||
}
|
||||
|
||||
// 2. Magia Blanca: Creamos la columna billing_settings "al vuelo" si no existía, sin que tengas que ir a Adminer
|
||||
// 2. Magia Blanca: Creamos la columna billing_settings "al vuelo" si no existía
|
||||
await client.query(`
|
||||
DO $$ BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='users' AND column_name='billing_settings') THEN
|
||||
@@ -2845,7 +2845,7 @@ app.post("/config/company", authMiddleware, async (req, res) => {
|
||||
END $$;
|
||||
`);
|
||||
|
||||
// 3. Guardamos todo, incluyendo la facturación
|
||||
// 3. Guardamos todo (Añadiendo ?? null para evitar que explote la base de datos)
|
||||
await client.query(`
|
||||
UPDATE users
|
||||
SET company_slug = COALESCE($1, company_slug),
|
||||
@@ -2855,7 +2855,15 @@ app.post("/config/company", authMiddleware, async (req, res) => {
|
||||
app_settings = COALESCE($5, app_settings),
|
||||
billing_settings = COALESCE($6, billing_settings)
|
||||
WHERE id = $7
|
||||
`, [cleanSlug, company_name, company_logo, portal_settings, app_settings, billing_settings, req.user.accountId]);
|
||||
`, [
|
||||
cleanSlug,
|
||||
company_name ?? null,
|
||||
company_logo ?? null,
|
||||
portal_settings ?? null,
|
||||
app_settings ?? null,
|
||||
billing_settings ?? null,
|
||||
req.user.accountId
|
||||
]);
|
||||
|
||||
res.json({ ok: true });
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user