diff --git a/api/api_v1/endpoints/report.py b/api/api_v1/endpoints/report.py index 80c74de..9994e4f 100644 --- a/api/api_v1/endpoints/report.py +++ b/api/api_v1/endpoints/report.py @@ -86,6 +86,9 @@ async def delete( """删除报表""" # 删除Report 自己创建的 del_report = await crud.report.delete(db, {'_id': data_in.id, 'user_id': current_user.id}) + # 从看板弹出 + del_item = {'report_id': data_in.id} + await crud.dashboard.update_many(db, {}, {'$pull': {'reports': del_item}}) if del_report.deleted_count == 0: return schemas.Msg(code=-1, msg='error', data='删除失败') diff --git a/crud/base.py b/crud/base.py index e5ea933..4669680 100644 --- a/crud/base.py +++ b/crud/base.py @@ -41,5 +41,8 @@ class CRUDBase: async def update_one(self, db, filter, update, upsert=False): return await db[self.coll_name].update_one(filter, update, upsert) + async def update_many(self, db, filter, update, upsert=False): + return await db[self.coll_name].update_many(filter, update, upsert) + async def distinct(self, db, key, filter=None): return await db[self.coll_name].distinct(key, filter)