Ejemplo n.º 1
0
func (tt *TimeTable) Save(a iface.Filter, data map[string]interface{}) error {
	if !tt.userIsProfessional {
		return fmt.Errorf("Only professionals can save timetables.")
	}
	ssl := toSS(data["timeTable"].([]interface{}))
	timeTable, err := evenday.StringsToTimeTable(ssl)
	if err != nil {
		return err
	}
	count, err := a.Count()
	if err != nil {
		return err
	}
	m := map[string]interface{}{}
	m["createdBy"] = tt.userId
	m["timeTable"] = timeTable
	if count == 0 {
		return a.Insert(m)
	} else if count == 1 {
		doc, err := a.SelectOne()
		if err != nil {
			return err
		}
		return doc.Update(m)
	}
	_, err = a.RemoveAll()
	if err != nil {
		return err
	}
	return a.Insert(m)
}
Ejemplo n.º 2
0
func (b *Basics) RemoveAll(a iface.Filter) error {
	_, err := a.RemoveAll()
	return err
}