Example #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)
}
Example #2
0
func (e *Entries) othersAlreadyTook(a iface.Filter, from, to int64) error {
	entryQ := map[string]interface{}{
		"$or": []interface{}{
			map[string]interface{}{
				"from": map[string]interface{}{
					"$gt": from,
					"$lt": to,
				},
			},
			map[string]interface{}{
				"to": map[string]interface{}{
					"$gt": from,
					"$lt": to,
				},
			},
		},
	}
	a.AddQuery(entryQ)
	eC, err := a.Count()
	if err != nil {
		return err
	}
	if eC > 0 {
		return fmt.Errorf("That time is already taken.")
	}
	return nil
}
Example #3
0
func hasAdmin(f iface.Filter) error {
	q := map[string]interface{}{
		"level": 300,
	}
	f.AddQuery(q)
	c, err := f.Count()
	if err != nil {
		return err
	}
	if c > 0 {
		return fmt.Errorf("Site already has an admin.")
	}
	return nil
}
Example #4
0
func (b *Basics) Get(a iface.Filter) ([]map[string]interface{}, *QueryInfo, error) {
	list, err := a.Find()
	if err != nil {
		return nil, nil, err
	}
	count, err := a.Count()
	if err != nil {
		return nil, nil, err
	}
	return list, &QueryInfo{
		count, a.Modifiers().Skip(),
		a.Modifiers().Limit(),
		a.Modifiers().Sort(),
	}, nil
}