Add vendor node query support
Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
@@ -117,6 +117,13 @@ func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error
|
|||||||
}
|
}
|
||||||
|
|
||||||
return types.NewPeople(people), nil
|
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:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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(
|
func (v *Vendors) LoadByOrganizationID(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
conn pg.Conn,
|
conn pg.Conn,
|
||||||
|
|||||||
@@ -89,6 +89,26 @@ func (s Service) GetPeople(
|
|||||||
return people, nil
|
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(
|
func (s Service) ListOrganizationFrameworks(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
organizationID gid.GID,
|
organizationID gid.GID,
|
||||||
|
|||||||
Reference in New Issue
Block a user