Versie module 1 van 26-7
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
const db = require("../config/database");
|
||||
|
||||
|
||||
class ProductRepository {
|
||||
|
||||
|
||||
getAll() {
|
||||
|
||||
return db.prepare(`
|
||||
|
||||
SELECT
|
||||
|
||||
products.*,
|
||||
|
||||
categories.name AS category_name,
|
||||
|
||||
categories.icon AS category_icon
|
||||
|
||||
|
||||
FROM products
|
||||
|
||||
|
||||
LEFT JOIN categories
|
||||
|
||||
ON categories.id = products.category_id
|
||||
|
||||
|
||||
ORDER BY products.name
|
||||
|
||||
`).all();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
findById(id) {
|
||||
|
||||
return db.prepare(`
|
||||
|
||||
SELECT *
|
||||
|
||||
FROM products
|
||||
|
||||
WHERE id = ?
|
||||
|
||||
`).get(id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
create(data) {
|
||||
|
||||
|
||||
return db.prepare(`
|
||||
|
||||
INSERT INTO products
|
||||
|
||||
(
|
||||
name,
|
||||
category_id,
|
||||
barcode
|
||||
)
|
||||
|
||||
VALUES (?, ?, ?)
|
||||
|
||||
`).run(
|
||||
|
||||
data.name,
|
||||
|
||||
data.category_id || null,
|
||||
|
||||
data.barcode || null
|
||||
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
module.exports = new ProductRepository();
|
||||
@@ -0,0 +1,35 @@
|
||||
const db = require("../config/database");
|
||||
|
||||
|
||||
class UserRepository {
|
||||
|
||||
|
||||
findById(id) {
|
||||
|
||||
return db.prepare(`
|
||||
|
||||
SELECT
|
||||
users.*,
|
||||
household_members.household_id,
|
||||
household_members.role,
|
||||
households.name AS household_name
|
||||
|
||||
FROM users
|
||||
|
||||
LEFT JOIN household_members
|
||||
ON users.id = household_members.user_id
|
||||
|
||||
LEFT JOIN households
|
||||
ON households.id = household_members.household_id
|
||||
|
||||
WHERE users.id = ?
|
||||
|
||||
`).get(id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
module.exports = new UserRepository();
|
||||
Reference in New Issue
Block a user