feat(judgement,approvals,ui): action classes are records with a level, history and reset; the precedent guard reads the class level (#2003)
This commit is contained in:
15 files changed
+900
-16
No files matched your search
@@ -262,6 +262,27 @@ func (m *Module) ForRun(ctx context.Context, runID uuid.UUID) ([]Request, error)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Outcomes says what became of the requests made for the decisions in ids,
|
||||
// for the history of the action class they belong to.
|
||||
func (m *Module) Outcomes(ctx context.Context, ids []uuid.UUID) (map[uuid.UUID]judgement.Outcome, error) {
|
||||
rows, err := m.store.ByDecisions(ctx, m.orgID, ids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make(map[uuid.UUID]judgement.Outcome, len(rows))
|
||||
for _, row := range rows {
|
||||
o := judgement.Outcome{State: row.State}
|
||||
if row.AnsweredBy.Valid {
|
||||
o.By = row.AnsweredBy.String
|
||||
}
|
||||
if row.AnsweredAt.Valid {
|
||||
o.At = row.AnsweredAt.Time
|
||||
}
|
||||
out[row.DecisionID] = o
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Routes adds the approvals API to mux behind guard.
|
||||
func (m *Module) Routes(mux *http.ServeMux, guard func(http.Handler) http.Handler) {
|
||||
mux.Handle("GET /api/approvals", guard(http.HandlerFunc(m.list)))
|
||||
|
||||
@@ -136,5 +136,23 @@ func (s *Store) ForRun(ctx context.Context, orgID string, runID uuid.UUID) ([]Re
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ByDecisions returns the requests made for the decisions in ids.
|
||||
func (s *Store) ByDecisions(ctx context.Context, orgID string, ids []uuid.UUID) ([]Request, error) {
|
||||
if len(ids) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
query, args, err := sqlx.In(`
|
||||
SELECT `+requestColumns+` FROM approvals.requests
|
||||
WHERE org_id = ? AND decision_id IN (?) ORDER BY created_at`, orgID, ids)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("list requests by decision: %w", err)
|
||||
}
|
||||
var out []Request
|
||||
if err := s.db.SelectContext(ctx, &out, s.db.Rebind(query), args...); err != nil {
|
||||
return nil, fmt.Errorf("list requests by decision: %w", err)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ErrNotFound means no request has that id or key.
|
||||
var ErrNotFound = errors.New("no such approval request")
|
||||
Reference in new issue
Block a user