diff --git a/api/rpk-api/firm/core/models.py b/api/rpk-api/firm/core/models.py index 8a2321c..2889230 100644 --- a/api/rpk-api/firm/core/models.py +++ b/api/rpk-api/firm/core/models.py @@ -78,13 +78,16 @@ class CrudDocument(BaseModel): @classmethod async def update(cls, db, model, update_schema): - model_dict = update_schema.model_dump(mode="json") | {"updated_by": db.partner.id} + model_dict = update_schema.model_dump(mode="json") | {"updated_by": db.partner.id, "updated_at": datetime.now(UTC)} update_query = { "$set": {field: value for field, value in model_dict.items() if field!= "id" } } await cls._get_collection(db).update_one({"_id": model.id}, update_query) - return await cls.get(db, model.id) + new_model = await cls.get(db, model.id) + if new_model.label != model.label: + await cls._get_collection(db).update_one({"_id": model.id}, {"$set": {"label": new_model.label}}) + return new_model @classmethod async def delete(cls, db, model):