approval

package
v1.799.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2026 License: Apache-2.0, MIT Imports: 6 Imported by: 0

Documentation

Overview

Package approval is the B2B spend-approval domain: before a company's (models/company) cart converts to an order, it can require sign-off from an admin or sales manager. The pure state machine governing the pending → approved/rejected transition lives in service.go.

Index

Constants

View Source
const (
	TypeAdmin        = "admin"
	TypeSalesManager = "sales_manager"
)

Approval types.

View Source
const (
	StatusPending  = "pending"
	StatusApproved = "approved"
	StatusRejected = "rejected"
)

Approval lifecycle states.

View Source
const (
	ActionApprove = "approve"
	ActionReject  = "reject"
)

Actions that drive an approval's state machine.

Variables

View Source
var ErrAlreadyResolved = errors.New("approval: already resolved")

ErrAlreadyResolved is returned when an action is taken on an approval that has already left the pending state.

View Source
var ErrUnknownAction = errors.New("approval: unknown action")

ErrUnknownAction is returned for an action that is neither approve nor reject.

Functions

func NextStatus

func NextStatus(current string, action string) (string, error)

NextStatus computes the status an approval moves to when action is applied to its current status. Only a pending approval is transitionable: "approve" yields approved, "reject" yields rejected. Any action on an already-resolved approval returns ErrAlreadyResolved; an unrecognized action returns ErrUnknownAction.

func Query

Types

type Approval

type Approval struct {
	mixin.Model[Approval]

	CartId    string `json:"cartId"`
	OrderId   string `json:"orderId,omitempty"`
	CompanyId string `json:"companyId"`

	// Type is the approver role required: admin or sales_manager.
	Type string `json:"type"`

	Status string `json:"status" orm:"default:pending"`

	// HandledBy records the user who approved or rejected.
	HandledBy string `json:"handledBy,omitempty"`

	Metadata  Map    `json:"metadata,omitempty" datastore:"-"`
	Metadata_ string `json:"-" datastore:",noindex"`
}

Approval is a spend-approval gate on a B2B cart/order. It is resolved once its status leaves pending; NextStatus (service.go) enforces the transitions.

func New

func New(db *datastore.Datastore) *Approval

func (*Approval) IsResolved

func (a *Approval) IsResolved() bool

IsResolved reports whether the approval has been decided (no longer pending).

func (*Approval) Load

func (a *Approval) Load(ps []datastore.Property) (err error)

func (*Approval) Save

func (a *Approval) Save() ([]datastore.Property, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL