MukeshKapoor25 commited on
Commit
2ea2c73
·
1 Parent(s): 8c8d149

company based templates

Browse files
Files changed (1) hide show
  1. app/services/dispatcher.py +3 -15
app/services/dispatcher.py CHANGED
@@ -36,24 +36,12 @@ class NotificationDispatcher:
36
  ) -> Optional[Dict[str, Any]]:
37
  """
38
  Fetch notification_channels and notification_templates from scm_merchant_settings.
39
- First tries merchant_id-specific settings, then falls back to merchant_type='company'.
40
  Returns dict with both keys, or None if not found.
41
  """
42
  db = get_database()
43
  projection = {"_id": 0, "notification_channels": 1, "notification_templates": 1}
44
 
45
- doc = await db[settings.MERCHANT_SETTINGS_COLLECTION].find_one(
46
- {"merchant_id": merchant_id},
47
- projection,
48
- )
49
- if doc:
50
- return doc
51
-
52
- # Fallback: use company-level settings (merchant_type = "company")
53
- logger.info(
54
- "No merchant settings found for merchant_id, falling back to company-level settings",
55
- extra={"event": "merchant_settings_fallback", "merchant_id": merchant_id},
56
- )
57
  company_doc = await db[settings.MERCHANT_SETTINGS_COLLECTION].find_one(
58
  {"merchant_type": "company"},
59
  projection,
@@ -146,14 +134,14 @@ class NotificationDispatcher:
146
  "$set": {
147
  "status": NotificationStatus.FAILED.value,
148
  "channel_results": {
149
- "error": f"No notification_channels config found for merchant {merchant_id} and no company-level fallback exists"
150
  },
151
  "updated_at": datetime.utcnow(),
152
  }
153
  },
154
  )
155
  logger.error(
156
- "Dispatch failed: merchant settings not found and no company fallback",
157
  extra={
158
  "event": "notification_dispatch_failure",
159
  "notification_id": nid,
 
36
  ) -> Optional[Dict[str, Any]]:
37
  """
38
  Fetch notification_channels and notification_templates from scm_merchant_settings.
39
+ Always uses the company-level settings doc (merchant_type='company').
40
  Returns dict with both keys, or None if not found.
41
  """
42
  db = get_database()
43
  projection = {"_id": 0, "notification_channels": 1, "notification_templates": 1}
44
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  company_doc = await db[settings.MERCHANT_SETTINGS_COLLECTION].find_one(
46
  {"merchant_type": "company"},
47
  projection,
 
134
  "$set": {
135
  "status": NotificationStatus.FAILED.value,
136
  "channel_results": {
137
+ "error": "No company-level notification_channels config found (merchant_type=company)"
138
  },
139
  "updated_at": datetime.utcnow(),
140
  }
141
  },
142
  )
143
  logger.error(
144
+ "Dispatch failed: company-level merchant settings not found",
145
  extra={
146
  "event": "notification_dispatch_failure",
147
  "notification_id": nid,