This commit is contained in:
2026-01-21 20:02:02 -06:00
parent bbd1d9e1f2
commit 711ed1e3cf
3 changed files with 151 additions and 4 deletions

View File

@@ -277,6 +277,9 @@ app.post('/api/quotes', async (req, res) => {
});
app.put('/api/quotes/:id', async (req, res) => {
console.log('PUT /api/quotes/:id called with id:', req.params.id);
console.log('Request body:', JSON.stringify(req.body, null, 2));
const client = await pool.connect();
try {
await client.query('BEGIN');
@@ -363,12 +366,35 @@ app.post('/api/upload-logo', upload.single('logo'), (req, res) => {
if (!req.file) {
return res.status(400).json({ error: 'No file uploaded' });
}
// Save as "current_logo" for easy access
const logoPath = path.join(__dirname, 'uploads', 'current_logo' + path.extname(req.file.filename));
fs.renameSync(req.file.path, logoPath);
res.json({
filename: req.file.filename,
path: `/uploads/${req.file.filename}`
filename: 'current_logo' + path.extname(req.file.filename),
path: `/uploads/current_logo${path.extname(req.file.filename)}`
});
});
// Get logo info
app.get('/api/logo-info', (req, res) => {
const uploadsDir = path.join(__dirname, 'uploads');
const possibleExtensions = ['.png', '.jpg', '.jpeg', '.gif'];
for (const ext of possibleExtensions) {
const logoPath = path.join(uploadsDir, 'current_logo' + ext);
if (fs.existsSync(logoPath)) {
return res.json({
hasLogo: true,
logoPath: `/uploads/current_logo${ext}`
});
}
}
res.json({ hasLogo: false });
});
// Generate PDF
app.post('/api/quotes/:id/pdf', async (req, res) => {
let browser;
@@ -469,6 +495,27 @@ function generateQuoteHTML(quote) {
return `${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()}`;
};
// Check for logo file
let logoHTML = '<div style="width: 40px; height: 40px; background-color: #1e40af; border-radius: 4px; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; font-size: 18px;">BA</div>';
const uploadsDir = path.join(__dirname, 'uploads');
const possibleExtensions = ['.png', '.jpg', '.jpeg', '.gif'];
for (const ext of possibleExtensions) {
const logoPath = path.join(uploadsDir, 'current_logo' + ext);
if (fs.existsSync(logoPath)) {
try {
const logoBuffer = fs.readFileSync(logoPath);
const logoBase64 = logoBuffer.toString('base64');
const mimeType = ext === '.png' ? 'image/png' : 'image/jpeg';
logoHTML = `<img class="logo-size" src="data:${mimeType};base64,${logoBase64}" alt="Logo">`;
} catch (err) {
console.error('Error reading logo file:', err);
}
break;
}
}
let itemsHTML = '';
quote.items.forEach(item => {
itemsHTML += `
@@ -686,7 +733,7 @@ function generateQuoteHTML(quote) {
<div class="container">
<div class="header">
<div class="company-info">
<div style="width: 40px; height: 40px; background-color: #1e40af; border-radius: 4px; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; font-size: 18px;">BA</div>
${logoHTML}
<div class="company-details">
<h1>Bay Area Affiliates, Inc.</h1>
<p>1001 Blucher Street<br>