event

Amendment Apply Requested

A user finished reviewing a contract amendment and asked for its changes to be applied. cna-nexus's amendment consumer executes the changes on the contract and the franchise.

Event Topic: ContractKey: contractId

Overview

Fact: an amendment was saved in the state APPLYING and its application is requested.

When it is published. CNA NexusCNA NexusServicev1.0.0Franchise network back-office (franchises, economic groups, partners, contracts and amendments, document storage, AI doc...PublishesInviteUser, ContractActivationRequested +13SubscribesContractActivationRequested, AmendmentApplyRequested +4Ownercna-platformMapRepoView docs, in persistAmendmentUpdate, reached from the mutations that update an amendment or a rescission: after the amendment’s change rows and participants are replaced and its signedAt and status = APPLYING are written. No transaction wraps those writes and the producer is awaited afterwards, not registered with afterCommit. The parent contract is untouched at this point.

What the consumer does. cna-nexus (amendmentApplyConsumer, group contract-amendment-apply), using only amendmentId (contractId is there for routing):

  1. Loads the amendment; a missing one throws (logged and reported to Sentry).
  2. Idempotency guard: APPLIED or APPLY_FAILED are skipped.
  3. applyAmendmentChanges: in one transaction, dispatches each change to its handler (name, legal name, CNPJ, category, estimated opening date, address, territory, end date, corporate change; ADDITIONAL_CLAUSE and OTHER have no handler and are skipped), runs the contract termination for a RESCISSION, writes field-level audit rows with the uploader as author, and marks the amendment APPLIED.
  4. On failure: logs and sets the amendment to APPLY_FAILED. Not rethrown.

Follow-up message. Exactly one FranchiseUpdated per amendment, registered with manager.afterCommit() (see the Franchise topic).

Kafka

Topic (aggregateRoot)Contract
Message key (routingKey)payload.contractId
Contract ownerNEXUS
metadata.eventAmendmentApplyRequested
Consumer groupcontract-amendment-apply

Payload schema

Source of truth

type AmendmentApplyRequestedPayload = {
contractId: string;
amendmentId: string;
};
export class AmendmentApplyRequested extends Event<AmendmentApplyRequestedPayload> {
static readonly owner = "NEXUS";
static readonly aggregateRoot = "Contract";
static readonly routingKey = "contractId";
}

The class exists only in cna-nexus.

Custom properties

PropertyValue
Contract Ownerx-contract-ownerNEXUS
Kafka Topicx-kafka-topicContract
Message Keyx-message-keycontractId
Sourcex-sourcecna-nexus api/app/events/nexus/contract/AmendmentApplyRequested.ts
2 properties
contractIdstring
required

Contract the amendment modifies (UUID). Kafka message key, so amendments and activations of one contract stay ordered.

amendmentIdstring
required

Amendment id (UUID) in contract.contract_amendments. The only field the consumer reads.