Versie module 1 van 26-7
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
const db = require("../config/database");
|
||||
|
||||
|
||||
class HouseholdService {
|
||||
|
||||
|
||||
createForUser(userId, name) {
|
||||
|
||||
|
||||
const create =
|
||||
db.transaction(() => {
|
||||
|
||||
|
||||
const household =
|
||||
db.prepare(`
|
||||
|
||||
INSERT INTO households
|
||||
(name)
|
||||
|
||||
VALUES (?)
|
||||
|
||||
`).run(name);
|
||||
|
||||
|
||||
|
||||
db.prepare(`
|
||||
|
||||
INSERT INTO household_members
|
||||
|
||||
(
|
||||
household_id,
|
||||
user_id,
|
||||
role
|
||||
)
|
||||
|
||||
VALUES (?, ?, ?)
|
||||
|
||||
`).run(
|
||||
household.lastInsertRowid,
|
||||
userId,
|
||||
"OWNER"
|
||||
);
|
||||
|
||||
|
||||
return household.lastInsertRowid;
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
return create();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
module.exports = new HouseholdService();
|
||||
@@ -0,0 +1,26 @@
|
||||
const ProductRepository =
|
||||
require("../repositories/ProductRepository");
|
||||
|
||||
|
||||
class ProductService {
|
||||
|
||||
|
||||
getProducts() {
|
||||
|
||||
return ProductRepository.getAll();
|
||||
|
||||
}
|
||||
|
||||
|
||||
createProduct(data) {
|
||||
|
||||
return ProductRepository.create(data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
module.exports =
|
||||
new ProductService();
|
||||
Reference in New Issue
Block a user