Adding multi tenant check and Starting firm initialization
This commit is contained in:
@@ -9,9 +9,9 @@ from pydantic import BaseModel, Field, computed_field
|
||||
class CrudDocument(BaseModel):
|
||||
id: Optional[PydanticObjectId] = Field(default=None)
|
||||
created_at: datetime = Field(default=datetime.now(UTC), nullable=False, title="Créé le")
|
||||
# created_by: str
|
||||
updated_at: datetime = Field(default_factory=datetime.utcnow, nullable=False, title="Modifié le")
|
||||
# updated_by: str
|
||||
created_by: str = Field(nullable=False, title="Créé par")
|
||||
updated_at: datetime = Field(default_factory=lambda: datetime.now(UTC), nullable=False, title="Modifié le")
|
||||
updated_by: str = Field(nullable=False, title="Modifié par")
|
||||
|
||||
@property
|
||||
def _id(self):
|
||||
@@ -37,8 +37,9 @@ class CrudDocument(BaseModel):
|
||||
|
||||
@classmethod
|
||||
async def create(cls, db, create_schema):
|
||||
values = cls.model_validate(create_schema.model_dump()).model_dump(mode="json")
|
||||
result = await cls._get_collection(db).insert_one(values)
|
||||
model_dict = create_schema.model_dump() | {"created_by": db.user, "updated_by":db.user}
|
||||
document = cls.model_validate(model_dict).model_dump(mode="json")
|
||||
result = await cls._get_collection(db).insert_one(document)
|
||||
|
||||
return await cls.get(db, result.inserted_id)
|
||||
|
||||
@@ -56,12 +57,12 @@ class CrudDocument(BaseModel):
|
||||
|
||||
@classmethod
|
||||
async def get(cls, db, model_id):
|
||||
value = await cls._get_collection(db).find_one({"_id": model_id})
|
||||
if not value:
|
||||
document = await cls._get_collection(db).find_one({"_id": model_id})
|
||||
if not document:
|
||||
return None
|
||||
|
||||
value["id"] = value.pop("_id")
|
||||
return cls.model_validate(value)
|
||||
document["id"] = document.pop("_id")
|
||||
return cls.model_validate(document)
|
||||
|
||||
@classmethod
|
||||
async def update(cls, db, model, update_schema):
|
||||
|
||||
Reference in New Issue
Block a user