import uuid from app.config import TaskEnv from app.models.monito_physical_progress import PhysicalProgressModel from core.repositories.base import BaseRepository from core.service.mongo_db import use_collection from core.utils.crudify import mongo_inserter from app.repositories.project import ProjectRepository COLLECTION = TaskEnv.CLN_MONITOR_PYSICAL MODEL = PhysicalProgressModel class PhysicalProgressRepository(BaseRepository): def __init__(self): super().__init__(collection=TaskEnv.CLN_MONITOR_PYSICAL, model=PhysicalProgressModel) async def last_record(self,project_id:uuid.UUID): last = await use_collection(TaskEnv.CLN_MONITOR_PYSICAL).find({'project_id':project_id}).sort("$natural", -1).to_list(None) if last: return last[0] else: return {} async def create(self,_inp:MODEL): create = await mongo_inserter(_inp,COLLECTION,getter=self.get) await ProjectRepository().set_sts_two_for_monitor(_inp.project_id) return create