feat(MyTasks): allow filtering by task complete status
This commit is contained in:
@ -69,8 +69,8 @@ type Querier interface {
|
||||
GetAllUserAccounts(ctx context.Context) ([]UserAccount, error)
|
||||
GetAllVisibleProjectsForUserID(ctx context.Context, userID uuid.UUID) ([]Project, error)
|
||||
GetAssignedMembersForTask(ctx context.Context, taskID uuid.UUID) ([]TaskAssigned, error)
|
||||
GetAssignedTasksDueDateForUserID(ctx context.Context, userID uuid.UUID) ([]Task, error)
|
||||
GetAssignedTasksProjectForUserID(ctx context.Context, userID uuid.UUID) ([]Task, error)
|
||||
GetAssignedTasksDueDateForUserID(ctx context.Context, arg GetAssignedTasksDueDateForUserIDParams) ([]Task, error)
|
||||
GetAssignedTasksProjectForUserID(ctx context.Context, arg GetAssignedTasksProjectForUserIDParams) ([]Task, error)
|
||||
GetCommentsForTaskID(ctx context.Context, taskID uuid.UUID) ([]TaskComment, error)
|
||||
GetConfirmTokenByEmail(ctx context.Context, email string) (UserAccountConfirmToken, error)
|
||||
GetConfirmTokenByID(ctx context.Context, confirmTokenID uuid.UUID) (UserAccountConfirmToken, error)
|
||||
@ -99,7 +99,7 @@ type Querier interface {
|
||||
GetProjectMembersForProjectID(ctx context.Context, projectID uuid.UUID) ([]ProjectMember, error)
|
||||
GetProjectRolesForUserID(ctx context.Context, userID uuid.UUID) ([]GetProjectRolesForUserIDRow, error)
|
||||
GetProjectsForInvitedMember(ctx context.Context, email string) ([]uuid.UUID, error)
|
||||
GetRecentlyAssignedTaskForUserID(ctx context.Context, userID uuid.UUID) ([]Task, error)
|
||||
GetRecentlyAssignedTaskForUserID(ctx context.Context, arg GetRecentlyAssignedTaskForUserIDParams) ([]Task, error)
|
||||
GetRefreshTokenByID(ctx context.Context, tokenID uuid.UUID) (RefreshToken, error)
|
||||
GetRoleForProjectMemberByUserID(ctx context.Context, arg GetRoleForProjectMemberByUserIDParams) (Role, error)
|
||||
GetRoleForTeamMember(ctx context.Context, arg GetRoleForTeamMemberParams) (Role, error)
|
||||
|
@ -59,14 +59,25 @@ UPDATE task_comment SET message = $2, updated_at = $3 WHERE task_comment_id = $1
|
||||
|
||||
-- name: GetRecentlyAssignedTaskForUserID :many
|
||||
SELECT task.* FROM task_assigned INNER JOIN
|
||||
task ON task.task_id = task_assigned.task_id WHERE user_id = $1 ORDER BY task_assigned.assigned_date DESC;
|
||||
task ON task.task_id = task_assigned.task_id WHERE user_id = $1
|
||||
AND $4::boolean = true OR (
|
||||
$4::boolean = false AND complete = $2 AND (
|
||||
$2 = false OR ($2 = true AND completed_at > $3)
|
||||
)
|
||||
)
|
||||
ORDER BY task_assigned.assigned_date DESC;
|
||||
|
||||
-- name: GetAssignedTasksProjectForUserID :many
|
||||
SELECT task.* FROM task_assigned
|
||||
INNER JOIN task ON task.task_id = task_assigned.task_id
|
||||
INNER JOIN task ON task.task_id = task_assigned.task_id
|
||||
INNER JOIN task_group ON task_group.task_group_id = task.task_group_id
|
||||
WHERE user_id = $1
|
||||
ORDER BY task_group.project_id DESC, task_assigned.assigned_date DESC;
|
||||
WHERE user_id = $1
|
||||
AND $4::boolean = true OR (
|
||||
$4::boolean = false AND complete = $2 AND (
|
||||
$2 = false OR ($2 = true AND completed_at > $3)
|
||||
)
|
||||
)
|
||||
ORDER BY task_group.project_id DESC, task_assigned.assigned_date DESC;
|
||||
|
||||
-- name: GetProjectIdMappings :many
|
||||
SELECT project_id, task_id FROM task
|
||||
@ -75,7 +86,12 @@ INNER JOIN task_group ON task_group.task_group_id = task.task_group_id
|
||||
|
||||
-- name: GetAssignedTasksDueDateForUserID :many
|
||||
SELECT task.* FROM task_assigned
|
||||
INNER JOIN task ON task.task_id = task_assigned.task_id
|
||||
INNER JOIN task ON task.task_id = task_assigned.task_id
|
||||
INNER JOIN task_group ON task_group.task_group_id = task.task_group_id
|
||||
WHERE user_id = $1
|
||||
ORDER BY task.due_date DESC, task_group.project_id DESC;
|
||||
WHERE user_id = $1
|
||||
AND $4::boolean = true OR (
|
||||
$4::boolean = false AND complete = $2 AND (
|
||||
$2 = false OR ($2 = true AND completed_at > $3)
|
||||
)
|
||||
)
|
||||
ORDER BY task.due_date DESC, task_group.project_id DESC;
|
||||
|
@ -200,14 +200,31 @@ func (q *Queries) GetAllTasks(ctx context.Context) ([]Task, error) {
|
||||
|
||||
const getAssignedTasksDueDateForUserID = `-- name: GetAssignedTasksDueDateForUserID :many
|
||||
SELECT task.task_id, task.task_group_id, task.created_at, task.name, task.position, task.description, task.due_date, task.complete, task.completed_at, task.has_time FROM task_assigned
|
||||
INNER JOIN task ON task.task_id = task_assigned.task_id
|
||||
INNER JOIN task ON task.task_id = task_assigned.task_id
|
||||
INNER JOIN task_group ON task_group.task_group_id = task.task_group_id
|
||||
WHERE user_id = $1
|
||||
ORDER BY task.due_date DESC, task_group.project_id DESC
|
||||
WHERE user_id = $1
|
||||
AND $4::boolean = true OR (
|
||||
$4::boolean = false AND complete = $2 AND (
|
||||
$2 = false OR ($2 = true AND completed_at > $3)
|
||||
)
|
||||
)
|
||||
ORDER BY task.due_date DESC, task_group.project_id DESC
|
||||
`
|
||||
|
||||
func (q *Queries) GetAssignedTasksDueDateForUserID(ctx context.Context, userID uuid.UUID) ([]Task, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getAssignedTasksDueDateForUserID, userID)
|
||||
type GetAssignedTasksDueDateForUserIDParams struct {
|
||||
UserID uuid.UUID `json:"user_id"`
|
||||
Complete bool `json:"complete"`
|
||||
CompletedAt sql.NullTime `json:"completed_at"`
|
||||
Column4 bool `json:"column_4"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetAssignedTasksDueDateForUserID(ctx context.Context, arg GetAssignedTasksDueDateForUserIDParams) ([]Task, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getAssignedTasksDueDateForUserID,
|
||||
arg.UserID,
|
||||
arg.Complete,
|
||||
arg.CompletedAt,
|
||||
arg.Column4,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -242,14 +259,31 @@ func (q *Queries) GetAssignedTasksDueDateForUserID(ctx context.Context, userID u
|
||||
|
||||
const getAssignedTasksProjectForUserID = `-- name: GetAssignedTasksProjectForUserID :many
|
||||
SELECT task.task_id, task.task_group_id, task.created_at, task.name, task.position, task.description, task.due_date, task.complete, task.completed_at, task.has_time FROM task_assigned
|
||||
INNER JOIN task ON task.task_id = task_assigned.task_id
|
||||
INNER JOIN task ON task.task_id = task_assigned.task_id
|
||||
INNER JOIN task_group ON task_group.task_group_id = task.task_group_id
|
||||
WHERE user_id = $1
|
||||
ORDER BY task_group.project_id DESC, task_assigned.assigned_date DESC
|
||||
WHERE user_id = $1
|
||||
AND $4::boolean = true OR (
|
||||
$4::boolean = false AND complete = $2 AND (
|
||||
$2 = false OR ($2 = true AND completed_at > $3)
|
||||
)
|
||||
)
|
||||
ORDER BY task_group.project_id DESC, task_assigned.assigned_date DESC
|
||||
`
|
||||
|
||||
func (q *Queries) GetAssignedTasksProjectForUserID(ctx context.Context, userID uuid.UUID) ([]Task, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getAssignedTasksProjectForUserID, userID)
|
||||
type GetAssignedTasksProjectForUserIDParams struct {
|
||||
UserID uuid.UUID `json:"user_id"`
|
||||
Complete bool `json:"complete"`
|
||||
CompletedAt sql.NullTime `json:"completed_at"`
|
||||
Column4 bool `json:"column_4"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetAssignedTasksProjectForUserID(ctx context.Context, arg GetAssignedTasksProjectForUserIDParams) ([]Task, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getAssignedTasksProjectForUserID,
|
||||
arg.UserID,
|
||||
arg.Complete,
|
||||
arg.CompletedAt,
|
||||
arg.Column4,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -366,11 +400,29 @@ func (q *Queries) GetProjectIdMappings(ctx context.Context, dollar_1 []uuid.UUID
|
||||
|
||||
const getRecentlyAssignedTaskForUserID = `-- name: GetRecentlyAssignedTaskForUserID :many
|
||||
SELECT task.task_id, task.task_group_id, task.created_at, task.name, task.position, task.description, task.due_date, task.complete, task.completed_at, task.has_time FROM task_assigned INNER JOIN
|
||||
task ON task.task_id = task_assigned.task_id WHERE user_id = $1 ORDER BY task_assigned.assigned_date DESC
|
||||
task ON task.task_id = task_assigned.task_id WHERE user_id = $1
|
||||
AND $4::boolean = true OR (
|
||||
$4::boolean = false AND complete = $2 AND (
|
||||
$2 = false OR ($2 = true AND completed_at > $3)
|
||||
)
|
||||
)
|
||||
ORDER BY task_assigned.assigned_date DESC
|
||||
`
|
||||
|
||||
func (q *Queries) GetRecentlyAssignedTaskForUserID(ctx context.Context, userID uuid.UUID) ([]Task, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getRecentlyAssignedTaskForUserID, userID)
|
||||
type GetRecentlyAssignedTaskForUserIDParams struct {
|
||||
UserID uuid.UUID `json:"user_id"`
|
||||
Complete bool `json:"complete"`
|
||||
CompletedAt sql.NullTime `json:"completed_at"`
|
||||
Column4 bool `json:"column_4"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetRecentlyAssignedTaskForUserID(ctx context.Context, arg GetRecentlyAssignedTaskForUserIDParams) ([]Task, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getRecentlyAssignedTaskForUserID,
|
||||
arg.UserID,
|
||||
arg.Complete,
|
||||
arg.CompletedAt,
|
||||
arg.Column4,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jinzhu/now"
|
||||
"github.com/jordanknott/taskcafe/internal/auth"
|
||||
"github.com/jordanknott/taskcafe/internal/db"
|
||||
"github.com/jordanknott/taskcafe/internal/logger"
|
||||
@ -1411,18 +1412,60 @@ func (r *queryResolver) MyTasks(ctx context.Context, input MyTasks) (*MyTasksPay
|
||||
projects := []ProjectTaskMapping{}
|
||||
var tasks []db.Task
|
||||
var err error
|
||||
showAll := false
|
||||
if input.Status == MyTasksStatusAll {
|
||||
showAll = true
|
||||
}
|
||||
complete := false
|
||||
completedAt := sql.NullTime{Valid: false, Time: time.Time{}}
|
||||
switch input.Status {
|
||||
case MyTasksStatusCompleteAll:
|
||||
complete = true
|
||||
completedAt = sql.NullTime{Valid: true, Time: time.Time{}}
|
||||
case MyTasksStatusCompleteToday:
|
||||
complete = true
|
||||
completedAt = sql.NullTime{Valid: true, Time: now.BeginningOfDay()}
|
||||
case MyTasksStatusCompleteYesterday:
|
||||
complete = true
|
||||
completedAt = sql.NullTime{Valid: true, Time: now.With(time.Now().AddDate(0, 0, -1)).BeginningOfDay()}
|
||||
case MyTasksStatusCompleteOneWeek:
|
||||
complete = true
|
||||
completedAt = sql.NullTime{Valid: true, Time: now.With(time.Now().AddDate(0, 0, -7)).BeginningOfDay()}
|
||||
case MyTasksStatusCompleteTwoWeek:
|
||||
complete = true
|
||||
completedAt = sql.NullTime{Valid: true, Time: now.With(time.Now().AddDate(0, 0, -14)).BeginningOfDay()}
|
||||
case MyTasksStatusCompleteThreeWeek:
|
||||
complete = true
|
||||
completedAt = sql.NullTime{Valid: true, Time: now.With(time.Now().AddDate(0, 0, -21)).BeginningOfDay()}
|
||||
}
|
||||
|
||||
if input.Sort == MyTasksSortNone {
|
||||
tasks, err = r.Repository.GetRecentlyAssignedTaskForUserID(ctx, userID)
|
||||
tasks, err = r.Repository.GetRecentlyAssignedTaskForUserID(ctx, db.GetRecentlyAssignedTaskForUserIDParams{
|
||||
UserID: userID,
|
||||
Complete: complete,
|
||||
CompletedAt: completedAt,
|
||||
Column4: showAll,
|
||||
})
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return &MyTasksPayload{}, err
|
||||
}
|
||||
} else if input.Sort == MyTasksSortProject {
|
||||
tasks, err = r.Repository.GetAssignedTasksProjectForUserID(ctx, userID)
|
||||
tasks, err = r.Repository.GetAssignedTasksProjectForUserID(ctx, db.GetAssignedTasksProjectForUserIDParams{
|
||||
UserID: userID,
|
||||
Complete: complete,
|
||||
CompletedAt: completedAt,
|
||||
Column4: showAll,
|
||||
})
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return &MyTasksPayload{}, err
|
||||
}
|
||||
} else if input.Sort == MyTasksSortDueDate {
|
||||
tasks, err = r.Repository.GetAssignedTasksDueDateForUserID(ctx, userID)
|
||||
tasks, err = r.Repository.GetAssignedTasksDueDateForUserID(ctx, db.GetAssignedTasksDueDateForUserIDParams{
|
||||
UserID: userID,
|
||||
Complete: complete,
|
||||
CompletedAt: completedAt,
|
||||
Column4: showAll,
|
||||
})
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return &MyTasksPayload{}, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user