EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
sync-product-prices.js
Go to the documentation of this file.
1#!/usr/bin/env node
2const { Pool } = require('pg');
3
4const pool = new Pool({
5 host: 'rmm-psa-db-do-user-28531160-0.i.db.ondigitalocean.com',
6 port: 25060,
7 database: 'defaultdb',
8 user: 'doadmin',
9 password: 'AVNS_J8RJAmsEwsHFG52_-F2',
10 ssl: { rejectUnauthorized: false }
11});
12
13/**
14 *
15 */
16async function syncPrices() {
17 console.log('Syncing price_retail and price_ex_tax from unit_price...\n');
18
19 const result = await pool.query(`
20 UPDATE products
21 SET
22 price_retail = unit_price,
23 price_ex_tax = unit_price
24 WHERE unit_price > 0 AND (price_retail = 0 OR price_ex_tax = 0)
25 RETURNING product_id, name, unit_price
26 `);
27
28 console.log(`✓ Updated ${result.rows.length} products\n`);
29
30 for (const product of result.rows) {
31 console.log(` ${product.name.padEnd(40)} $${parseFloat(product.unit_price).toFixed(2)}`);
32 }
33
34 await pool.end();
35}
36
37syncPrices().catch(console.error);