Implentation of get current firm
This commit is contained in:
@@ -5,7 +5,7 @@ from pydantic import Field
|
||||
|
||||
from firm.core.models import CrudDocument
|
||||
from firm.core.schemas import Writer, Reader
|
||||
from firm.entity.schemas import EntityIndividualCreate, EntityCorporationCreate
|
||||
from firm.entity.schemas import EntityIndividualCreate, EntityCorporationCreate, EntityRead
|
||||
|
||||
|
||||
class CurrentFirmModel(CrudDocument):
|
||||
@@ -34,7 +34,17 @@ class CurrentFirmModel(CrudDocument):
|
||||
|
||||
|
||||
class CurrentFirmSchemaRead(Reader):
|
||||
pass
|
||||
entity: EntityRead
|
||||
partner: EntityRead
|
||||
instance: str
|
||||
firm: str
|
||||
primary_color: str
|
||||
secondary_color: str
|
||||
|
||||
@classmethod
|
||||
def from_model_and_entities(cls, model, entity, partner):
|
||||
schema = cls(**model.model_dump(mode="json"), entity=entity, partner=partner)
|
||||
return schema
|
||||
|
||||
class CurrentFirmSchemaCreate(Writer):
|
||||
corporation: EntityCorporationCreate = Field(title="Informations sur la firme")
|
||||
@@ -51,3 +61,12 @@ class CurrentFirmSchemaUpdate(Writer):
|
||||
class Partner(CrudDocument):
|
||||
user_id: PydanticObjectId = Field()
|
||||
entity_id: PydanticObjectId = Field()
|
||||
|
||||
@classmethod
|
||||
async def get_by_user_id(cls, db, user_id):
|
||||
document = await cls._get_collection(db).find_one({"user_id": str(user_id)})
|
||||
if not document:
|
||||
return None
|
||||
|
||||
document["id"] = document.pop("_id")
|
||||
return cls.model_validate(document)
|
||||
|
||||
Reference in New Issue
Block a user