Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 6x 6x | const pool = require('../config/db'); class Establishment { static async findAll() { const [rows] = await pool.query( 'SELECT * FROM establishments ORDER BY name' ); return rows; } static async findById(id) { const [rows] = await pool.query( 'SELECT * FROM establishments WHERE id = ?', [id] ); return rows[0]; } static async create(establishmentData) { const { name, location, type, certificate_number, certificate_expiry, contact_person, contact_email, contact_phone } = establishmentData; const [result] = await pool.query( 'INSERT INTO establishments (name, location, type, certificate_number, certificate_expiry, contact_person, contact_email, contact_phone) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', [name, location, type, certificate_number, certificate_expiry, contact_person, contact_email, contact_phone] ); return result.insertId; } static async update(id, establishmentData) { const { name, location, type, certificate_number, certificate_expiry, contact_person, contact_email, contact_phone } = establishmentData; await pool.query( 'UPDATE establishments SET name = ?, location = ?, type = ?, certificate_number = ?, certificate_expiry = ?, contact_person = ?, contact_email = ?, contact_phone = ? WHERE id = ?', [name, location, type, certificate_number, certificate_expiry, contact_person, contact_email, contact_phone, id] ); } } module.exports = Establishment; |