secondary email

This commit is contained in:
2026-05-06 17:04:16 -05:00
parent 6662b3cb18
commit f9b4916e40
5 changed files with 238 additions and 46 deletions

View File

@@ -22,16 +22,16 @@ router.get('/', async (req, res) => {
router.post('/', async (req, res) => {
const {
name, contact, line1, line2, line3, line4, city, state, zip_code,
account_number, email, phone, phone2, taxable, remarks
account_number, email, secondary_email, phone, phone2, taxable, remarks
} = req.body;
try {
const result = await pool.query(
`INSERT INTO customers (name, contact, line1, line2, line3, line4, city, state, zip_code, account_number, email, phone, phone2, taxable, remarks)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) RETURNING *`,
`INSERT INTO customers (name, contact, line1, line2, line3, line4, city, state, zip_code, account_number, email, secondary_email, phone, phone2, taxable, remarks)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16) RETURNING *`,
[name, contact || null, line1 || null, line2 || null, line3 || null, line4 || null,
city || null, state || null, zip_code || null, account_number || null,
email || null, phone || null, phone2 || null,
email || null, secondary_email || null, phone || null, phone2 || null,
taxable !== undefined ? taxable : true, remarks || null]
);
res.json(result.rows[0]);
@@ -46,20 +46,21 @@ router.put('/:id', async (req, res) => {
const { id } = req.params;
const {
name, contact, line1, line2, line3, line4, city, state, zip_code,
account_number, email, phone, phone2, taxable, remarks
account_number, email, secondary_email, phone, phone2, taxable, remarks
} = req.body;
try {
const result = await pool.query(
`UPDATE customers
SET name = $1, contact = $2, line1 = $3, line2 = $4, line3 = $5, line4 = $6,
city = $7, state = $8, zip_code = $9, account_number = $10, email = $11,
phone = $12, phone2 = $13, taxable = $14, remarks = $15, updated_at = CURRENT_TIMESTAMP
WHERE id = $16
`UPDATE customers
SET name = $1, contact = $2, line1 = $3, line2 = $4, line3 = $5, line4 = $6,
city = $7, state = $8, zip_code = $9, account_number = $10, email = $11,
secondary_email = $12, phone = $13, phone2 = $14, taxable = $15,
remarks = $16, updated_at = CURRENT_TIMESTAMP
WHERE id = $17
RETURNING *`,
[name, contact || null, line1 || null, line2 || null, line3 || null, line4 || null,
city || null, state || null, zip_code || null, account_number || null,
email || null, phone || null, phone2 || null,
email || null, secondary_email || null, phone || null, phone2 || null,
taxable !== undefined ? taxable : true, remarks || null, id]
);
@@ -143,7 +144,6 @@ router.delete('/:id', async (req, res) => {
const { id } = req.params;
try {
// Load customer
const custResult = await pool.query('SELECT * FROM customers WHERE id = $1', [id]);
if (custResult.rows.length === 0) {
return res.status(404).json({ error: 'Customer not found' });
@@ -151,14 +151,12 @@ router.delete('/:id', async (req, res) => {
const customer = custResult.rows[0];
// Deactivate in QBO if present
if (customer.qbo_id) {
try {
const oauthClient = getOAuthClient();
const companyId = oauthClient.getToken().realmId;
const baseUrl = getQboBaseUrl();
// Get SyncToken
const qboRes = await makeQboApiCall({
url: `${baseUrl}/v3/company/${companyId}/customer/${customer.qbo_id}`,
method: 'GET'
@@ -188,7 +186,6 @@ router.delete('/:id', async (req, res) => {
}
}
// Delete locally
await pool.query('DELETE FROM customers WHERE id = $1', [id]);
res.json({ success: true });
@@ -222,7 +219,6 @@ router.post('/:id/export-qbo', async (req, res) => {
Notes: customer.remarks || undefined
};
// Contact
if (customer.contact) {
const parts = customer.contact.trim().split(/\s+/);
if (parts.length >= 2) {
@@ -233,7 +229,6 @@ router.post('/:id/export-qbo', async (req, res) => {
}
}
// Address
const addr = {};
if (customer.line1) addr.Line1 = customer.line1;
if (customer.line2) addr.Line2 = customer.line2;
@@ -267,4 +262,4 @@ router.post('/:id/export-qbo', async (req, res) => {
}
});
module.exports = router;
module.exports = router;