taskcafe/internal/graph/schema.resolvers.go

1290 lines
47 KiB
Go
Raw Normal View History

package graph
2020-04-10 04:40:22 +02:00
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
import (
"context"
"database/sql"
"errors"
2020-04-20 05:02:55 +02:00
"fmt"
2020-04-10 04:40:22 +02:00
"time"
"github.com/google/uuid"
"github.com/jordanknott/project-citadel/api/internal/db"
2020-04-10 04:40:22 +02:00
log "github.com/sirupsen/logrus"
"github.com/vektah/gqlparser/v2/gqlerror"
"golang.org/x/crypto/bcrypt"
2020-04-10 04:40:22 +02:00
)
func (r *labelColorResolver) ID(ctx context.Context, obj *db.LabelColor) (uuid.UUID, error) {
2020-05-27 23:18:50 +02:00
return obj.LabelColorID, nil
}
func (r *mutationResolver) CreateProject(ctx context.Context, input NewProject) (*db.Project, error) {
2020-04-10 04:40:22 +02:00
createdAt := time.Now().UTC()
project, err := r.Repository.CreateProject(ctx, db.CreateProjectParams{input.UserID, input.TeamID, createdAt, input.Name})
2020-04-10 04:40:22 +02:00
return &project, err
}
func (r *mutationResolver) DeleteProject(ctx context.Context, input DeleteProject) (*DeleteProjectPayload, error) {
project, err := r.Repository.GetProjectByID(ctx, input.ProjectID)
if err != nil {
return &DeleteProjectPayload{Ok: false}, err
}
err = r.Repository.DeleteProjectByID(ctx, input.ProjectID)
if err != nil {
return &DeleteProjectPayload{Ok: false}, err
}
return &DeleteProjectPayload{Project: &project, Ok: true}, err
}
func (r *mutationResolver) UpdateProjectName(ctx context.Context, input *UpdateProjectName) (*db.Project, error) {
project, err := r.Repository.UpdateProjectNameByID(ctx, db.UpdateProjectNameByIDParams{ProjectID: input.ProjectID, Name: input.Name})
2020-05-31 06:11:19 +02:00
if err != nil {
return &db.Project{}, err
2020-05-31 06:11:19 +02:00
}
return &project, nil
}
func (r *mutationResolver) CreateProjectLabel(ctx context.Context, input NewProjectLabel) (*db.ProjectLabel, error) {
2020-05-27 23:18:50 +02:00
createdAt := time.Now().UTC()
var name sql.NullString
if input.Name != nil {
name = sql.NullString{
*input.Name,
true,
}
} else {
name = sql.NullString{
"",
false,
}
}
projectLabel, err := r.Repository.CreateProjectLabel(ctx, db.CreateProjectLabelParams{input.ProjectID, input.LabelColorID, createdAt, name})
2020-05-27 23:18:50 +02:00
return &projectLabel, err
2020-04-21 01:04:27 +02:00
}
func (r *mutationResolver) DeleteProjectLabel(ctx context.Context, input DeleteProjectLabel) (*db.ProjectLabel, error) {
label, err := r.Repository.GetProjectLabelByID(ctx, input.ProjectLabelID)
if err != nil {
return &db.ProjectLabel{}, err
}
err = r.Repository.DeleteProjectLabelByID(ctx, input.ProjectLabelID)
return &label, err
}
func (r *mutationResolver) UpdateProjectLabel(ctx context.Context, input UpdateProjectLabel) (*db.ProjectLabel, error) {
label, err := r.Repository.UpdateProjectLabel(ctx, db.UpdateProjectLabelParams{ProjectLabelID: input.ProjectLabelID, LabelColorID: input.LabelColorID, Name: sql.NullString{String: input.Name, Valid: true}})
return &label, err
}
func (r *mutationResolver) UpdateProjectLabelName(ctx context.Context, input UpdateProjectLabelName) (*db.ProjectLabel, error) {
label, err := r.Repository.UpdateProjectLabelName(ctx, db.UpdateProjectLabelNameParams{ProjectLabelID: input.ProjectLabelID, Name: sql.NullString{String: input.Name, Valid: true}})
return &label, err
}
func (r *mutationResolver) UpdateProjectLabelColor(ctx context.Context, input UpdateProjectLabelColor) (*db.ProjectLabel, error) {
label, err := r.Repository.UpdateProjectLabelColor(ctx, db.UpdateProjectLabelColorParams{ProjectLabelID: input.ProjectLabelID, LabelColorID: input.LabelColorID})
return &label, err
}
func (r *mutationResolver) CreateProjectMember(ctx context.Context, input CreateProjectMember) (*CreateProjectMemberPayload, error) {
addedAt := time.Now().UTC()
_, err := r.Repository.CreateProjectMember(ctx, db.CreateProjectMemberParams{ProjectID: input.ProjectID, UserID: input.UserID, AddedAt: addedAt, RoleCode: "member"})
2020-04-10 04:40:22 +02:00
if err != nil {
return &CreateProjectMemberPayload{Ok: false}, err
2020-04-10 04:40:22 +02:00
}
user, err := r.Repository.GetUserAccountByID(ctx, input.UserID)
if err != nil {
return &CreateProjectMemberPayload{Ok: false}, err
}
var url *string
if user.ProfileAvatarUrl.Valid {
url = &user.ProfileAvatarUrl.String
}
profileIcon := &ProfileIcon{url, &user.Initials, &user.ProfileBgColor}
role, err := r.Repository.GetRoleForProjectMemberByUserID(ctx, db.GetRoleForProjectMemberByUserIDParams{UserID: input.UserID, ProjectID: input.ProjectID})
if err != nil {
return &CreateProjectMemberPayload{Ok: false}, err
}
return &CreateProjectMemberPayload{Ok: true, Member: &Member{
ID: input.UserID,
FullName: user.FullName,
ProfileIcon: profileIcon,
Role: &db.Role{Code: role.Code, Name: role.Name},
}}, nil
2020-04-10 04:40:22 +02:00
}
func (r *mutationResolver) DeleteProjectMember(ctx context.Context, input DeleteProjectMember) (*DeleteProjectMemberPayload, error) {
err := r.Repository.DeleteProjectMember(ctx, db.DeleteProjectMemberParams{UserID: input.UserID, ProjectID: input.ProjectID})
if err != nil {
return &DeleteProjectMemberPayload{Ok: false}, err
}
user, err := r.Repository.GetUserAccountByID(ctx, input.UserID)
if err != nil {
return &DeleteProjectMemberPayload{Ok: false}, err
}
var url *string
if user.ProfileAvatarUrl.Valid {
url = &user.ProfileAvatarUrl.String
}
profileIcon := &ProfileIcon{url, &user.Initials, &user.ProfileBgColor}
role, err := r.Repository.GetRoleForProjectMemberByUserID(ctx, db.GetRoleForProjectMemberByUserIDParams{UserID: input.UserID, ProjectID: input.ProjectID})
if err != nil {
return &DeleteProjectMemberPayload{Ok: false}, err
}
return &DeleteProjectMemberPayload{Ok: true, Member: &Member{
ID: input.UserID,
FullName: user.FullName,
ProfileIcon: profileIcon,
Role: &db.Role{Code: role.Code, Name: role.Name},
}, ProjectID: input.ProjectID}, nil
}
func (r *mutationResolver) UpdateProjectMemberRole(ctx context.Context, input UpdateProjectMemberRole) (*UpdateProjectMemberRolePayload, error) {
if input.RoleCode == RoleCodeOwner {
return &UpdateProjectMemberRolePayload{Ok: false}, errors.New("can not set project owner through this mutation")
}
user, err := r.Repository.GetUserAccountByID(ctx, input.UserID)
2020-06-19 01:12:15 +02:00
if err != nil {
log.WithError(err).Error("get user account")
return &UpdateProjectMemberRolePayload{Ok: false}, err
2020-06-19 01:12:15 +02:00
}
_, err = r.Repository.UpdateProjectMemberRole(ctx, db.UpdateProjectMemberRoleParams{ProjectID: input.ProjectID,
UserID: input.UserID, RoleCode: input.RoleCode.String()})
if err != nil {
log.WithError(err).Error("update project member role")
return &UpdateProjectMemberRolePayload{Ok: false}, err
}
role, err := r.Repository.GetRoleForProjectMemberByUserID(ctx, db.GetRoleForProjectMemberByUserIDParams{UserID: user.UserID, ProjectID: input.ProjectID})
if err != nil {
log.WithError(err).Error("get role for project member")
return &UpdateProjectMemberRolePayload{Ok: false}, err
}
var url *string
if user.ProfileAvatarUrl.Valid {
url = &user.ProfileAvatarUrl.String
}
profileIcon := &ProfileIcon{url, &user.Initials, &user.ProfileBgColor}
if user.ProfileAvatarUrl.Valid {
url = &user.ProfileAvatarUrl.String
}
member := Member{ID: user.UserID, FullName: user.FullName, ProfileIcon: profileIcon,
Role: &db.Role{Code: role.Code, Name: role.Name},
}
return &UpdateProjectMemberRolePayload{Ok: true, Member: &member}, err
2020-06-13 00:21:58 +02:00
}
func (r *mutationResolver) SetProjectOwner(ctx context.Context, input SetProjectOwner) (*SetProjectOwnerPayload, error) {
project, err := r.Repository.GetProjectByID(ctx, input.ProjectID)
if project.Owner == input.OwnerID {
return &SetProjectOwnerPayload{Ok: false}, errors.New("new project owner is already project owner")
}
_, err = r.Repository.SetProjectOwner(ctx, db.SetProjectOwnerParams{Owner: input.OwnerID, ProjectID: input.ProjectID})
2020-04-11 21:24:45 +02:00
if err != nil {
return &SetProjectOwnerPayload{Ok: false}, err
2020-04-11 21:24:45 +02:00
}
err = r.Repository.DeleteProjectMember(ctx, db.DeleteProjectMemberParams{ProjectID: input.ProjectID, UserID: input.OwnerID})
2020-04-11 21:24:45 +02:00
if err != nil {
return &SetProjectOwnerPayload{Ok: false}, err
2020-04-11 21:24:45 +02:00
}
addedAt := time.Now().UTC()
_, err = r.Repository.CreateProjectMember(ctx, db.CreateProjectMemberParams{ProjectID: input.ProjectID,
UserID: project.Owner, RoleCode: RoleCodeAdmin.String(), AddedAt: addedAt})
2020-04-11 21:24:45 +02:00
if err != nil {
return &SetProjectOwnerPayload{Ok: false}, err
2020-04-11 21:24:45 +02:00
}
oldUser, err := r.Repository.GetUserAccountByID(ctx, project.Owner)
var url *string
if oldUser.ProfileAvatarUrl.Valid {
url = &oldUser.ProfileAvatarUrl.String
}
profileIcon := &ProfileIcon{url, &oldUser.Initials, &oldUser.ProfileBgColor}
oldUserRole := db.Role{Code: "admin", Name: "Admin"}
oldMember := &Member{
ID: oldUser.UserID,
Username: oldUser.Username,
FullName: oldUser.FullName,
ProfileIcon: profileIcon,
Role: &oldUserRole,
}
newUser, err := r.Repository.GetUserAccountByID(ctx, input.OwnerID)
if newUser.ProfileAvatarUrl.Valid {
url = &newUser.ProfileAvatarUrl.String
}
profileIcon = &ProfileIcon{url, &newUser.Initials, &newUser.ProfileBgColor}
newUserRole := db.Role{Code: "owner", Name: "Owner"}
newMember := &Member{
ID: newUser.UserID,
Username: newUser.Username,
FullName: newUser.FullName,
ProfileIcon: profileIcon,
Role: &newUserRole,
}
return &SetProjectOwnerPayload{
Ok: true,
PrevOwner: oldMember,
NewOwner: newMember,
}, nil
2020-04-11 21:24:45 +02:00
}
func (r *mutationResolver) CreateTask(ctx context.Context, input NewTask) (*db.Task, error) {
taskGroupID, err := uuid.Parse(input.TaskGroupID)
createdAt := time.Now().UTC()
2020-04-20 05:02:55 +02:00
if err != nil {
return &db.Task{}, err
2020-04-20 05:02:55 +02:00
}
task, err := r.Repository.CreateTask(ctx, db.CreateTaskParams{taskGroupID, createdAt, input.Name, input.Position})
return &task, err
2020-04-20 05:02:55 +02:00
}
func (r *mutationResolver) DeleteTask(ctx context.Context, input DeleteTaskInput) (*DeleteTaskPayload, error) {
taskID, err := uuid.Parse(input.TaskID)
2020-05-31 06:11:19 +02:00
if err != nil {
return &DeleteTaskPayload{}, err
2020-05-31 06:11:19 +02:00
}
log.WithFields(log.Fields{
"taskID": taskID.String(),
}).Info("deleting task")
err = r.Repository.DeleteTaskByID(ctx, taskID)
2020-05-31 06:11:19 +02:00
if err != nil {
return &DeleteTaskPayload{}, err
2020-05-31 06:11:19 +02:00
}
return &DeleteTaskPayload{taskID.String()}, nil
}
func (r *mutationResolver) UpdateTaskDescription(ctx context.Context, input UpdateTaskDescriptionInput) (*db.Task, error) {
task, err := r.Repository.UpdateTaskDescription(ctx, db.UpdateTaskDescriptionParams{input.TaskID, sql.NullString{String: input.Description, Valid: true}})
2020-05-31 06:11:19 +02:00
return &task, err
}
func (r *mutationResolver) UpdateTaskLocation(ctx context.Context, input NewTaskLocation) (*UpdateTaskLocationPayload, error) {
previousTask, err := r.Repository.GetTaskByID(ctx, input.TaskID)
2020-05-31 06:11:19 +02:00
if err != nil {
return &UpdateTaskLocationPayload{}, err
2020-05-31 06:11:19 +02:00
}
task, err := r.Repository.UpdateTaskLocation(ctx, db.UpdateTaskLocationParams{input.TaskID, input.TaskGroupID, input.Position})
2020-05-31 06:11:19 +02:00
return &UpdateTaskLocationPayload{Task: &task, PreviousTaskGroupID: previousTask.TaskGroupID}, err
}
2020-05-31 06:11:19 +02:00
func (r *mutationResolver) UpdateTaskName(ctx context.Context, input UpdateTaskName) (*db.Task, error) {
taskID, err := uuid.Parse(input.TaskID)
if err != nil {
return &db.Task{}, err
2020-05-31 06:11:19 +02:00
}
task, err := r.Repository.UpdateTaskName(ctx, db.UpdateTaskNameParams{taskID, input.Name})
return &task, err
}
2020-05-31 06:11:19 +02:00
func (r *mutationResolver) SetTaskComplete(ctx context.Context, input SetTaskComplete) (*db.Task, error) {
task, err := r.Repository.SetTaskComplete(ctx, db.SetTaskCompleteParams{TaskID: input.TaskID, Complete: input.Complete})
2020-05-31 06:11:19 +02:00
if err != nil {
return &db.Task{}, err
2020-05-31 06:11:19 +02:00
}
return &task, nil
}
2020-05-31 06:11:19 +02:00
func (r *mutationResolver) UpdateTaskDueDate(ctx context.Context, input UpdateTaskDueDate) (*db.Task, error) {
var dueDate sql.NullTime
if input.DueDate == nil {
dueDate = sql.NullTime{Valid: false, Time: time.Now()}
} else {
dueDate = sql.NullTime{Valid: true, Time: *input.DueDate}
}
task, err := r.Repository.UpdateTaskDueDate(ctx, db.UpdateTaskDueDateParams{
TaskID: input.TaskID,
DueDate: dueDate,
2020-05-31 06:11:19 +02:00
})
return &task, err
}
func (r *mutationResolver) AssignTask(ctx context.Context, input *AssignTaskInput) (*db.Task, error) {
assignedDate := time.Now().UTC()
assignedTask, err := r.Repository.CreateTaskAssigned(ctx, db.CreateTaskAssignedParams{input.TaskID, input.UserID, assignedDate})
log.WithFields(log.Fields{
"userID": assignedTask.UserID,
"taskID": assignedTask.TaskID,
"assignedTaskID": assignedTask.TaskAssignedID,
}).Info("assigned task")
2020-05-31 06:11:19 +02:00
if err != nil {
return &db.Task{}, err
2020-05-31 06:11:19 +02:00
}
task, err := r.Repository.GetTaskByID(ctx, input.TaskID)
return &task, err
}
2020-05-31 06:11:19 +02:00
func (r *mutationResolver) UnassignTask(ctx context.Context, input *UnassignTaskInput) (*db.Task, error) {
task, err := r.Repository.GetTaskByID(ctx, input.TaskID)
if err != nil {
return &db.Task{}, err
}
_, err = r.Repository.DeleteTaskAssignedByID(ctx, db.DeleteTaskAssignedByIDParams{input.TaskID, input.UserID})
if err != nil {
return &db.Task{}, err
}
return &task, nil
2020-04-20 05:02:55 +02:00
}
func (r *mutationResolver) CreateTaskChecklist(ctx context.Context, input CreateTaskChecklist) (*db.TaskChecklist, error) {
2020-06-19 01:12:15 +02:00
createdAt := time.Now().UTC()
taskChecklist, err := r.Repository.CreateTaskChecklist(ctx, db.CreateTaskChecklistParams{
2020-06-19 01:12:15 +02:00
TaskID: input.TaskID,
CreatedAt: createdAt,
Name: input.Name,
Position: input.Position,
})
if err != nil {
return &db.TaskChecklist{}, err
2020-06-19 01:12:15 +02:00
}
return &taskChecklist, nil
}
func (r *mutationResolver) DeleteTaskChecklist(ctx context.Context, input DeleteTaskChecklist) (*DeleteTaskChecklistPayload, error) {
taskChecklist, err := r.Repository.GetTaskChecklistByID(ctx, input.TaskChecklistID)
if err != nil {
return &DeleteTaskChecklistPayload{Ok: false}, err
}
err = r.Repository.DeleteTaskChecklistByID(ctx, input.TaskChecklistID)
if err != nil {
return &DeleteTaskChecklistPayload{Ok: false}, err
}
return &DeleteTaskChecklistPayload{Ok: true, TaskChecklist: &taskChecklist}, nil
}
func (r *mutationResolver) UpdateTaskChecklistName(ctx context.Context, input UpdateTaskChecklistName) (*db.TaskChecklist, error) {
checklist, err := r.Repository.UpdateTaskChecklistName(ctx, db.UpdateTaskChecklistNameParams{TaskChecklistID: input.TaskChecklistID, Name: input.Name})
if err != nil {
return &db.TaskChecklist{}, err
}
return &checklist, nil
}
func (r *mutationResolver) CreateTaskChecklistItem(ctx context.Context, input CreateTaskChecklistItem) (*db.TaskChecklistItem, error) {
2020-06-19 01:12:15 +02:00
createdAt := time.Now().UTC()
taskChecklistItem, err := r.Repository.CreateTaskChecklistItem(ctx, db.CreateTaskChecklistItemParams{
2020-06-19 01:12:15 +02:00
TaskChecklistID: input.TaskChecklistID,
CreatedAt: createdAt,
Name: input.Name,
Position: input.Position,
})
if err != nil {
return &db.TaskChecklistItem{}, err
2020-06-19 01:12:15 +02:00
}
return &taskChecklistItem, nil
}
func (r *mutationResolver) UpdateTaskChecklistItemName(ctx context.Context, input UpdateTaskChecklistItemName) (*db.TaskChecklistItem, error) {
task, err := r.Repository.UpdateTaskChecklistItemName(ctx, db.UpdateTaskChecklistItemNameParams{TaskChecklistItemID: input.TaskChecklistItemID,
2020-06-19 01:12:15 +02:00
Name: input.Name,
})
if err != nil {
return &db.TaskChecklistItem{}, err
2020-06-19 01:12:15 +02:00
}
return &task, nil
}
func (r *mutationResolver) SetTaskChecklistItemComplete(ctx context.Context, input SetTaskChecklistItemComplete) (*db.TaskChecklistItem, error) {
item, err := r.Repository.SetTaskChecklistItemComplete(ctx, db.SetTaskChecklistItemCompleteParams{TaskChecklistItemID: input.TaskChecklistItemID, Complete: input.Complete})
2020-06-19 01:12:15 +02:00
if err != nil {
return &db.TaskChecklistItem{}, err
2020-06-19 01:12:15 +02:00
}
return &item, nil
}
func (r *mutationResolver) DeleteTaskChecklistItem(ctx context.Context, input DeleteTaskChecklistItem) (*DeleteTaskChecklistItemPayload, error) {
item, err := r.Repository.GetTaskChecklistItemByID(ctx, input.TaskChecklistItemID)
if err != nil {
return &DeleteTaskChecklistItemPayload{
Ok: false,
TaskChecklistItem: &db.TaskChecklistItem{},
2020-06-19 01:12:15 +02:00
}, err
}
err = r.Repository.DeleteTaskChecklistItem(ctx, input.TaskChecklistItemID)
if err != nil {
return &DeleteTaskChecklistItemPayload{
Ok: false,
TaskChecklistItem: &db.TaskChecklistItem{},
2020-06-19 01:12:15 +02:00
}, err
}
return &DeleteTaskChecklistItemPayload{
Ok: true,
TaskChecklistItem: &item,
}, err
}
2020-07-12 09:06:11 +02:00
func (r *mutationResolver) UpdateTaskChecklistLocation(ctx context.Context, input UpdateTaskChecklistLocation) (*UpdateTaskChecklistLocationPayload, error) {
checklist, err := r.Repository.UpdateTaskChecklistPosition(ctx, db.UpdateTaskChecklistPositionParams{Position: input.Position, TaskChecklistID: input.ChecklistID})
if err != nil {
return &UpdateTaskChecklistLocationPayload{}, err
}
return &UpdateTaskChecklistLocationPayload{Checklist: &checklist}, nil
}
func (r *mutationResolver) UpdateTaskChecklistItemLocation(ctx context.Context, input UpdateTaskChecklistItemLocation) (*UpdateTaskChecklistItemLocationPayload, error) {
currentChecklistItem, err := r.Repository.GetTaskChecklistItemByID(ctx, input.ChecklistItemID)
checklistItem, err := r.Repository.UpdateTaskChecklistItemLocation(ctx, db.UpdateTaskChecklistItemLocationParams{TaskChecklistID: input.ChecklistID, TaskChecklistItemID: input.ChecklistItemID, Position: input.Position})
if err != nil {
return &UpdateTaskChecklistItemLocationPayload{}, err
}
return &UpdateTaskChecklistItemLocationPayload{PrevChecklistID: currentChecklistItem.TaskChecklistID, ChecklistID: input.ChecklistID, ChecklistItem: &checklistItem}, err
}
func (r *mutationResolver) CreateTaskGroup(ctx context.Context, input NewTaskGroup) (*db.TaskGroup, error) {
2020-04-10 04:40:22 +02:00
createdAt := time.Now().UTC()
projectID, err := uuid.Parse(input.ProjectID)
2020-04-10 04:40:22 +02:00
if err != nil {
return &db.TaskGroup{}, err
2020-04-10 04:40:22 +02:00
}
project, err := r.Repository.CreateTaskGroup(ctx,
db.CreateTaskGroupParams{projectID, createdAt, input.Name, input.Position})
return &project, err
}
2020-04-10 04:40:22 +02:00
func (r *mutationResolver) UpdateTaskGroupLocation(ctx context.Context, input NewTaskGroupLocation) (*db.TaskGroup, error) {
taskGroup, err := r.Repository.UpdateTaskGroupLocation(ctx, db.UpdateTaskGroupLocationParams{
input.TaskGroupID,
input.Position,
})
return &taskGroup, err
2020-04-10 04:40:22 +02:00
}
func (r *mutationResolver) UpdateTaskGroupName(ctx context.Context, input UpdateTaskGroupName) (*db.TaskGroup, error) {
taskGroup, err := r.Repository.SetTaskGroupName(ctx, db.SetTaskGroupNameParams{TaskGroupID: input.TaskGroupID, Name: input.Name})
if err != nil {
return &db.TaskGroup{}, err
}
return &taskGroup, nil
2020-04-20 05:02:55 +02:00
}
func (r *mutationResolver) DeleteTaskGroup(ctx context.Context, input DeleteTaskGroupInput) (*DeleteTaskGroupPayload, error) {
deletedTasks, err := r.Repository.DeleteTasksByTaskGroupID(ctx, input.TaskGroupID)
2020-04-10 04:40:22 +02:00
if err != nil {
return &DeleteTaskGroupPayload{}, err
}
taskGroup, err := r.Repository.GetTaskGroupByID(ctx, input.TaskGroupID)
if err != nil {
return &DeleteTaskGroupPayload{}, err
}
deletedTaskGroups, err := r.Repository.DeleteTaskGroupByID(ctx, input.TaskGroupID)
if err != nil {
return &DeleteTaskGroupPayload{}, err
2020-04-10 04:40:22 +02:00
}
return &DeleteTaskGroupPayload{true, int(deletedTasks + deletedTaskGroups), &taskGroup}, nil
}
2020-04-10 04:40:22 +02:00
func (r *mutationResolver) AddTaskLabel(ctx context.Context, input *AddTaskLabelInput) (*db.Task, error) {
assignedDate := time.Now().UTC()
_, err := r.Repository.CreateTaskLabelForTask(ctx, db.CreateTaskLabelForTaskParams{input.TaskID, input.ProjectLabelID, assignedDate})
if err != nil {
return &db.Task{}, err
}
task, err := r.Repository.GetTaskByID(ctx, input.TaskID)
return &task, nil
2020-04-10 04:40:22 +02:00
}
func (r *mutationResolver) RemoveTaskLabel(ctx context.Context, input *RemoveTaskLabelInput) (*db.Task, error) {
taskLabel, err := r.Repository.GetTaskLabelByID(ctx, input.TaskLabelID)
2020-04-10 04:40:22 +02:00
if err != nil {
return &db.Task{}, err
2020-04-10 04:40:22 +02:00
}
task, err := r.Repository.GetTaskByID(ctx, taskLabel.TaskID)
if err != nil {
return &db.Task{}, err
}
err = r.Repository.DeleteTaskLabelByID(ctx, input.TaskLabelID)
2020-04-10 04:40:22 +02:00
return &task, err
}
func (r *mutationResolver) ToggleTaskLabel(ctx context.Context, input ToggleTaskLabelInput) (*ToggleTaskLabelPayload, error) {
task, err := r.Repository.GetTaskByID(ctx, input.TaskID)
2020-06-19 01:12:15 +02:00
if err != nil {
return &ToggleTaskLabelPayload{}, err
2020-06-19 01:12:15 +02:00
}
_, err = r.Repository.GetTaskLabelForTaskByProjectLabelID(ctx, db.GetTaskLabelForTaskByProjectLabelIDParams{TaskID: input.TaskID, ProjectLabelID: input.ProjectLabelID})
createdAt := time.Now().UTC()
if err == sql.ErrNoRows {
log.WithFields(log.Fields{"err": err}).Warning("no rows")
_, err := r.Repository.CreateTaskLabelForTask(ctx, db.CreateTaskLabelForTaskParams{
TaskID: input.TaskID,
ProjectLabelID: input.ProjectLabelID,
AssignedDate: createdAt,
})
if err != nil {
return &ToggleTaskLabelPayload{}, err
}
payload := ToggleTaskLabelPayload{Active: true, Task: &task}
return &payload, nil
2020-06-16 00:36:59 +02:00
}
if err != nil {
return &ToggleTaskLabelPayload{}, err
}
err = r.Repository.DeleteTaskLabelForTaskByProjectLabelID(ctx, db.DeleteTaskLabelForTaskByProjectLabelIDParams{
TaskID: input.TaskID,
ProjectLabelID: input.ProjectLabelID,
2020-06-16 00:36:59 +02:00
})
if err != nil {
return &ToggleTaskLabelPayload{}, err
}
payload := ToggleTaskLabelPayload{Active: false, Task: &task}
return &payload, nil
2020-06-16 00:36:59 +02:00
}
func (r *mutationResolver) DeleteTeam(ctx context.Context, input DeleteTeam) (*DeleteTeamPayload, error) {
team, err := r.Repository.GetTeamByID(ctx, input.TeamID)
2020-04-10 04:40:22 +02:00
if err != nil {
log.Error(err)
return &DeleteTeamPayload{Ok: false}, err
}
projects, err := r.Repository.GetAllProjectsForTeam(ctx, input.TeamID)
if err != nil {
log.Error(err)
return &DeleteTeamPayload{Ok: false}, err
}
err = r.Repository.DeleteTeamByID(ctx, input.TeamID)
if err != nil {
log.Error(err)
return &DeleteTeamPayload{Ok: false}, err
2020-04-10 04:40:22 +02:00
}
return &DeleteTeamPayload{Ok: true, Team: &team, Projects: projects}, nil
}
func (r *mutationResolver) CreateTeam(ctx context.Context, input NewTeam) (*db.Team, error) {
userID, ok := GetUserID(ctx)
if !ok {
return &db.Team{}, fmt.Errorf("internal server error")
}
createdAt := time.Now().UTC()
team, err := r.Repository.CreateTeam(ctx, db.CreateTeamParams{OrganizationID: input.OrganizationID, CreatedAt: createdAt, Name: input.Name, Owner: userID})
return &team, err
}
func (r *mutationResolver) SetTeamOwner(ctx context.Context, input SetTeamOwner) (*SetTeamOwnerPayload, error) {
team, err := r.Repository.GetTeamByID(ctx, input.TeamID)
if team.Owner == input.UserID {
return &SetTeamOwnerPayload{Ok: false}, errors.New("new project owner is already project owner")
}
_, err = r.Repository.SetTeamOwner(ctx, db.SetTeamOwnerParams{Owner: input.UserID, TeamID: input.TeamID})
2020-04-10 04:40:22 +02:00
if err != nil {
return &SetTeamOwnerPayload{Ok: false}, errors.New("new project owner is already project owner")
2020-04-10 04:40:22 +02:00
}
err = r.Repository.DeleteTeamMember(ctx, db.DeleteTeamMemberParams{TeamID: input.TeamID, UserID: input.UserID})
if err != nil {
return &SetTeamOwnerPayload{Ok: false}, errors.New("new project owner is already project owner")
}
addedAt := time.Now().UTC()
_, err = r.Repository.CreateTeamMember(ctx, db.CreateTeamMemberParams{TeamID: input.TeamID,
UserID: team.Owner, RoleCode: RoleCodeAdmin.String(), Addeddate: addedAt})
if err != nil {
return &SetTeamOwnerPayload{Ok: false}, errors.New("new project owner is already project owner")
}
oldUser, err := r.Repository.GetUserAccountByID(ctx, team.Owner)
var url *string
if oldUser.ProfileAvatarUrl.Valid {
url = &oldUser.ProfileAvatarUrl.String
}
profileIcon := &ProfileIcon{url, &oldUser.Initials, &oldUser.ProfileBgColor}
oldUserRole := db.Role{Code: "admin", Name: "Admin"}
oldMember := &Member{
ID: oldUser.UserID,
Username: oldUser.Username,
FullName: oldUser.FullName,
ProfileIcon: profileIcon,
Role: &oldUserRole,
}
newUser, err := r.Repository.GetUserAccountByID(ctx, input.UserID)
if newUser.ProfileAvatarUrl.Valid {
url = &newUser.ProfileAvatarUrl.String
}
profileIcon = &ProfileIcon{url, &newUser.Initials, &newUser.ProfileBgColor}
newUserRole := db.Role{Code: "owner", Name: "Owner"}
newMember := &Member{
ID: newUser.UserID,
Username: newUser.Username,
FullName: newUser.FullName,
ProfileIcon: profileIcon,
Role: &newUserRole,
}
return &SetTeamOwnerPayload{
Ok: true,
PrevOwner: oldMember,
NewOwner: newMember,
}, nil
2020-04-10 04:40:22 +02:00
}
func (r *mutationResolver) CreateTeamMember(ctx context.Context, input CreateTeamMember) (*CreateTeamMemberPayload, error) {
addedDate := time.Now().UTC()
team, err := r.Repository.GetTeamByID(ctx, input.TeamID)
2020-04-20 05:02:55 +02:00
if err != nil {
return &CreateTeamMemberPayload{}, err
2020-04-20 05:02:55 +02:00
}
_, err = r.Repository.CreateTeamMember(ctx, db.CreateTeamMemberParams{TeamID: input.TeamID, UserID: input.UserID, Addeddate: addedDate, RoleCode: RoleCodeMember.String()})
user, err := r.Repository.GetUserAccountByID(ctx, input.UserID)
if err != nil {
return &CreateTeamMemberPayload{}, err
}
var url *string
if user.ProfileAvatarUrl.Valid {
url = &user.ProfileAvatarUrl.String
}
profileIcon := &ProfileIcon{url, &user.Initials, &user.ProfileBgColor}
return &CreateTeamMemberPayload{
Team: &team,
TeamMember: &Member{
ID: user.UserID,
Username: user.Username,
FullName: user.FullName,
ProfileIcon: profileIcon,
Role: &db.Role{Code: "member", Name: "Member"},
}}, nil
2020-04-20 05:02:55 +02:00
}
func (r *mutationResolver) UpdateTeamMemberRole(ctx context.Context, input UpdateTeamMemberRole) (*UpdateTeamMemberRolePayload, error) {
if input.RoleCode == RoleCodeOwner || input.RoleCode == RoleCodeObserver {
return &UpdateTeamMemberRolePayload{Ok: false}, errors.New("can not set project owner through this mutation")
}
user, err := r.Repository.GetUserAccountByID(ctx, input.UserID)
2020-04-21 01:04:27 +02:00
if err != nil {
log.WithError(err).Error("get user account")
return &UpdateTeamMemberRolePayload{Ok: false}, err
2020-04-21 01:04:27 +02:00
}
_, err = r.Repository.UpdateTeamMemberRole(ctx, db.UpdateTeamMemberRoleParams{TeamID: input.TeamID,
UserID: input.UserID, RoleCode: input.RoleCode.String()})
2020-04-21 01:04:27 +02:00
if err != nil {
log.WithError(err).Error("update project member role")
return &UpdateTeamMemberRolePayload{Ok: false}, err
2020-04-21 01:04:27 +02:00
}
role, err := r.Repository.GetRoleForTeamMember(ctx, db.GetRoleForTeamMemberParams{UserID: user.UserID, TeamID: input.TeamID})
if err != nil {
log.WithError(err).Error("get role for project member")
return &UpdateTeamMemberRolePayload{Ok: false}, err
}
var url *string
if user.ProfileAvatarUrl.Valid {
url = &user.ProfileAvatarUrl.String
}
profileIcon := &ProfileIcon{url, &user.Initials, &user.ProfileBgColor}
if user.ProfileAvatarUrl.Valid {
url = &user.ProfileAvatarUrl.String
}
member := Member{ID: user.UserID, FullName: user.FullName, ProfileIcon: profileIcon,
Role: &db.Role{Code: role.Code, Name: role.Name},
}
return &UpdateTeamMemberRolePayload{Ok: true, Member: &member}, err
}
func (r *mutationResolver) DeleteTeamMember(ctx context.Context, input DeleteTeamMember) (*DeleteTeamMemberPayload, error) {
2020-07-12 09:06:11 +02:00
ownedProjects, err := r.Repository.GetOwnedTeamProjectsForUserID(ctx, db.GetOwnedTeamProjectsForUserIDParams{TeamID: input.TeamID, Owner: input.UserID})
if err != nil {
return &DeleteTeamMemberPayload{}, err
}
_, err = r.Repository.GetTeamMemberByID(ctx, db.GetTeamMemberByIDParams{TeamID: input.TeamID, UserID: input.UserID})
if err != nil {
return &DeleteTeamMemberPayload{}, err
}
err = r.Repository.DeleteTeamMember(ctx, db.DeleteTeamMemberParams{TeamID: input.TeamID, UserID: input.UserID})
if err != nil {
return &DeleteTeamMemberPayload{}, err
}
2020-07-12 09:06:11 +02:00
if input.NewOwnerID != nil {
for _, projectID := range ownedProjects {
_, err = r.Repository.SetProjectOwner(ctx, db.SetProjectOwnerParams{ProjectID: projectID, Owner: *input.NewOwnerID})
}
}
return &DeleteTeamMemberPayload{TeamID: input.TeamID, UserID: input.UserID}, nil
}
func (r *mutationResolver) CreateRefreshToken(ctx context.Context, input NewRefreshToken) (*db.RefreshToken, error) {
userID := uuid.MustParse("0183d9ab-d0ed-4c9b-a3df-77a0cdd93dca")
refreshCreatedAt := time.Now().UTC()
refreshExpiresAt := refreshCreatedAt.AddDate(0, 0, 1)
refreshToken, err := r.Repository.CreateRefreshToken(ctx, db.CreateRefreshTokenParams{userID, refreshCreatedAt, refreshExpiresAt})
return &refreshToken, err
}
func (r *mutationResolver) CreateUserAccount(ctx context.Context, input NewUserAccount) (*db.UserAccount, error) {
createdAt := time.Now().UTC()
hashedPwd, err := bcrypt.GenerateFromPassword([]byte(input.Password), 14)
if err != nil {
return &db.UserAccount{}, err
}
userAccount, err := r.Repository.CreateUserAccount(ctx, db.CreateUserAccountParams{
FullName: input.FullName,
RoleCode: input.RoleCode,
Initials: input.Initials,
Email: input.Email,
Username: input.Username,
CreatedAt: createdAt,
PasswordHash: string(hashedPwd),
})
return &userAccount, err
}
func (r *mutationResolver) DeleteUserAccount(ctx context.Context, input DeleteUserAccount) (*DeleteUserAccountPayload, error) {
user, err := r.Repository.GetUserAccountByID(ctx, input.UserID)
if err != nil {
return &DeleteUserAccountPayload{Ok: false}, err
}
err = r.Repository.DeleteUserAccountByID(ctx, input.UserID)
if err != nil {
return &DeleteUserAccountPayload{Ok: false}, err
}
return &DeleteUserAccountPayload{UserAccount: &user, Ok: true}, nil
2020-04-21 01:04:27 +02:00
}
2020-04-11 21:24:45 +02:00
func (r *mutationResolver) LogoutUser(ctx context.Context, input LogoutUser) (bool, error) {
userID, err := uuid.Parse(input.UserID)
if err != nil {
return false, err
}
err = r.Repository.DeleteRefreshTokenByUserID(ctx, userID)
return true, err
}
func (r *mutationResolver) ClearProfileAvatar(ctx context.Context) (*db.UserAccount, error) {
userID, ok := GetUserID(ctx)
if !ok {
return &db.UserAccount{}, fmt.Errorf("internal server error")
}
user, err := r.Repository.UpdateUserAccountProfileAvatarURL(ctx, db.UpdateUserAccountProfileAvatarURLParams{UserID: userID, ProfileAvatarUrl: sql.NullString{Valid: false, String: ""}})
if err != nil {
return &db.UserAccount{}, err
}
return &user, nil
}
2020-07-12 09:06:11 +02:00
func (r *mutationResolver) UpdateUserRole(ctx context.Context, input UpdateUserRole) (*UpdateUserRolePayload, error) {
user, err := r.Repository.UpdateUserRole(ctx, db.UpdateUserRoleParams{RoleCode: input.RoleCode.String(), UserID: input.UserID})
if err != nil {
return &UpdateUserRolePayload{}, err
}
return &UpdateUserRolePayload{User: &user}, nil
}
func (r *organizationResolver) ID(ctx context.Context, obj *db.Organization) (uuid.UUID, error) {
return obj.OrganizationID, nil
}
func (r *projectResolver) ID(ctx context.Context, obj *db.Project) (uuid.UUID, error) {
2020-05-27 02:53:31 +02:00
return obj.ProjectID, nil
}
func (r *projectResolver) Team(ctx context.Context, obj *db.Project) (*db.Team, error) {
2020-04-20 05:02:55 +02:00
team, err := r.Repository.GetTeamByID(ctx, obj.TeamID)
return &team, err
2020-04-10 04:40:22 +02:00
}
func (r *projectResolver) Owner(ctx context.Context, obj *db.Project) (*Member, error) {
2020-04-20 05:02:55 +02:00
user, err := r.Repository.GetUserAccountByID(ctx, obj.Owner)
if err != nil {
return &Member{}, err
2020-04-20 05:02:55 +02:00
}
2020-06-13 00:21:58 +02:00
var url *string
if user.ProfileAvatarUrl.Valid {
url = &user.ProfileAvatarUrl.String
}
profileIcon := &ProfileIcon{url, &user.Initials, &user.ProfileBgColor}
role, err := r.Repository.GetRoleForProjectMemberByUserID(ctx, db.GetRoleForProjectMemberByUserIDParams{UserID: user.UserID, ProjectID: obj.ProjectID})
if user.ProfileAvatarUrl.Valid {
url = &user.ProfileAvatarUrl.String
}
return &Member{ID: obj.Owner, FullName: user.FullName, ProfileIcon: profileIcon,
Role: &db.Role{Code: role.Code, Name: role.Name},
}, nil
2020-04-10 04:40:22 +02:00
}
func (r *projectResolver) TaskGroups(ctx context.Context, obj *db.Project) ([]db.TaskGroup, error) {
2020-04-10 04:40:22 +02:00
return r.Repository.GetTaskGroupsForProject(ctx, obj.ProjectID)
}
func (r *projectResolver) Members(ctx context.Context, obj *db.Project) ([]Member, error) {
2020-04-20 05:02:55 +02:00
user, err := r.Repository.GetUserAccountByID(ctx, obj.Owner)
members := []Member{}
if err == sql.ErrNoRows {
return members, nil
}
2020-04-20 05:02:55 +02:00
if err != nil {
log.WithError(err).Error("get user account by ID")
2020-04-20 05:02:55 +02:00
return members, err
}
2020-06-13 00:21:58 +02:00
var url *string
if user.ProfileAvatarUrl.Valid {
url = &user.ProfileAvatarUrl.String
}
profileIcon := &ProfileIcon{url, &user.Initials, &user.ProfileBgColor}
members = append(members, Member{
ID: obj.Owner, FullName: user.FullName, ProfileIcon: profileIcon, Username: user.Username,
Role: &db.Role{Code: "owner", Name: "Owner"},
})
projectMembers, err := r.Repository.GetProjectMembersForProjectID(ctx, obj.ProjectID)
if err != nil {
log.WithError(err).Error("get project members for project id")
return members, err
}
for _, projectMember := range projectMembers {
user, err = r.Repository.GetUserAccountByID(ctx, projectMember.UserID)
if err != nil {
log.WithError(err).Error("get user account by ID")
return members, err
}
var url *string
if user.ProfileAvatarUrl.Valid {
url = &user.ProfileAvatarUrl.String
}
role, err := r.Repository.GetRoleForProjectMemberByUserID(ctx, db.GetRoleForProjectMemberByUserIDParams{UserID: user.UserID, ProjectID: obj.ProjectID})
if err != nil {
log.WithError(err).Error("get role for projet member by user ID")
return members, err
}
profileIcon := &ProfileIcon{url, &user.Initials, &user.ProfileBgColor}
members = append(members, Member{ID: user.UserID, FullName: user.FullName, ProfileIcon: profileIcon,
Username: user.Username, Role: &db.Role{Code: role.Code, Name: role.Name},
})
}
2020-04-20 05:02:55 +02:00
return members, nil
2020-04-10 04:40:22 +02:00
}
func (r *projectResolver) Labels(ctx context.Context, obj *db.Project) ([]db.ProjectLabel, error) {
2020-04-21 01:04:27 +02:00
labels, err := r.Repository.GetProjectLabelsForProject(ctx, obj.ProjectID)
return labels, err
}
func (r *projectLabelResolver) ID(ctx context.Context, obj *db.ProjectLabel) (uuid.UUID, error) {
2020-05-27 02:53:31 +02:00
return obj.ProjectLabelID, nil
}
func (r *projectLabelResolver) LabelColor(ctx context.Context, obj *db.ProjectLabel) (*db.LabelColor, error) {
2020-04-21 01:04:27 +02:00
labelColor, err := r.Repository.GetLabelColorByID(ctx, obj.LabelColorID)
if err != nil {
return &db.LabelColor{}, err
2020-04-21 01:04:27 +02:00
}
2020-05-27 23:18:50 +02:00
return &labelColor, nil
2020-04-21 01:04:27 +02:00
}
func (r *projectLabelResolver) Name(ctx context.Context, obj *db.ProjectLabel) (*string, error) {
2020-05-27 02:53:31 +02:00
var name *string
if obj.Name.Valid {
name = &obj.Name.String
}
return name, nil
2020-04-21 01:04:27 +02:00
}
func (r *queryResolver) Organizations(ctx context.Context) ([]db.Organization, error) {
return r.Repository.GetAllOrganizations(ctx)
}
func (r *queryResolver) Users(ctx context.Context) ([]db.UserAccount, error) {
2020-04-10 04:40:22 +02:00
return r.Repository.GetAllUserAccounts(ctx)
}
func (r *queryResolver) FindUser(ctx context.Context, input FindUser) (*db.UserAccount, error) {
2020-04-10 04:40:22 +02:00
userId, err := uuid.Parse(input.UserID)
if err != nil {
return &db.UserAccount{}, err
2020-04-10 04:40:22 +02:00
}
account, err := r.Repository.GetUserAccountByID(ctx, userId)
if err == sql.ErrNoRows {
return &db.UserAccount{}, &gqlerror.Error{
2020-04-10 04:40:22 +02:00
Message: "User not found",
Extensions: map[string]interface{}{
"code": "10-404",
},
}
}
return &account, err
}
func (r *queryResolver) FindProject(ctx context.Context, input FindProject) (*db.Project, error) {
2020-04-10 04:40:22 +02:00
projectID, err := uuid.Parse(input.ProjectID)
if err != nil {
return &db.Project{}, err
2020-04-10 04:40:22 +02:00
}
project, err := r.Repository.GetProjectByID(ctx, projectID)
if err == sql.ErrNoRows {
return &db.Project{}, &gqlerror.Error{
2020-04-10 04:40:22 +02:00
Message: "Project not found",
Extensions: map[string]interface{}{
"code": "11-404",
},
}
}
return &project, err
}
func (r *queryResolver) FindTask(ctx context.Context, input FindTask) (*db.Task, error) {
2020-04-20 05:02:55 +02:00
task, err := r.Repository.GetTaskByID(ctx, input.TaskID)
return &task, err
2020-04-10 04:40:22 +02:00
}
func (r *queryResolver) Projects(ctx context.Context, input *ProjectsFilter) ([]db.Project, error) {
2020-04-10 04:40:22 +02:00
if input != nil {
return r.Repository.GetAllProjectsForTeam(ctx, *input.TeamID)
2020-04-10 04:40:22 +02:00
}
return r.Repository.GetAllProjects(ctx)
}
func (r *queryResolver) FindTeam(ctx context.Context, input FindTeam) (*db.Team, error) {
team, err := r.Repository.GetTeamByID(ctx, input.TeamID)
if err != nil {
return &db.Team{}, err
}
return &team, nil
}
func (r *queryResolver) Teams(ctx context.Context) ([]db.Team, error) {
return r.Repository.GetAllTeams(ctx)
}
func (r *queryResolver) LabelColors(ctx context.Context) ([]db.LabelColor, error) {
2020-05-27 23:18:50 +02:00
return r.Repository.GetLabelColors(ctx)
}
func (r *queryResolver) TaskGroups(ctx context.Context) ([]db.TaskGroup, error) {
2020-04-10 04:40:22 +02:00
return r.Repository.GetAllTaskGroups(ctx)
}
func (r *queryResolver) Me(ctx context.Context) (*db.UserAccount, error) {
2020-04-20 05:02:55 +02:00
userID, ok := GetUserID(ctx)
if !ok {
return &db.UserAccount{}, fmt.Errorf("internal server error")
2020-04-20 05:02:55 +02:00
}
user, err := r.Repository.GetUserAccountByID(ctx, userID)
if err != nil {
return &db.UserAccount{}, err
2020-04-20 05:02:55 +02:00
}
return &user, err
}
func (r *refreshTokenResolver) ID(ctx context.Context, obj *db.RefreshToken) (uuid.UUID, error) {
2020-05-27 02:53:31 +02:00
return obj.TokenID, nil
}
func (r *taskResolver) ID(ctx context.Context, obj *db.Task) (uuid.UUID, error) {
2020-05-27 02:53:31 +02:00
return obj.TaskID, nil
}
func (r *taskResolver) TaskGroup(ctx context.Context, obj *db.Task) (*db.TaskGroup, error) {
taskGroup, err := r.Repository.GetTaskGroupByID(ctx, obj.TaskGroupID)
return &taskGroup, err
2020-04-10 04:40:22 +02:00
}
func (r *taskResolver) Description(ctx context.Context, obj *db.Task) (*string, error) {
2020-04-20 05:02:55 +02:00
task, err := r.Repository.GetTaskByID(ctx, obj.TaskID)
if err != nil {
return nil, err
}
if !task.Description.Valid {
return nil, nil
}
return &task.Description.String, nil
}
func (r *taskResolver) DueDate(ctx context.Context, obj *db.Task) (*time.Time, error) {
2020-06-16 00:36:59 +02:00
if obj.DueDate.Valid {
return &obj.DueDate.Time, nil
}
return nil, nil
}
func (r *taskResolver) Assigned(ctx context.Context, obj *db.Task) ([]Member, error) {
2020-04-20 05:02:55 +02:00
taskMemberLinks, err := r.Repository.GetAssignedMembersForTask(ctx, obj.TaskID)
taskMembers := []Member{}
2020-04-20 05:02:55 +02:00
if err != nil {
return taskMembers, err
}
for _, taskMemberLink := range taskMemberLinks {
user, err := r.Repository.GetUserAccountByID(ctx, taskMemberLink.UserID)
if err != nil {
return taskMembers, err
}
2020-06-13 00:21:58 +02:00
var url *string
if user.ProfileAvatarUrl.Valid {
url = &user.ProfileAvatarUrl.String
}
profileIcon := &ProfileIcon{url, &user.Initials, &user.ProfileBgColor}
projectID, err := r.Repository.GetProjectIDForTask(ctx, obj.TaskID)
if err != nil {
return taskMembers, err
}
role, err := r.Repository.GetRoleForProjectMemberByUserID(ctx, db.GetRoleForProjectMemberByUserIDParams{UserID: user.UserID, ProjectID: projectID})
if err != nil {
if err == sql.ErrNoRows {
role = db.Role{Code: "owner", Name: "Owner"}
} else {
log.WithFields(log.Fields{"userID": user.UserID}).WithError(err).Error("get role for project member")
return taskMembers, err
}
}
taskMembers = append(taskMembers, Member{ID: taskMemberLink.UserID, FullName: user.FullName, ProfileIcon: profileIcon,
Role: &role,
})
2020-04-20 05:02:55 +02:00
}
return taskMembers, nil
}
func (r *taskResolver) Labels(ctx context.Context, obj *db.Task) ([]db.TaskLabel, error) {
2020-04-20 05:02:55 +02:00
return r.Repository.GetTaskLabelsForTaskID(ctx, obj.TaskID)
}
func (r *taskResolver) Checklists(ctx context.Context, obj *db.Task) ([]db.TaskChecklist, error) {
2020-06-19 01:12:15 +02:00
return r.Repository.GetTaskChecklistsForTask(ctx, obj.TaskID)
}
func (r *taskResolver) Badges(ctx context.Context, obj *db.Task) (*TaskBadges, error) {
2020-06-19 01:12:15 +02:00
checklists, err := r.Repository.GetTaskChecklistsForTask(ctx, obj.TaskID)
if err != nil {
return &TaskBadges{}, err
}
if len(checklists) == 0 {
return &TaskBadges{Checklist: nil}, err
}
complete := 0
total := 0
for _, checklist := range checklists {
items, err := r.Repository.GetTaskChecklistItemsForTaskChecklist(ctx, checklist.TaskChecklistID)
if err != nil {
return &TaskBadges{}, err
}
for _, item := range items {
total += 1
if item.Complete {
complete += 1
}
}
}
return &TaskBadges{Checklist: &ChecklistBadge{Total: total, Complete: complete}}, nil
}
func (r *taskChecklistResolver) ID(ctx context.Context, obj *db.TaskChecklist) (uuid.UUID, error) {
2020-06-19 01:12:15 +02:00
return obj.TaskChecklistID, nil
}
func (r *taskChecklistResolver) Items(ctx context.Context, obj *db.TaskChecklist) ([]db.TaskChecklistItem, error) {
2020-06-19 01:12:15 +02:00
return r.Repository.GetTaskChecklistItemsForTaskChecklist(ctx, obj.TaskChecklistID)
}
func (r *taskChecklistItemResolver) ID(ctx context.Context, obj *db.TaskChecklistItem) (uuid.UUID, error) {
2020-06-19 01:12:15 +02:00
return obj.TaskChecklistItemID, nil
}
func (r *taskChecklistItemResolver) DueDate(ctx context.Context, obj *db.TaskChecklistItem) (*time.Time, error) {
2020-06-19 01:12:15 +02:00
panic(fmt.Errorf("not implemented"))
}
func (r *taskGroupResolver) ID(ctx context.Context, obj *db.TaskGroup) (uuid.UUID, error) {
2020-05-27 02:53:31 +02:00
return obj.TaskGroupID, nil
}
func (r *taskGroupResolver) ProjectID(ctx context.Context, obj *db.TaskGroup) (string, error) {
2020-04-10 04:40:22 +02:00
return obj.ProjectID.String(), nil
}
func (r *taskGroupResolver) Tasks(ctx context.Context, obj *db.TaskGroup) ([]db.Task, error) {
2020-04-10 04:40:22 +02:00
tasks, err := r.Repository.GetTasksForTaskGroupID(ctx, obj.TaskGroupID)
return tasks, err
}
func (r *taskLabelResolver) ID(ctx context.Context, obj *db.TaskLabel) (uuid.UUID, error) {
2020-05-27 02:53:31 +02:00
return obj.TaskLabelID, nil
}
func (r *taskLabelResolver) ProjectLabel(ctx context.Context, obj *db.TaskLabel) (*db.ProjectLabel, error) {
2020-04-21 01:04:27 +02:00
projectLabel, err := r.Repository.GetProjectLabelByID(ctx, obj.ProjectLabelID)
2020-05-31 06:11:19 +02:00
return &projectLabel, err
2020-04-21 01:04:27 +02:00
}
func (r *teamResolver) ID(ctx context.Context, obj *db.Team) (uuid.UUID, error) {
2020-05-27 02:53:31 +02:00
return obj.TeamID, nil
}
func (r *teamResolver) Members(ctx context.Context, obj *db.Team) ([]Member, error) {
user, err := r.Repository.GetUserAccountByID(ctx, obj.Owner)
members := []Member{}
2020-07-12 09:06:11 +02:00
log.WithFields(log.Fields{"teamID": obj.TeamID}).Info("getting members")
if err == sql.ErrNoRows {
return members, nil
}
if err != nil {
log.WithError(err).Error("get user account by ID")
return members, err
}
2020-07-12 09:06:11 +02:00
ownedProjects, err := r.Repository.GetOwnedTeamProjectsForUserID(ctx, db.GetOwnedTeamProjectsForUserIDParams{TeamID: obj.TeamID, Owner: user.UserID})
log.WithFields(log.Fields{"projects": ownedProjects}).Info("retrieved owned project list")
if err == sql.ErrNoRows {
ownedProjects = []uuid.UUID{}
} else if err != nil {
log.WithError(err).Error("get owned team projects for user id")
return members, err
}
ownedTeams := []uuid.UUID{}
var ownerList *OwnersList
if len(ownedTeams) != 0 || len(ownedProjects) != 0 {
log.Info("owned list is not empty")
ownerList = &OwnersList{Projects: ownedProjects, Teams: ownedTeams}
}
var url *string
if user.ProfileAvatarUrl.Valid {
url = &user.ProfileAvatarUrl.String
}
profileIcon := &ProfileIcon{url, &user.Initials, &user.ProfileBgColor}
members = append(members, Member{
ID: obj.Owner, FullName: user.FullName, ProfileIcon: profileIcon, Username: user.Username,
2020-07-12 09:06:11 +02:00
Owned: ownerList, Role: &db.Role{Code: "owner", Name: "Owner"},
})
teamMembers, err := r.Repository.GetTeamMembersForTeamID(ctx, obj.TeamID)
if err != nil {
log.WithError(err).Error("get project members for project id")
return members, err
}
for _, teamMember := range teamMembers {
user, err = r.Repository.GetUserAccountByID(ctx, teamMember.UserID)
if err != nil {
log.WithError(err).Error("get user account by ID")
return members, err
}
var url *string
if user.ProfileAvatarUrl.Valid {
url = &user.ProfileAvatarUrl.String
}
role, err := r.Repository.GetRoleForTeamMember(ctx, db.GetRoleForTeamMemberParams{UserID: user.UserID, TeamID: obj.TeamID})
if err != nil {
log.WithError(err).Error("get role for projet member by user ID")
return members, err
}
2020-07-12 09:06:11 +02:00
ownedProjects, err := r.Repository.GetOwnedTeamProjectsForUserID(ctx, db.GetOwnedTeamProjectsForUserIDParams{TeamID: obj.TeamID, Owner: user.UserID})
log.WithFields(log.Fields{"projects": ownedProjects}).Info("retrieved owned project list")
if err == sql.ErrNoRows {
ownedProjects = []uuid.UUID{}
} else if err != nil {
log.WithError(err).Error("get owned team projects for user id")
return members, err
}
ownedTeams := []uuid.UUID{}
var ownerList *OwnersList
if len(ownedTeams) != 0 || len(ownedProjects) != 0 {
log.Info("owned list is not empty")
ownerList = &OwnersList{Projects: ownedProjects, Teams: ownedTeams}
}
profileIcon := &ProfileIcon{url, &user.Initials, &user.ProfileBgColor}
members = append(members, Member{ID: user.UserID, FullName: user.FullName, ProfileIcon: profileIcon,
2020-07-12 09:06:11 +02:00
Username: user.Username, Owned: ownerList, Role: &db.Role{Code: role.Code, Name: role.Name},
})
}
return members, nil
}
func (r *userAccountResolver) ID(ctx context.Context, obj *db.UserAccount) (uuid.UUID, error) {
2020-05-27 02:53:31 +02:00
return obj.UserID, nil
}
func (r *userAccountResolver) Role(ctx context.Context, obj *db.UserAccount) (*db.Role, error) {
role, err := r.Repository.GetRoleForUserID(ctx, obj.UserID)
if err != nil {
log.Info("beep!")
log.WithError(err).Error("get role for user id")
return &db.Role{}, err
}
return &db.Role{Code: role.Code, Name: role.Name}, nil
}
func (r *userAccountResolver) ProfileIcon(ctx context.Context, obj *db.UserAccount) (*ProfileIcon, error) {
2020-06-13 00:21:58 +02:00
var url *string
if obj.ProfileAvatarUrl.Valid {
url = &obj.ProfileAvatarUrl.String
}
profileIcon := &ProfileIcon{url, &obj.Initials, &obj.ProfileBgColor}
2020-04-20 05:02:55 +02:00
return profileIcon, nil
2020-04-10 04:40:22 +02:00
}
2020-05-27 23:18:50 +02:00
// LabelColor returns LabelColorResolver implementation.
func (r *Resolver) LabelColor() LabelColorResolver { return &labelColorResolver{r} }
// Mutation returns MutationResolver implementation.
func (r *Resolver) Mutation() MutationResolver { return &mutationResolver{r} }
// Organization returns OrganizationResolver implementation.
func (r *Resolver) Organization() OrganizationResolver { return &organizationResolver{r} }
// Project returns ProjectResolver implementation.
func (r *Resolver) Project() ProjectResolver { return &projectResolver{r} }
2020-04-21 01:04:27 +02:00
// ProjectLabel returns ProjectLabelResolver implementation.
func (r *Resolver) ProjectLabel() ProjectLabelResolver { return &projectLabelResolver{r} }
// Query returns QueryResolver implementation.
func (r *Resolver) Query() QueryResolver { return &queryResolver{r} }
2020-05-27 02:53:31 +02:00
// RefreshToken returns RefreshTokenResolver implementation.
func (r *Resolver) RefreshToken() RefreshTokenResolver { return &refreshTokenResolver{r} }
// Task returns TaskResolver implementation.
func (r *Resolver) Task() TaskResolver { return &taskResolver{r} }
2020-06-19 01:12:15 +02:00
// TaskChecklist returns TaskChecklistResolver implementation.
func (r *Resolver) TaskChecklist() TaskChecklistResolver { return &taskChecklistResolver{r} }
// TaskChecklistItem returns TaskChecklistItemResolver implementation.
func (r *Resolver) TaskChecklistItem() TaskChecklistItemResolver { return &taskChecklistItemResolver{r} }
// TaskGroup returns TaskGroupResolver implementation.
func (r *Resolver) TaskGroup() TaskGroupResolver { return &taskGroupResolver{r} }
2020-04-20 05:02:55 +02:00
// TaskLabel returns TaskLabelResolver implementation.
func (r *Resolver) TaskLabel() TaskLabelResolver { return &taskLabelResolver{r} }
2020-05-27 02:53:31 +02:00
// Team returns TeamResolver implementation.
func (r *Resolver) Team() TeamResolver { return &teamResolver{r} }
2020-04-20 05:02:55 +02:00
// UserAccount returns UserAccountResolver implementation.
func (r *Resolver) UserAccount() UserAccountResolver { return &userAccountResolver{r} }
2020-04-10 04:40:22 +02:00
2020-05-27 23:18:50 +02:00
type labelColorResolver struct{ *Resolver }
2020-04-10 04:40:22 +02:00
type mutationResolver struct{ *Resolver }
type organizationResolver struct{ *Resolver }
2020-04-10 04:40:22 +02:00
type projectResolver struct{ *Resolver }
2020-04-21 01:04:27 +02:00
type projectLabelResolver struct{ *Resolver }
2020-04-10 04:40:22 +02:00
type queryResolver struct{ *Resolver }
2020-05-27 02:53:31 +02:00
type refreshTokenResolver struct{ *Resolver }
2020-04-10 04:40:22 +02:00
type taskResolver struct{ *Resolver }
2020-06-19 01:12:15 +02:00
type taskChecklistResolver struct{ *Resolver }
type taskChecklistItemResolver struct{ *Resolver }
2020-04-10 04:40:22 +02:00
type taskGroupResolver struct{ *Resolver }
2020-04-20 05:02:55 +02:00
type taskLabelResolver struct{ *Resolver }
2020-05-27 02:53:31 +02:00
type teamResolver struct{ *Resolver }
2020-04-20 05:02:55 +02:00
type userAccountResolver struct{ *Resolver }