110 lines
4.2 KiB
Python
110 lines
4.2 KiB
Python
from typing import cast
|
|
import strawberry
|
|
from strawberry.types import Info
|
|
from core.graphql.inputs.session_note import (
|
|
ServiceSessionNoteInput,
|
|
ServiceSessionNoteUpdateInput,
|
|
ProjectSessionNoteInput,
|
|
ProjectSessionNoteUpdateInput,
|
|
)
|
|
from core.graphql.types.session_note import (
|
|
ServiceSessionNoteType,
|
|
ProjectSessionNoteType,
|
|
)
|
|
from core.models.session import ServiceSessionNote, ProjectSessionNote
|
|
from core.graphql.utils import create_object, update_object, delete_object
|
|
from core.services.events import (
|
|
publish_session_note_created, publish_session_note_updated, publish_session_note_deleted,
|
|
)
|
|
|
|
|
|
@strawberry.type
|
|
class Mutation:
|
|
@strawberry.mutation(description="Create a new service session note")
|
|
async def create_service_session_note(self, input: ServiceSessionNoteInput, info: Info) -> ServiceSessionNoteType:
|
|
instance = await create_object(input, ServiceSessionNote)
|
|
|
|
# Publish event for notifications
|
|
profile = getattr(info.context.request, 'profile', None)
|
|
await publish_session_note_created(
|
|
note_id=str(instance.id),
|
|
session_id=str(instance.session_id),
|
|
triggered_by=profile
|
|
)
|
|
|
|
return cast(ServiceSessionNoteType, instance)
|
|
|
|
@strawberry.mutation(description="Update an existing service session note")
|
|
async def update_service_session_note(self, input: ServiceSessionNoteUpdateInput, info: Info) -> ServiceSessionNoteType:
|
|
instance = await update_object(input, ServiceSessionNote)
|
|
|
|
# Publish event for notifications
|
|
profile = getattr(info.context.request, 'profile', None)
|
|
await publish_session_note_updated(
|
|
note_id=str(instance.id),
|
|
session_id=str(instance.session_id),
|
|
triggered_by=profile
|
|
)
|
|
|
|
return cast(ServiceSessionNoteType, instance)
|
|
|
|
@strawberry.mutation(description="Delete a service session note")
|
|
async def delete_service_session_note(self, id: strawberry.ID, info: Info) -> strawberry.ID:
|
|
instance = await delete_object(id, ServiceSessionNote)
|
|
if not instance:
|
|
raise ValueError(f"ServiceSessionNote with ID {id} does not exist")
|
|
|
|
# Publish event for notifications
|
|
profile = getattr(info.context.request, 'profile', None)
|
|
await publish_session_note_deleted(
|
|
note_id=str(id),
|
|
session_id=str(instance.session_id),
|
|
triggered_by=profile
|
|
)
|
|
|
|
return id
|
|
|
|
@strawberry.mutation(description="Create a new project session note")
|
|
async def create_project_session_note(self, input: ProjectSessionNoteInput, info: Info) -> ProjectSessionNoteType:
|
|
instance = await create_object(input, ProjectSessionNote)
|
|
|
|
# Publish event for notifications
|
|
profile = getattr(info.context.request, 'profile', None)
|
|
await publish_session_note_created(
|
|
note_id=str(instance.id),
|
|
session_id=str(instance.session_id),
|
|
triggered_by=profile
|
|
)
|
|
|
|
return cast(ProjectSessionNoteType, instance)
|
|
|
|
@strawberry.mutation(description="Update an existing project session note")
|
|
async def update_project_session_note(self, input: ProjectSessionNoteUpdateInput, info: Info) -> ProjectSessionNoteType:
|
|
instance = await update_object(input, ProjectSessionNote)
|
|
|
|
# Publish event for notifications
|
|
profile = getattr(info.context.request, 'profile', None)
|
|
await publish_session_note_updated(
|
|
note_id=str(instance.id),
|
|
session_id=str(instance.session_id),
|
|
triggered_by=profile
|
|
)
|
|
|
|
return cast(ProjectSessionNoteType, instance)
|
|
|
|
@strawberry.mutation(description="Delete a project session note")
|
|
async def delete_project_session_note(self, id: strawberry.ID, info: Info) -> strawberry.ID:
|
|
instance = await delete_object(id, ProjectSessionNote)
|
|
if not instance:
|
|
raise ValueError(f"ProjectSessionNote with ID {id} does not exist")
|
|
|
|
# Publish event for notifications
|
|
profile = getattr(info.context.request, 'profile', None)
|
|
await publish_session_note_deleted(
|
|
note_id=str(id),
|
|
session_id=str(instance.session_id),
|
|
triggered_by=profile
|
|
)
|
|
|
|
return id
|