Rescoped colead role and revised session handling.
This commit is contained in:
parent
da5f3524fa
commit
7dbcd05262
12 changed files with 376 additions and 50 deletions
31
db.go
31
db.go
|
|
@ -939,6 +939,8 @@ func (app *App) mergeParticipants(canonicalID, otherID int) error {
|
|||
); err != nil {
|
||||
return err
|
||||
}
|
||||
app.db.Exec(`INSERT OR IGNORE INTO participant_roles (participant_id, role) SELECT ?, role FROM participant_roles WHERE participant_id = ?`, canonicalID, otherID)
|
||||
app.db.Exec(`INSERT OR IGNORE INTO participant_departments (participant_id, department_id) SELECT ?, department_id FROM participant_departments WHERE participant_id = ?`, canonicalID, otherID)
|
||||
_, err := app.db.Exec(
|
||||
`UPDATE participants SET deleted_at=?, updated_at=? WHERE id=?`, ts, ts, otherID,
|
||||
)
|
||||
|
|
@ -1206,7 +1208,7 @@ const volunteerSelect = `v.id, v.participant_id,
|
|||
v.created_at, v.updated_at, v.deleted_at`
|
||||
const volunteerFrom = `FROM volunteers v INNER JOIN participants p ON p.id = v.participant_id`
|
||||
|
||||
func (app *App) listVolunteers(search string, deptID *int, since string) ([]Volunteer, error) {
|
||||
func (app *App) listVolunteers(search string, deptIDs []int, since string) ([]Volunteer, error) {
|
||||
q := `SELECT ` + volunteerSelect + ` ` + volunteerFrom + ` WHERE 1=1`
|
||||
var args []any
|
||||
if since != "" {
|
||||
|
|
@ -1220,9 +1222,14 @@ func (app *App) listVolunteers(search string, deptID *int, since string) ([]Volu
|
|||
s := "%" + search + "%"
|
||||
args = append(args, s, s)
|
||||
}
|
||||
if deptID != nil {
|
||||
if len(deptIDs) == 1 {
|
||||
q += ` AND v.department_id = ?`
|
||||
args = append(args, *deptID)
|
||||
args = append(args, deptIDs[0])
|
||||
} else if len(deptIDs) > 1 {
|
||||
q += ` AND v.department_id IN (` + placeholders(len(deptIDs)) + `)`
|
||||
for _, id := range deptIDs {
|
||||
args = append(args, id)
|
||||
}
|
||||
}
|
||||
q += ` ORDER BY p.preferred_name`
|
||||
return queryVolunteers(app.db, q, args...)
|
||||
|
|
@ -1422,7 +1429,7 @@ func generateConfirmationToken() (string, error) {
|
|||
|
||||
// --- Shifts ---
|
||||
|
||||
func (app *App) listShifts(deptID *int, day, since string) ([]Shift, error) {
|
||||
func (app *App) listShifts(deptIDs []int, day, since string) ([]Shift, error) {
|
||||
q := `SELECT ` + shiftCols + ` FROM shifts WHERE 1=1`
|
||||
var args []any
|
||||
if since != "" {
|
||||
|
|
@ -1431,9 +1438,14 @@ func (app *App) listShifts(deptID *int, day, since string) ([]Shift, error) {
|
|||
} else {
|
||||
q += ` AND deleted_at IS NULL`
|
||||
}
|
||||
if deptID != nil {
|
||||
if len(deptIDs) == 1 {
|
||||
q += ` AND department_id = ?`
|
||||
args = append(args, *deptID)
|
||||
args = append(args, deptIDs[0])
|
||||
} else if len(deptIDs) > 1 {
|
||||
q += ` AND department_id IN (` + placeholders(len(deptIDs)) + `)`
|
||||
for _, id := range deptIDs {
|
||||
args = append(args, id)
|
||||
}
|
||||
}
|
||||
if day != "" {
|
||||
q += ` AND day = ?`
|
||||
|
|
@ -1669,3 +1681,10 @@ func boolInt(b bool) int {
|
|||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func placeholders(n int) string {
|
||||
if n <= 0 {
|
||||
return ""
|
||||
}
|
||||
return strings.Repeat("?,", n-1) + "?"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue