AppRequest.changeApproval constructor

AppRequest.changeApproval({
  1. required String from,
  2. required String to,
  3. required String targetType,
  4. required String targetId,
  5. required Map<String, dynamic> changes,
  6. String? targetName,
  7. String? module,
  8. String? message,
  9. String? action,
  10. Map<String, dynamic>? extra,
})

Generic "change approval" request — gates sensitive edits behind review. Reusable across the ecosystem (content edits by non-admin users) and the ERP (approvals on sensitive financial/contact data).

from - profileId of the requester to - reviewer queue (typically CoreConstants.appBot) targetType - entity kind ('releaseItem', 'erpLead', ...) targetId - id of the entity being changed changes - map of field -> new value (or full entity JSON) to apply action - mutation kind: 'create' | 'update' | 'delete' (optional) extra - additional payload keys merged in (optional)

Implementation

factory AppRequest.changeApproval({
  required String from,
  required String to,
  required String targetType,
  required String targetId,
  required Map<String, dynamic> changes,
  String? targetName,
  String? module,
  String? message,
  String? action,
  Map<String, dynamic>? extra,
}) {
  final now = DateTime.now().millisecondsSinceEpoch;
  return AppRequest(
    id: '${from}_change_$now',
    from: from,
    to: to,
    eventId: targetId,
    createdTime: now,
    message: message ?? 'Solicitud de cambio: "${targetName ?? targetId}"',
    requestDecision: RequestDecision.pending,
    type: RequestType.changeApproval,
    payload: {
      if (action != null) 'action': action,
      ...?extra,
      'targetType': targetType,
      'targetId': targetId,
      if (targetName != null) 'targetName': targetName,
      if (module != null) 'module': module,
      'changes': changes,
    },
  );
}