mirror of
https://github.com/nfonteyne/octane-website.git
synced 2026-09-03 23:24:48 +02:00
update: propose repetion dates on the interface
This commit is contained in:
parent
324cc3c977
commit
21ba87d5ba
8 changed files with 314 additions and 2 deletions
33
src/repositories/rehearsalsRepo.js
Normal file
33
src/repositories/rehearsalsRepo.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
const pool = require('../db/pool');
|
||||
|
||||
async function findUpcoming() {
|
||||
const { rows } = await pool.query(`
|
||||
SELECT r.id, r.starts_at, r.ends_at, r.location, r.proposed_by, u.name AS proposed_by_name, r.created_at
|
||||
FROM rehearsals r
|
||||
JOIN users u ON u.id = r.proposed_by
|
||||
WHERE r.ends_at >= now()
|
||||
ORDER BY r.starts_at
|
||||
`);
|
||||
return rows;
|
||||
}
|
||||
|
||||
async function findById(id) {
|
||||
const { rows } = await pool.query('SELECT id, starts_at, ends_at, location, proposed_by FROM rehearsals WHERE id = $1', [id]);
|
||||
return rows[0] || null;
|
||||
}
|
||||
|
||||
async function create({ startsAt, endsAt, location, proposedBy }) {
|
||||
const { rows } = await pool.query(
|
||||
`INSERT INTO rehearsals (starts_at, ends_at, location, proposed_by)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, starts_at, ends_at, location, proposed_by, created_at`,
|
||||
[startsAt, endsAt, location || null, proposedBy]
|
||||
);
|
||||
return rows[0];
|
||||
}
|
||||
|
||||
async function remove(id) {
|
||||
await pool.query('DELETE FROM rehearsals WHERE id = $1', [id]);
|
||||
}
|
||||
|
||||
module.exports = { findUpcoming, findById, create, remove };
|
||||
Loading…
Add table
Add a link
Reference in a new issue