db4bc9bfe1
Co-authored-by: Cursor <cursoragent@cursor.com>
21 lines
712 B
JavaScript
21 lines
712 B
JavaScript
const { query } = require('./db');
|
|
|
|
async function seedPromoCodes() {
|
|
const { rows } = await query('SELECT COUNT(*)::int AS n FROM promo_codes');
|
|
if (rows[0].n > 0) return;
|
|
|
|
const expires = new Date();
|
|
expires.setDate(expires.getDate() + 30);
|
|
|
|
await query(
|
|
`INSERT INTO promo_codes (code, description, discount_type, discount_value, expires_at, min_order_cents)
|
|
VALUES
|
|
('WELCOME10', 'Скидка 10% новым покупателям', 'percent', 10, $1, 0),
|
|
('SALE500', 'Скидка 500 ₽ от 3000 ₽', 'fixed', 50000, $1, 300000)`,
|
|
[expires.toISOString()]
|
|
);
|
|
console.log('Демо-промокоды: WELCOME10, SALE500');
|
|
}
|
|
|
|
module.exports = { seedPromoCodes };
|