import { MusterContext } from "../domain/ports/common.mjs"; import { AttendanceCorrectionDocument, ProposedSessionChanges } from "../models/attendance-correction.model.mjs"; import { AttendanceSessionRepository } from "./attendance-session.repository.mjs"; import { PluginType, Repository } from "@classytic/mongokit"; import { Model } from "mongoose"; import { EventTransport } from "@classytic/primitives/events"; import { ApprovalChain } from "@classytic/primitives/approval"; import { OutboxStore } from "@classytic/primitives/outbox"; //#region src/repositories/attendance-correction.repository.d.ts interface RequestCorrectionInput { sessionId: string; proposedChanges: ProposedSessionChanges; reason: string; /** * Optional multi-step approval chain from * `@classytic/primitives/approval.createChain({...})`. When present, * `approve()` will throw `CorrectionAwaitingApprovalError` until * `isApproved(chain) === true`. */ approvals?: ApprovalChain; metadata?: Record; } interface ReviewCorrectionInput { reviewerNote?: string; } interface AttendanceCorrectionRepositoryConfig { model: Model; plugins?: PluginType[]; sessionRepo: AttendanceSessionRepository; idPrefix?: string; idPartition?: 'yearly' | 'monthly' | 'daily'; eventTransport?: EventTransport | undefined; outbox?: OutboxStore | undefined; /** * When `true`, `approve()` falls back to non-transactional execution on * standalone Mongo deployments. Default `false` — see * `AttendanceSessionRepositoryConfig.allowNonTransactional` for context. */ allowNonTransactional?: boolean | undefined; logger?: { error(message: string, ...args: unknown[]): void; } | undefined; } declare class AttendanceCorrectionRepository extends Repository { private readonly eventTransport; private readonly outbox; private readonly pkgLogger; private readonly sessionRepo; private readonly allowNonTransactional; constructor(config: AttendanceCorrectionRepositoryConfig); private get unitConfig(); /** * request — file a pending correction against an existing session. * * `assertManagedSession` runs FIRST so that a host calling this inside * its own transaction without a `[PENDING_EVENTS]` queue gets an error * BEFORE any document or outbox row is staged. If the host catches the * error and commits anyway, the database is untouched. */ request(input: RequestCorrectionInput, ctx: MusterContext): Promise; /** * approve — transition pending → approved AND apply the proposed * changes to the underlying session. Always runs under a transaction; * on standalone Mongo this throws unless `allowNonTransactional: true` * was set at construction time. `correction.approved` and * `session.corrected` events are queued during the transaction body and * published only after commit (no leakage on retry / rollback). * * To compose with cross-package writes inside one transaction, use * `engine.withTransaction(ctx, async (txCtx) => { await * correction.approve(num, input, txCtx); ... })`. */ approve(correctionNumber: string, input: ReviewCorrectionInput, ctx: MusterContext): Promise; /** * updateApprovals — persist a chain after the host calls `applyDecision()` * from `@classytic/primitives/approval`. Status stays `pending`; callers * invoke `approve()` separately once `isApproved(chain) === true`. This * mirrors the pattern used by `@classytic/order`'s quotation flow: the * chain lives on the document, pure functions move it forward. */ updateApprovals(correctionNumber: string, chain: ApprovalChain, ctx: MusterContext): Promise; /** * reject — transition pending → rejected. No session mutation. * * `assertManagedSession` runs FIRST — same rationale as `request`. */ reject(correctionNumber: string, input: ReviewCorrectionInput, ctx: MusterContext): Promise; private loadPending; /** * emitDomain — same ordering as `AttendanceSessionRepository.dispatch`: * unmanaged-session guard FIRST (before any side effect), then outbox * save, then publish-or-queue. Defense-in-depth — `request` / `reject` * also call `assertManagedSession(ctx)` at their entry so the throw * lands before any mutation. */ private emitDomain; } //#endregion export { AttendanceCorrectionRepository, AttendanceCorrectionRepositoryConfig, RequestCorrectionInput, ReviewCorrectionInput };