Untitled

 avatar
unknown
plain_text
5 months ago
1.6 kB
2
Indexable
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 .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 []
        )
Editor is loading...
Leave a Comment