mirror of
https://github.com/beak-insights/felicity-lims.git
synced 2025-02-24 08:53:00 +08:00
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from typing import List, Optional
|
|
|
|
import strawberry # noqa
|
|
from api.gql.noticeboard.types import NoticeType
|
|
from api.gql.permissions import IsAuthenticated
|
|
from apps.noticeboard import models
|
|
|
|
|
|
@strawberry.type
|
|
class NoticeQuery:
|
|
@strawberry.field(permission_classes=[IsAuthenticated])
|
|
async def notice_by_uid(self, info, uid: str) -> Optional[NoticeType]:
|
|
return await models.Notice.get(uid=uid)
|
|
|
|
@strawberry.field(permission_classes=[IsAuthenticated])
|
|
async def notices_by_creator(self, info, uid: str) -> Optional[List[NoticeType]]:
|
|
return await models.Notice.get_all(created_by_uid=uid)
|
|
|
|
@strawberry.field(permission_classes=[IsAuthenticated])
|
|
async def notice_filter(
|
|
self,
|
|
info,
|
|
group_uid: str | None,
|
|
department_uid: str | None,
|
|
) -> List[NoticeType]:
|
|
filters = {}
|
|
|
|
if group_uid:
|
|
filters["groups__uid__in"] = [group_uid]
|
|
|
|
if department_uid:
|
|
filters["departments__uid__in"] = [department_uid]
|
|
|
|
notice_stmt = models.Notice.smart_query(
|
|
filters=filters, sort_attrs=["-created_at"]
|
|
)
|
|
|
|
notices = (await models.Notice.session.execute(notice_stmt)).scalars().all()
|
|
return list(notices)
|