refactor(core): Related ticket slash command to use serializer

ref: #248 #368 #374
This commit is contained in:
2024-11-01 14:59:47 +09:30
parent bf56b271d7
commit 04ae338864

View File

@ -48,7 +48,7 @@ For this command to process the following conditions must be met:
if ticket_id is not None:
from core.models.ticket.ticket import RelatedTickets
from core.serializers.ticket_related import RelatedTicketModelSerializer
if command == 'relate':
@ -82,13 +82,23 @@ For this command to process the following conditions must be met:
to_ticket = self.ticket.__class__.objects.get(pk = ticket_id)
RelatedTickets.objects.create(
from_ticket_id = from_ticket,
how_related = how_related,
to_ticket_id = to_ticket,
organization = self.organization
item = RelatedTicketModelSerializer(
data = {
'from_ticket_id': from_ticket.id,
'how_related': int(how_related),
'to_ticket_id': to_ticket.id,
'organization': from_ticket.organization.id
}
)
if item.is_valid( raise_exception = False ):
item.save()
else:
return str(match.string[match.start():match.end()])
else:
#ToDo: Add logging that the slash command could not be processed.