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) }
func _new(db iface.Db, f iface.Filter, hooks iface.Hooks, client iface.Client) (*User, error) { uidI, err := client.GetDecrypted("user") if err != nil { return nil, err } id, err := db.ToId(uidI.(string)) if err != nil { return nil, err } q := map[string]interface{}{ "_id": id, } f.AddQuery(q) userDoc, err := f.SelectOne() if err != nil { return nil, err } var langs []string if langz, ok := userDoc.Data()["languages"].([]interface{}); ok { for _, v := range langz { langs = append(langs, v.(string)) } } else if client.Languages() != nil { langs = client.Languages() } else { langs = []string{"en"} } return &User{ userDoc, numcon.IntP(userDoc.Data()["level"]), langs, }, nil }