Files
roleplay-contract/api/rpk-api/firm/current_firm/__init__.py
2025-04-16 22:49:47 +02:00

54 lines
1.5 KiB
Python

from typing import Any
from beanie import PydanticObjectId
from pydantic import Field
from firm.core.models import CrudDocument
from firm.core.schemas import Writer, Reader
from firm.entity.schemas import EntityIndividualCreate, EntityCorporationCreate
class CurrentFirmModel(CrudDocument):
instance: str = Field()
firm: str = Field()
entity_id: PydanticObjectId = Field()
primary_color: str = Field()
secondary_color: str = Field()
def __eq__(self, other: Any) -> bool:
if isinstance(other, dict):
return self.instance == other["instance"] and self.firm == other["firm"]
return super().__eq__(other)
def compute_label(self) -> str:
return f"{self.instance} / {self.firm}"
@classmethod
async def get_current(cls, db):
document = await cls._get_collection(db).find_one({})
if not document:
return None
document["id"] = document.pop("_id")
return cls.model_validate(document)
class CurrentFirmSchemaRead(Reader):
pass
class CurrentFirmSchemaCreate(Writer):
corporation: EntityCorporationCreate = Field(title="Informations sur la firme")
owner: EntityIndividualCreate = Field(title="Informations sur le dirigeant")
position: str = Field(title="Poste")
primary_color: str = Field()
secondary_color: str = Field()
class CurrentFirmSchemaUpdate(Writer):
pass
class Partner(CrudDocument):
user_id: PydanticObjectId = Field()
entity_id: PydanticObjectId = Field()