Untitled

 avatar
unknown
plain_text
5 months ago
6.0 kB
3
Indexable
product_field_type.py:
from typing import TYPE_CHECKING, Annotated, Optional

from strawberry import ID, Parent, field, lazy, type

from app.graphql.schema import Info
from app.models import ProductField

if TYPE_CHECKING:
    from .field_detail_type import FieldDetailType
    from .product_type import ProductType


@type(name="ProductField")
class ProductFieldType:
    id: ID
    record_id: int
    field_id: int
    field_value: Optional[str]

    @field
    def product_id(self, info: Info) -> int:
        return self.record_id

    @field
    @staticmethod
    async def product(
        info: Info, parent: Parent["ProductField"]
    ) -> Optional[Annotated["ProductType", lazy(".product_type")]]:
        return await info.context.load_product.load(parent.record_id)

    @field
    @staticmethod
    async def field_details(
        info: Info, parent: Parent["ProductField"]
    ) -> Optional[Annotated["FieldDetailType", lazy(".field_detail_type")]]:
        return await info.context.load_field_detail.load(parent.field_id)

product_type.py:
from datetime import datetime
from typing import List, Optional

from strawberry import ID, Parent, field, type

from app.graphql.schema import Info
from app.models import Product, ProductField

from .product_field_type import ProductFieldType
from .status_type import StatusType
from .country_type import CountryType
from .therapeutic_type import TherapeuticType
from .user_type import UserType


@type(name="Product")
class ProductType:
    id: ID
    mdm_id: int
    series_id: int
    country_id: int
    product_name: str
    request_status_id: int
    current_record: int
    last_active: int
    is_deleted: int
    created_date: datetime
    created_by_id: str
    updated_date: datetime
    updated_by_id: str

    reltio_id: Optional[str]
    group_type: Optional[str]
    janssen_mstr_prdct_nm: Optional[str]
    product_phase: Optional[str]
    jnj_full_compound_id: Optional[str]
    generic_name: Optional[str]
    jnj_flag: Optional[str]
    th_area: Optional[int]
    product_status: Optional[str]
    ta_sub_type: Optional[str]

    @field
    @staticmethod
    async def created_by(info: Info, parent: Parent["Product"]) -> Optional["UserType"]:
        return await info.context.load_user_by_login.load(parent.created_by_id)

    @field
    @staticmethod
    async def updated_by(info: Info, parent: Parent["Product"]) -> Optional["UserType"]:
        return await info.context.load_user_by_login.load(parent.updated_by_id)

    @field
    @staticmethod
    async def product_fields(
        info: Info, parent: Parent["Product"]
    ) -> List["ProductFieldType"]:
        return (
            await info.context.load_product_fields_by_product_id.load(parent.id) or []
        )
    
    @field
    @staticmethod
    async def status(info: Info, parent: Parent["Product"]) -> Optional["StatusType"]:
        return await info.context.load_status.load(parent.id)

    @field
    @staticmethod
    async def country(info: Info, parent: Parent["Product"]) -> Optional["CountryType"]:
        return await info.context.load_country.load(parent.id)

    @field
    @staticmethod
    async def therapeutic(info: Info, parent: Parent["Product"]) -> Optional["TherapeuticType"]:
        return await info.context.load_therapeutic.load(parent.id)

field_detail_type.py:
from datetime import datetime
from typing import List, Optional

from strawberry import ID, Parent, field, input, type

from app.graphql.schema import Info
from app.models import FieldDetail

from .user_type import UserType
from .validation_type import ValidationType


@type(name="FieldDetail")
class FieldDetailType:
    id: ID
    label: str
    name: str
    type: str
    order: int
    field_format: str | None
    validation_id: str | None
    options: str | None
    rcvd_from_reltio: str | None
    is_dynamic: str
    is_active: str
    is_editable: str
    is_deleted: int
    is_visible: str
    is_downstream: str
    is_published: str
    default_option: str | None
    created_date: datetime
    created_by_id: str
    updated_by_id: str

    @field
    @staticmethod
    async def created_by(
        info: Info, parent: Parent["FieldDetail"]
    ) -> Optional["UserType"]:
        return await info.context.load_user_by_login.load(parent.created_by_id)

    @field
    @staticmethod
    async def updated_by(
        info: Info, parent: Parent["FieldDetail"]
    ) -> Optional["UserType"]:
        return await info.context.load_user_by_login.load(parent.updated_by_id)

    @field
    @staticmethod
    async def validations(
        info: Info, parent: Parent["FieldDetail"]
    ) -> Optional[List["ValidationType"]]:
        if not parent.validation_id:
            return None
        ids = [int(id.strip()) for id in parent.validation_id.split(",") if id.strip()]
        return await info.context.load_validation.load_many(ids)


@input
class UpdateFieldDetailsInput:
    id: int
    label: str
    name: str
    type: str
    order: int
    options: Optional[str] = None
    field_format: Optional[str] = None
    validation_value: Optional[str] = None


@input
class CreateFieldDetailsInput:
    label: str
    name: str
    type: str
    order: int
    field_format: Optional[str] = None
    validation_value: Optional[str] = None
    options: Optional[str] = None
    rcvd_from_reltio: Optional[str] = None
    is_dynamic: Optional[str] = None
    is_active: Optional[str] = None
    is_editable: Optional[str] = None
    is_visible: Optional[str] = None
    is_downstream: Optional[str] = None
    is_published: Optional[str] = None
    default_option: Optional[str] = None
    created_by: Optional[str] = None
    updated_by: Optional[str] = None


@input
class DeleteFieldDetailsInput:
    id: int
Editor is loading...
Leave a Comment