59 lines
839 B
JavaScript
59 lines
839 B
JavaScript
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(); |