Sprint 0: Updated inventories (MASTER/BACKEND/DATABASE) with verified baseline Sprint 1: Fixed 8 P0 blockers - CFDI entities (schema cfdi→fiscal), auth base DDL, billing duplication (→operations), 5 project entities, PaymentInvoiceAllocation, core.companies DDL, recreate-database.sh array Sprint 2: 4 new auth entities, session/role/permission DDL reconciliation, CFDI PAC+StampQueue, partner address+contact alignment Sprint 3: CFDI service+controller+routes, mobile service+controller+routes, inventory extended DDL (7 tables) Sprint 4: timestamp→timestamptz (40 files), field divergences, token/roles/permissions service alignment with new DDL-aligned entities Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
110 lines
3.2 KiB
TypeScript
110 lines
3.2 KiB
TypeScript
import {
|
|
Entity,
|
|
PrimaryGeneratedColumn,
|
|
Column,
|
|
CreateDateColumn,
|
|
Index,
|
|
ManyToOne,
|
|
JoinColumn,
|
|
} from 'typeorm';
|
|
import { CfdiInvoice } from './cfdi-invoice.entity.js';
|
|
|
|
/**
|
|
* CFDI operation type aligned with DDL fiscal.cfdi_operation_type
|
|
*/
|
|
export enum CfdiOperationType {
|
|
CREATE = 'create',
|
|
STAMP = 'stamp',
|
|
STAMP_RETRY = 'stamp_retry',
|
|
CANCEL_REQUEST = 'cancel_request',
|
|
CANCEL_ACCEPT = 'cancel_accept',
|
|
CANCEL_REJECT = 'cancel_reject',
|
|
CANCEL_COMPLETE = 'cancel_complete',
|
|
VALIDATE = 'validate',
|
|
DOWNLOAD = 'download',
|
|
EMAIL = 'email',
|
|
ERROR = 'error',
|
|
}
|
|
|
|
/**
|
|
* CFDI Operation Log Entity
|
|
* Aligned with DDL: fiscal.cfdi_operation_logs
|
|
*/
|
|
@Entity({ schema: 'fiscal', name: 'cfdi_operation_logs' })
|
|
@Index('idx_cfdi_operation_logs_tenant', ['tenantId'])
|
|
@Index('idx_cfdi_operation_logs_cfdi', ['cfdiInvoiceId'])
|
|
@Index('idx_cfdi_operation_logs_operation', ['operationType'])
|
|
@Index('idx_cfdi_operation_logs_created', ['createdAt'])
|
|
export class CfdiLog {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id: string;
|
|
|
|
@Column({ type: 'uuid', nullable: false, name: 'tenant_id' })
|
|
tenantId: string;
|
|
|
|
@Column({ type: 'uuid', nullable: true, name: 'cfdi_invoice_id' })
|
|
cfdiInvoiceId: string | null;
|
|
|
|
@Column({ type: 'varchar', length: 36, nullable: true, name: 'cfdi_uuid' })
|
|
cfdiUuid: string | null;
|
|
|
|
@Column({
|
|
type: 'enum',
|
|
enum: CfdiOperationType,
|
|
nullable: false,
|
|
name: 'operation_type',
|
|
})
|
|
operationType: CfdiOperationType;
|
|
|
|
@Column({ type: 'varchar', length: 50, nullable: true, name: 'status_before' })
|
|
statusBefore: string | null;
|
|
|
|
@Column({ type: 'varchar', length: 50, nullable: true, name: 'status_after' })
|
|
statusAfter: string | null;
|
|
|
|
@Column({ type: 'boolean', default: false, nullable: false, name: 'success' })
|
|
success: boolean;
|
|
|
|
@Column({ type: 'varchar', length: 100, nullable: true, name: 'error_code' })
|
|
errorCode: string | null;
|
|
|
|
@Column({ type: 'text', nullable: true, name: 'error_message' })
|
|
errorMessage: string | null;
|
|
|
|
@Column({ type: 'jsonb', nullable: true, name: 'error_details' })
|
|
errorDetails: Record<string, any> | null;
|
|
|
|
@Column({ type: 'jsonb', nullable: true, name: 'request_payload' })
|
|
requestPayload: Record<string, any> | null;
|
|
|
|
@Column({ type: 'jsonb', nullable: true, name: 'response_payload' })
|
|
responsePayload: Record<string, any> | null;
|
|
|
|
@Column({ type: 'varchar', length: 20, nullable: true, name: 'pac_code' })
|
|
pacCode: string | null;
|
|
|
|
@Column({ type: 'varchar', length: 100, nullable: true, name: 'pac_transaction_id' })
|
|
pacTransactionId: string | null;
|
|
|
|
@Column({ type: 'inet', nullable: true, name: 'ip_address' })
|
|
ipAddress: string | null;
|
|
|
|
@Column({ type: 'varchar', length: 500, nullable: true, name: 'user_agent' })
|
|
userAgent: string | null;
|
|
|
|
@Column({ type: 'integer', nullable: true, name: 'duration_ms' })
|
|
durationMs: number | null;
|
|
|
|
// Relation
|
|
@ManyToOne(() => CfdiInvoice, (invoice) => invoice.logs, { onDelete: 'SET NULL' })
|
|
@JoinColumn({ name: 'cfdi_invoice_id' })
|
|
cfdiInvoice: CfdiInvoice | null;
|
|
|
|
// Audit
|
|
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
|
|
createdAt: Date;
|
|
|
|
@Column({ type: 'uuid', nullable: true, name: 'created_by' })
|
|
createdBy: string | null;
|
|
}
|