feat(benefits-reception): add institutional benefits, QR digital card & reception access control (SDD-012 v3.8.39)
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
from app import db
|
||||
from datetime import datetime, timezone
|
||||
from typing import Dict, Any
|
||||
|
||||
|
||||
class AccessLogQR(db.Model):
|
||||
"""
|
||||
Registro y trazabilidad de ingresos escaneados por código QR en Recepción (SDD-012).
|
||||
Permite auditar el ingreso físico de alumnos y docentes a las sedes institucionales.
|
||||
"""
|
||||
__tablename__ = 'access_logs_qr'
|
||||
__allow_unmapped__ = True
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('users.id', ondelete='CASCADE'), nullable=False, index=True)
|
||||
building_id = db.Column(db.Integer, db.ForeignKey('buildings.id', ondelete='SET NULL'), nullable=True, index=True)
|
||||
scanned_by_user_id = db.Column(db.Integer, db.ForeignKey('users.id', ondelete='SET NULL'), nullable=True)
|
||||
scanned_at = db.Column(
|
||||
db.DateTime,
|
||||
default=lambda: datetime.now(timezone.utc).replace(tzinfo=None),
|
||||
nullable=False,
|
||||
index=True
|
||||
)
|
||||
status = db.Column(db.String(20), default='AUTORIZADO', nullable=False) # AUTORIZADO, DENEGADO, RESTRINGIDO
|
||||
reason = db.Column(db.String(150), nullable=True)
|
||||
|
||||
# Relaciones
|
||||
user = db.relationship('User', foreign_keys=[user_id], backref=db.backref('qr_access_logs', lazy='dynamic'))
|
||||
building = db.relationship('Building', foreign_keys=[building_id])
|
||||
scanned_by = db.relationship('User', foreign_keys=[scanned_by_user_id])
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
"""Serializa el registro de acceso a diccionario JSON."""
|
||||
return {
|
||||
'id': self.id,
|
||||
'user_id': self.user_id,
|
||||
'user_name': self.user.name if self.user else 'Desconocido',
|
||||
'user_dni': self.user.document_number if self.user else None,
|
||||
'user_role': self.user.role if self.user else None,
|
||||
'building_id': self.building_id,
|
||||
'building_name': self.building.name if self.building else 'Sede Desconocida',
|
||||
'scanned_by_user_id': self.scanned_by_user_id,
|
||||
'scanned_by_name': self.scanned_by.name if self.scanned_by else 'Sistema',
|
||||
'scanned_at': self.scanned_at.isoformat() if self.scanned_at else None,
|
||||
'status': self.status,
|
||||
'reason': self.reason
|
||||
}
|
||||
Reference in New Issue
Block a user