Example #1
0
func (t *Task) AddSubTask(subTaskId uuid.UUID) (bool, error) {
	sessionCopy := db.GetDatastore().Copy()
	defer sessionCopy.Close()
	coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_TASKS)
	if err := coll.Update(bson.M{"id": subTaskId}, bson.M{"$set": bson.M{"parentid": t.ID}}); err != nil {
		logger.Get().Error("Error updating sub task for task: %v. error: %v", t.ID, err)
		return false, err
	}
	//Update the sutask id on the parent task
	var task models.AppTask
	if err := coll.Find(bson.M{"id": t.ID}).One(&task); err != nil {
		logger.Get().Error("Unable to get task: %v", err)
		return false, err
	}
	task.SubTasks = append(task.SubTasks, subTaskId)
	if err := coll.Update(bson.M{"id": t.ID}, task); err != nil {
		logger.Get().Error("Error updating sub task for task: %v. error: %v", t.ID, err)
		return false, err
	}

	return true, nil
}
Example #2
0
func (t *Task) Persist() (bool, error) {
	sessionCopy := db.GetDatastore().Copy()
	defer sessionCopy.Close()
	coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_TASKS)

	// Populate the task details. The parent ID should always be updated by the parent task later.
	var appTask models.AppTask
	appTask.Id = t.ID
	appTask.Name = t.Name
	appTask.Started = t.Started
	appTask.Completed = t.Completed
	appTask.StatusList = t.StatusList
	appTask.Tag = t.Tag
	appTask.Owner = t.Owner

	if err := coll.Insert(appTask); err != nil {
		logger.Get().Error("Error persisting task: %v. error: %v", t.ID, err)
		return false, err
	}

	return true, nil
}