بلا عنوان

 

CREATE TABLE items ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, serial_number VARCHAR(100) UNIQUE NOT NULL, quantity INT DEFAULT 0, debit DECIMAL(10, 2) DEFAULT 0, credit DECIMAL(10, 2) DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); const express = require('express'); const app = express(); const bodyParser = require('body-parser'); const mysql = require('mysql'); app.use(bodyParser.json()); // MySQL connection setup const db = mysql.createConnection({ host: 'localhost', user: 'root', password: '', database: 'inventory_db' }); // Endpoint to add an item app.post('/api/items', (req, res) => { const { name, serial_number, quantity, debit, credit } = req.body; const sql = 'INSERT INTO items (name, serial_number, quantity, debit, credit) VALUES (?, ?, ?, ?, ?)'; db.query(sql, [name, serial_number, quantity, debit, credit], (err, result) => { if (err) throw err; res.send('Item added!'); }); }); // More endpoints... app.listen(3000, () => console.log('Server running on port 3000'));

Post a Comment

أحدث أقدم