Files
GuwandykA 11e1fa4972
Some checks failed
CI/CD / Vet, test, build (push) Has been cancelled
CI/CD / Docker image (push) Has been cancelled
CI/CD / Deploy binary to server (push) Has been cancelled
visamaster: record order actions for the "Ammallar" table
Every create, update and delete of a visa/master or sber order is now
recorded in visa_master_order_actions: who did it, finished or failed
(with the exception), and for an update only the columns that changed -
original before, changes after. Marking an order paid when a payment is
finalized is recorded the same way, with no user when the GBÜS callback
did it.

Actions are written in the transaction that changes the order, so one is
on record exactly when its change is; failed ones are written after the
rollback with the values they attempted. The payment finalize records
after its commit instead, so recording never holds up a payment GBÜS has
already taken. Updates that change nothing and creates that fail (no
order to attach to) are not recorded.

GET /visa-master-payment-orders/{id}/actions lists them, newest first;
GET /visa-master-payment-orders/{id}/actions/{actionId} adds original,
changes and exception. Both are staff-only and order-scoped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 22:39:42 +05:00

118 lines
3.9 KiB
Go

package visamasteractions
import (
"encoding/json"
"strings"
"time"
"online-back/internal/shared"
)
// Action names, as the "Ammallar" table's Amalyň ady column shows them.
const (
NameCreate = "create"
NameUpdate = "update"
NameDelete = "delete"
)
// Action statuses: finished once the change is committed, failed (with
// Exception) when it was attempted but rolled back.
const (
StatusFinished = "finished"
StatusFailed = "failed"
)
// orderTypeSber is the type value of Sber orders, matched case-insensitively
// like visamaster and visamasterpay do.
const orderTypeSber = "sber"
var nameLabels = map[string]shared.LocalizedText{
NameCreate: {Tm: "Goşmak", Ru: "Создание", En: "Create"},
NameUpdate: {Tm: "Üýtgetmek", Ru: "Изменение", En: "Update"},
NameDelete: {Tm: "Pozmak", Ru: "Удаление", En: "Delete"},
}
var (
sberTargetLabel = shared.LocalizedText{Tm: "Sber töleg (talyplar üçin)", Ru: "Оплата Sber (для студентов)", En: "Sber payment (for students)"}
visaMasterTargetLabel = shared.LocalizedText{Tm: "Visa/Master töleg (talyplar üçin)", Ru: "Оплата Visa/Master (для студентов)", En: "Visa/Master payment (for students)"}
)
// NameLabel is the display name of an action name; unknown names fall
// back to the name itself.
func NameLabel(name string) shared.LocalizedText {
if label, ok := nameLabels[name]; ok {
return label
}
return shared.LocalizedText{Tm: name, Ru: name, En: name}
}
// TargetLabel is the display name of the order an action was done to,
// by the order's (current) type.
func TargetLabel(orderType *string) shared.LocalizedText {
if orderType != nil && strings.EqualFold(strings.TrimSpace(*orderType), orderTypeSber) {
return sberTargetLabel
}
return visaMasterTargetLabel
}
// OrderActionTargetDTO is the order an action was done to - Amalyň
// nyşany (targedi), e.g. "TB6312-14083 (Sber töleg (talyplar üçin))".
type OrderActionTargetDTO struct {
Id int64 `json:"id"`
UniqueId *string `json:"uniqueId"`
Type *string `json:"type"`
Label shared.LocalizedText `json:"label"`
}
// OrderActionDTO is one row of an order's "Ammallar" table. CreatedById is
// null (and CreatedByName empty) when no user started the action - the
// GBÜS callback finalizing a payment.
type OrderActionDTO struct {
Id int64 `json:"id"`
OrderId int64 `json:"orderId"`
Name string `json:"name"`
NameLabel shared.LocalizedText `json:"nameLabel"`
Status string `json:"status"`
Target OrderActionTargetDTO `json:"target"`
CreatedById *int64 `json:"createdById"`
CreatedByName string `json:"createdByName"`
CreatedAt time.Time `json:"createdAt"`
}
// OrderActionDetailDTO is a single action with what it changed - the list
// leaves these out so pages stay small. Original holds the changed
// columns' values before the action and Changes their values after (or,
// for a failed action, the values it attempted); either is null when
// there's nothing on that side (Original for a create, Changes for a
// delete).
type OrderActionDetailDTO struct {
OrderActionDTO
Original json.RawMessage `json:"original" swaggertype:"object"`
Changes json.RawMessage `json:"changes" swaggertype:"object"`
Exception *string `json:"exception"`
}
type ListOrderActionDTO struct {
Count int64 `json:"count"`
Actions []OrderActionDTO `json:"actions"`
}
// CreateOrderActionDTO is one action to record, written by the
// repositories that change orders (cards/visamaster, payment/visamasterpay)
// - never through the API.
type CreateOrderActionDTO struct {
OrderId int64
Name string
Status string
Original map[string]interface{}
Changes map[string]interface{}
Exception *string
CreatedBy *int64
}
type ListFilter struct {
OrderId int64
Page int
Limit int
}