diff --git a/db/query/team.sql b/db/query/team.sql index de078cc..fd78f48 100644 --- a/db/query/team.sql +++ b/db/query/team.sql @@ -98,22 +98,22 @@ WHERE ( -- name: UpdateTeamMember :exec UPDATE team_members SET - first_name = COALESCE($1, first_name), - last_name = COALESCE($2, last_name), - phone_number = COALESCE($3, phone_number), - team_role = COALESCE($4, team_role), - department = COALESCE($5, department), - job_title = COALESCE($6, job_title), - employment_type = COALESCE($7, employment_type), - hire_date = COALESCE($8, hire_date), - profile_picture_url = COALESCE($9, profile_picture_url), - bio = COALESCE($10, bio), - work_phone = COALESCE($11, work_phone), - emergency_contact = COALESCE($12, emergency_contact), - permissions = COALESCE($13, permissions), - updated_by = $14, + first_name = COALESCE(sqlc.narg('first_name')::VARCHAR, first_name), + last_name = COALESCE(sqlc.narg('last_name')::VARCHAR, last_name), + phone_number = COALESCE(sqlc.narg('phone_number'), phone_number), + team_role = COALESCE(sqlc.narg('team_role')::VARCHAR, team_role), + department = COALESCE(sqlc.narg('department'), department), + job_title = COALESCE(sqlc.narg('job_title'), job_title), + employment_type = COALESCE(sqlc.narg('employment_type'), employment_type), + hire_date = COALESCE(sqlc.narg('hire_date'), hire_date), + profile_picture_url = COALESCE(sqlc.narg('profile_picture_url'), profile_picture_url), + bio = COALESCE(sqlc.narg('bio'), bio), + work_phone = COALESCE(sqlc.narg('work_phone'), work_phone), + emergency_contact = COALESCE(sqlc.narg('emergency_contact'), emergency_contact), + permissions = COALESCE(sqlc.narg('permissions'), permissions), + updated_by = @updated_by, updated_at = CURRENT_TIMESTAMP -WHERE id = $15; +WHERE id = @id; -- name: UpdateTeamMemberStatus :exec UPDATE team_members diff --git a/gen/db/team.sql.go b/gen/db/team.sql.go index a65aa33..66f5d0d 100644 --- a/gen/db/team.sql.go +++ b/gen/db/team.sql.go @@ -637,10 +637,10 @@ func (q *Queries) SearchTeamMembers(ctx context.Context, arg SearchTeamMembersPa const UpdateTeamMember = `-- name: UpdateTeamMember :exec UPDATE team_members SET - first_name = COALESCE($1, first_name), - last_name = COALESCE($2, last_name), + first_name = COALESCE($1::VARCHAR, first_name), + last_name = COALESCE($2::VARCHAR, last_name), phone_number = COALESCE($3, phone_number), - team_role = COALESCE($4, team_role), + team_role = COALESCE($4::VARCHAR, team_role), department = COALESCE($5, department), job_title = COALESCE($6, job_title), employment_type = COALESCE($7, employment_type), @@ -656,10 +656,10 @@ WHERE id = $15 ` type UpdateTeamMemberParams struct { - FirstName string `json:"first_name"` - LastName string `json:"last_name"` + FirstName pgtype.Text `json:"first_name"` + LastName pgtype.Text `json:"last_name"` PhoneNumber pgtype.Text `json:"phone_number"` - TeamRole string `json:"team_role"` + TeamRole pgtype.Text `json:"team_role"` Department pgtype.Text `json:"department"` JobTitle pgtype.Text `json:"job_title"` EmploymentType pgtype.Text `json:"employment_type"` diff --git a/internal/repository/team.go b/internal/repository/team.go index c6f7bc0..63c5c47 100644 --- a/internal/repository/team.go +++ b/internal/repository/team.go @@ -178,18 +178,18 @@ func (s *Store) UpdateTeamMember(ctx context.Context, req domain.UpdateTeamMembe } return s.queries.UpdateTeamMember(ctx, dbgen.UpdateTeamMemberParams{ - FirstName: req.FirstName, - LastName: req.LastName, - PhoneNumber: pgtype.Text{String: req.PhoneNumber, Valid: req.PhoneNumber != ""}, - TeamRole: req.TeamRole, - Department: pgtype.Text{String: req.Department, Valid: req.Department != ""}, - JobTitle: pgtype.Text{String: req.JobTitle, Valid: req.JobTitle != ""}, - EmploymentType: pgtype.Text{String: req.EmploymentType, Valid: req.EmploymentType != ""}, + FirstName: optionalPgText(req.FirstName), + LastName: optionalPgText(req.LastName), + PhoneNumber: optionalPgText(req.PhoneNumber), + TeamRole: optionalPgText(req.TeamRole), + Department: optionalPgText(req.Department), + JobTitle: optionalPgText(req.JobTitle), + EmploymentType: optionalPgText(req.EmploymentType), HireDate: hireDate, - ProfilePictureUrl: pgtype.Text{String: req.ProfilePictureURL, Valid: req.ProfilePictureURL != ""}, - Bio: pgtype.Text{String: req.Bio, Valid: req.Bio != ""}, - WorkPhone: pgtype.Text{String: req.WorkPhone, Valid: req.WorkPhone != ""}, - EmergencyContact: pgtype.Text{String: req.EmergencyContact, Valid: req.EmergencyContact != ""}, + ProfilePictureUrl: optionalPgText(req.ProfilePictureURL), + Bio: optionalPgText(req.Bio), + WorkPhone: optionalPgText(req.WorkPhone), + EmergencyContact: optionalPgText(req.EmergencyContact), Permissions: permissionsJSON, UpdatedBy: pgtype.Int8{Int64: req.UpdatedBy, Valid: req.UpdatedBy > 0}, ID: req.TeamMemberID, @@ -516,3 +516,10 @@ func (s *Store) GetTeamRefreshTokenByToken(ctx context.Context, token string) (d func (s *Store) RevokeTeamRefreshTokenByToken(ctx context.Context, token string) error { return s.queries.RevokeTeamRefreshTokenByToken(ctx, token) } + +func optionalPgText(value string) pgtype.Text { + if value == "" { + return pgtype.Text{} + } + return pgtype.Text{String: value, Valid: true} +}