Update manual Volunteer entry.
This commit is contained in:
parent
c03498b59e
commit
3429ee92fe
2 changed files with 18 additions and 6 deletions
|
|
@ -33,11 +33,15 @@ func (app *App) handleListVolunteers(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (app *App) handleCreateVolunteer(w http.ResponseWriter, r *http.Request) {
|
||||
var v Volunteer
|
||||
if err := json.NewDecoder(r.Body).Decode(&v); err != nil {
|
||||
var body struct {
|
||||
Volunteer
|
||||
TicketName string `json:"ticket_name"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
writeError(w, "invalid request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
v := body.Volunteer
|
||||
if v.Name == "" {
|
||||
writeError(w, "name is required", http.StatusBadRequest)
|
||||
return
|
||||
|
|
@ -52,7 +56,9 @@ func (app *App) handleCreateVolunteer(w http.ResponseWriter, r *http.Request) {
|
|||
if v.Email != "" && v.ParticipantID == nil {
|
||||
p, _ := app.getParticipantByEmail(v.Email)
|
||||
if p == nil {
|
||||
p, _ = app.createParticipant(Participant{PreferredName: v.Name, Email: v.Email})
|
||||
p, _ = app.createParticipant(Participant{PreferredName: v.Name, Email: v.Email, TicketName: body.TicketName})
|
||||
} else if body.TicketName != "" && p.TicketName == "" {
|
||||
app.db.Exec(`UPDATE participants SET ticket_name = ?, updated_at = ? WHERE id = ?`, body.TicketName, now(), p.ID)
|
||||
}
|
||||
if p != nil {
|
||||
v.ParticipantID = &p.ID
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue