Files
fleet/server/datastore/mysql/setup_experience.go
T
Jahziel Villasana-Espinoza 0a4107c889 feat: orbit SE status endpoint (#22678)
> Related issue: #22637

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files)
for more information.
- [x] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
2024-10-07 17:16:32 -04:00

38 lines
1.1 KiB
Go

package mysql
import (
"context"
"github.com/fleetdm/fleet/v4/server/contexts/ctxerr"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/jmoiron/sqlx"
)
func (ds *Datastore) ListSetupExperienceResultsByHostUUID(ctx context.Context, hostUUID string) ([]*fleet.SetupExperienceStatusResult, error) {
const stmt = `
SELECT
sesr.id,
sesr.host_uuid,
sesr.name,
sesr.status,
sesr.software_installer_id,
sesr.host_software_installs_id,
sesr.vpp_app_team_id,
sesr.nano_command_uuid,
sesr.setup_experience_script_id,
sesr.script_execution_id,
sesr.error,
COALESCE(si.title_id, COALESCE(va.title_id, NULL)) AS software_title_id
FROM setup_experience_status_results sesr
LEFT JOIN software_installers si ON si.id = sesr.software_installer_id
LEFT JOIN vpp_apps_teams vat ON vat.id = sesr.vpp_app_team_id
LEFT JOIN vpp_apps va ON vat.adam_id = va.adam_id
WHERE host_uuid = ?
`
var results []*fleet.SetupExperienceStatusResult
if err := sqlx.SelectContext(ctx, ds.reader(ctx), &results, stmt, hostUUID); err != nil {
return nil, ctxerr.Wrap(ctx, err, "select setup experience status results by host uuid")
}
return results, nil
}