Add vendor node query support

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-01-31 08:19:40 -08:00
parent 5291cdb3db
commit 98696d6bd1
3 changed files with 65 additions and 0 deletions

View File

@@ -117,6 +117,13 @@ func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error
}
return types.NewPeople(people), nil
case coredata.VendorEntityType:
vendor, err := r.svc.GetVendor(ctx, id)
if err != nil {
return nil, err
}
return types.NewVendor(vendor), nil
default:
}

View File

@@ -53,6 +53,44 @@ func (v *Vendor) scan(r pgx.Row) error {
)
}
func (v *Vendor) LoadByID(
ctx context.Context,
conn pg.Conn,
scope *Scope,
vendorID gid.GID,
) error {
q := `
SELECT
id,
organization_id,
name,
created_at,
updated_at
FROM
vendors
WHERE
%s
AND id = @vendor_id
LIMIT 1;
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"vendor_id": vendorID}
maps.Copy(args, scope.SQLArguments())
r := conn.QueryRow(ctx, q, args)
v2 := Vendor{}
if err := v2.scan(r); err != nil {
return err
}
*v = v2
return nil
}
func (v *Vendors) LoadByOrganizationID(
ctx context.Context,
conn pg.Conn,

View File

@@ -89,6 +89,26 @@ func (s Service) GetPeople(
return people, nil
}
func (s Service) GetVendor(
ctx context.Context,
vendorID gid.GID,
) (*coredata.Vendor, error) {
vendor := &coredata.Vendor{}
err := s.pg.WithConn(
ctx,
func(conn pg.Conn) error {
return vendor.LoadByID(ctx, conn, s.scope, vendorID)
},
)
if err != nil {
return nil, err
}
return vendor, nil
}
func (s Service) ListOrganizationFrameworks(
ctx context.Context,
organizationID gid.GID,