예제 #1
0
파일: meeting.go 프로젝트: crufter/nocrud
func (e *Entries) Insert(a iface.Filter, data map[string]interface{}) error {
	e.getOptions(a.Subject())
	from := data["from"].(int64)
	length := data["length"].(int64)
	prof, err := e.db.ToId(data["professional"].(string))
	if err != nil {
		return err
	}
	err = e.intervalIsValid(data, prof, length)
	if err != nil {
		return err
	}
	to := from + length*60
	err = e.okAccordingToTimeTable(data, from, to)
	if err != nil {
		return err
	}
	err = e.othersAlreadyTook(a, from, to)
	if err != nil {
		return err
	}
	i := map[string]interface{}{
		"createdBy":       e.userId,
		"from":            from,
		"to":              to,
		"length":          length,
		"day":             dateToString(from),
		"forProfessional": prof,
	}
	return a.Insert(i)
}
예제 #2
0
파일: meeting.go 프로젝트: crufter/nocrud
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)
}
예제 #3
0
파일: jsonedit.go 프로젝트: crufter/nocrud
func (c *C) Insert(a iface.Filter, data map[string]interface{}) error {
	m, err := c.decrypt(data)
	if err != nil {
		return err
	}
	m["created"] = time.Now().UnixNano() // Should include user too maybe.
	return a.Insert(m)
}
예제 #4
0
func RegisterUser(a iface.Filter, db iface.Db, user map[string]interface{}) (iface.Id, error) {
	user["password"] = hashPass(user["password"].(string))
	if _, has := user["level"]; !has {
		user["level"] = 100
	}
	user_id := db.NewId()
	user["_id"] = user_id
	err := a.Insert(user)
	if err != nil {
		return nil, fmt.Errorf("Name is not unique.")
	}
	return user_id, nil
}
예제 #5
0
파일: basics.go 프로젝트: crufter/nocrud
func (b *Basics) Insert(a iface.Filter, data map[string]interface{}) (iface.Id, error) {
	id := b.Db.NewId()
	data["_id"] = id
	err := a.Insert(data)
	if err != nil {
		return nil, err
	}
	if b.Hooks != nil {
		q := map[string]interface{}{
			"_id": id,
		}
		filt := a.Clone().AddQuery(q)
		b.Hooks.Select("Inserted").Fire(filt)
		b.Hooks.Select(a.Subject() + "Inserted").Fire(filt)
	}
	return id, nil
}