Skip to content

Various Fields/Columns Missing From Queries #15

@ehanahamed

Description

@ehanahamed

Various "newly" added fields and columns, like draft or subject_id on studysets, are inconsistent in a bunch of the SQL. Some queries/mutations are missing some of those columns in their queries, while other ones aren't.

For example, in query.resolvers.go, we're missing subject_id in the second "version" of this query for no reason:

func (r *queryResolver) Studyset(ctx context.Context, id string) (*model.Studyset, error) {
	authedUser := auth.AuthedUserContext(ctx)

	var studyset model.Studyset
	var err error
	if authedUser != nil {
		sql := `
			SELECT id, user_id, title, private, subject_id, draft,
				to_char(created_at, 'YYYY-MM-DD"T"HH24:MI:SS.MSTZH:TZM') as created_at,
				to_char(updated_at, 'YYYY-MM-DD"T"HH24:MI:SS.MSTZH:TZM') as updated_at
			FROM public.studysets
			WHERE id = $1 AND ((private = false AND draft = false) OR user_id = $2)`
		err = pgxscan.Get(ctx, r.DB, &studyset, sql, id, authedUser.ID)
	} else {
		sql := `
			SELECT id, user_id, title, private, draft,
				to_char(created_at, 'YYYY-MM-DD"T"HH24:MI:SS.MSTZH:TZM') as created_at,
				to_char(updated_at, 'YYYY-MM-DD"T"HH24:MI:SS.MSTZH:TZM') as updated_at
			FROM public.studysets
			WHERE id = $1 AND private = false AND draft = false`
		err = pgxscan.Get(ctx, r.DB, &studyset, sql, id)
	}
	if err != nil {
		if pgxscan.NotFound(err) {
			return nil, fmt.Errorf("studyset not found")
		}
		return nil, fmt.Errorf("failed to fetch studyset: %w", err)
	}

	return &studyset, nil
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions