fix(project):filter sts in monitor or design
This commit is contained in:
@@ -175,7 +175,16 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
||||
return True
|
||||
|
||||
async def list_project_design(self):
|
||||
project = await use_collection(COLLECTION).find({'monitor': {"$exists": 0}}).to_list(None)
|
||||
project = await use_collection(COLLECTION).find({
|
||||
'$or': [
|
||||
{'has_monitor': False},
|
||||
{'monitor': {'$exists': 0}},
|
||||
{
|
||||
'has_monitor': True,
|
||||
'monitor.has_design': True
|
||||
}
|
||||
]
|
||||
}).to_list(None)
|
||||
return project
|
||||
|
||||
async def list_project_monitor(self):
|
||||
@@ -231,25 +240,69 @@ class ProjectRepository(BaseRepository[ProjectModel]):
|
||||
|
||||
return projects
|
||||
|
||||
@staticmethod
|
||||
def _has_design_sts_filter(te_input) -> bool:
|
||||
if not te_input:
|
||||
return False
|
||||
f_list = getattr(te_input, 'f', None) if not isinstance(te_input, dict) else te_input.get('f')
|
||||
if not f_list:
|
||||
return False
|
||||
for scope in f_list:
|
||||
items = scope.get('items', []) if isinstance(scope, dict) else getattr(scope, 'items', [])
|
||||
if items:
|
||||
for item in items:
|
||||
col = item.get('col') if isinstance(item, dict) else getattr(item, 'col', '')
|
||||
if col == 'design.sts':
|
||||
return True
|
||||
return False
|
||||
|
||||
async def fetch_delete(self, _input: TableEngineRequestType) -> TableEngineExport[T]:
|
||||
return await NewTableEngine.mongo(
|
||||
extra_filter = [{'sts': 2}]
|
||||
if self._has_design_sts_filter(_input.te if _input else None):
|
||||
extra_filter.append({
|
||||
'$or': [
|
||||
{'has_monitor': False},
|
||||
{'monitor': {'$exists': False}},
|
||||
{'has_monitor': True, 'monitor.has_design': True}
|
||||
]
|
||||
})
|
||||
result = await NewTableEngine.mongo(
|
||||
query_class=use_collection(self.COLLECTION),
|
||||
soft_deleted=True,
|
||||
model=self.MODEL,
|
||||
search_cols=['design.title'],
|
||||
extra_filter=[{'sts': 2}],
|
||||
extra_filter=extra_filter,
|
||||
inputs=_input.te) \
|
||||
.to_dict()
|
||||
if result and result.rows:
|
||||
for row in result.rows:
|
||||
if row.monitor and row.monitor.has_design is False:
|
||||
row.design.sts = None
|
||||
return result
|
||||
|
||||
async def fetch(self, _input: TableEngineRequestType) -> TableEngineExport[T]:
|
||||
return await NewTableEngine.mongo(
|
||||
extra_filter = [{'sts': 1}]
|
||||
if self._has_design_sts_filter(_input.te if _input else None):
|
||||
extra_filter.append({
|
||||
'$or': [
|
||||
{'has_monitor': False},
|
||||
{'monitor': {'$exists': False}},
|
||||
{'has_monitor': True, 'monitor.has_design': True}
|
||||
]
|
||||
})
|
||||
result = await NewTableEngine.mongo(
|
||||
query_class=use_collection(self.COLLECTION),
|
||||
soft_deleted=True,
|
||||
model=self.MODEL,
|
||||
search_cols=['design.title'],
|
||||
extra_filter=[{'sts': 1}],
|
||||
extra_filter=extra_filter,
|
||||
inputs=_input.te) \
|
||||
.to_dict()
|
||||
if result and result.rows:
|
||||
for row in result.rows:
|
||||
if row.monitor and row.monitor.has_design is False:
|
||||
row.design.sts = None
|
||||
return result
|
||||
|
||||
async def get_all(self):
|
||||
url = 'http://api.khanesaziceco.ir/api/api/project/table'
|
||||
|
||||
Reference in New Issue
Block a user