feat(repairs): automatic repair status emails
This commit is contained in:
parent
3ed6596bf0
commit
c58e212e3a
21 changed files with 525 additions and 36 deletions
|
|
@ -18,14 +18,17 @@ from app.schemas.repair import (
|
|||
RepairPublicStatusResponse,
|
||||
)
|
||||
from app.services.audit_service import write_audit_log
|
||||
from app.services.repair_notification_service import STATUS_LABELS
|
||||
from app.services.repair_service import repair_label
|
||||
from app.services.repair_status_labels import STATUS_LABELS
|
||||
|
||||
|
||||
def normalize_token(token: str) -> str:
|
||||
return token.strip()
|
||||
|
||||
|
||||
def repair_label(repair: Repair) -> str:
|
||||
return f"{repair.repair_number} · {repair.customer_name}"
|
||||
|
||||
|
||||
def public_status_path(token: str) -> str:
|
||||
normalized_token = normalize_token(token)
|
||||
path = f"/status/{normalized_token}"
|
||||
|
|
@ -64,6 +67,23 @@ class RepairPublicLinkService:
|
|||
|
||||
@staticmethod
|
||||
def create(db: Session, repair: Repair, *, actor: User, request: Request) -> RepairPublicLinkCreateResponse:
|
||||
return RepairPublicLinkService.create_with_audit(
|
||||
db,
|
||||
repair,
|
||||
actor=actor,
|
||||
request=request,
|
||||
audit_action="repairs.public_link.create",
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def create_with_audit(
|
||||
db: Session,
|
||||
repair: Repair,
|
||||
*,
|
||||
actor: User | None,
|
||||
request: Request | None,
|
||||
audit_action: str,
|
||||
) -> RepairPublicLinkCreateResponse:
|
||||
token = RepairPublicLinkService.create_token()
|
||||
public_link = RepairRepository.create_public_link(
|
||||
db,
|
||||
|
|
@ -73,7 +93,7 @@ class RepairPublicLinkService:
|
|||
)
|
||||
write_audit_log(
|
||||
db,
|
||||
action="repairs.public_link.create",
|
||||
action=audit_action,
|
||||
entity_type="repairs",
|
||||
entity_id=repair.id,
|
||||
entity_label=repair_label(repair),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue