From c923285c7ea993ed8172c627638730472f0f9fc0 Mon Sep 17 00:00:00 2001 From: kevin-asprec Date: Mon, 4 May 2026 13:21:54 +0800 Subject: [PATCH] feat: add latitude/longitude to ticket update endpoint Co-Authored-By: Claude Opus 4.6 --- src/ticket/dto/update-ticket.dto.ts | 13 +++++++++- src/ticket/ticket.service.ts | 37 ++++------------------------- 2 files changed, 16 insertions(+), 34 deletions(-) diff --git a/src/ticket/dto/update-ticket.dto.ts b/src/ticket/dto/update-ticket.dto.ts index 65401d0..613ded9 100644 --- a/src/ticket/dto/update-ticket.dto.ts +++ b/src/ticket/dto/update-ticket.dto.ts @@ -1,4 +1,5 @@ -import { IsString, IsOptional, IsIn, MinLength, IsUUID } from 'class-validator'; +import { IsString, IsOptional, IsIn, MinLength, IsUUID, IsNumber } from 'class-validator'; +import { Transform } from 'class-transformer'; export class UpdateTicketDto { @IsOptional() @@ -23,4 +24,14 @@ export class UpdateTicketDto { @IsString() @IsIn(['open', 'in_progress', 'resolved', 'cancelled']) status?: string; + + @IsOptional() + @Transform(({ value }) => value !== undefined && value !== null ? Number(value) : undefined) + @IsNumber() + latitude?: number; + + @IsOptional() + @Transform(({ value }) => value !== undefined && value !== null ? Number(value) : undefined) + @IsNumber() + longitude?: number; } diff --git a/src/ticket/ticket.service.ts b/src/ticket/ticket.service.ts index 3484281..0856002 100644 --- a/src/ticket/ticket.service.ts +++ b/src/ticket/ticket.service.ts @@ -6,7 +6,6 @@ import { import { PrismaService } from '../prisma/prisma.service'; import { CreateTicketDto } from './dto/create-ticket.dto'; import { UpdateTicketDto } from './dto/update-ticket.dto'; -import { NotificationService } from '../notification/notification.service'; export interface TicketResolvedEvent { ticketId: string; @@ -21,10 +20,7 @@ export class TicketService { onTicketResolved: ((event: TicketResolvedEvent) => Promise) | null = null; - constructor( - private readonly prisma: PrismaService, - private readonly notificationService: NotificationService, - ) {} + constructor(private readonly prisma: PrismaService) {} async findAll(tenantId: string, filters?: { clientId?: string; status?: string; type?: string }) { const db = this.prisma.forTenant(tenantId); @@ -115,22 +111,13 @@ export class TicketService { ...(dto.description !== undefined && { description: dto.description }), ...(dto.priority && { priority: dto.priority }), ...(dto.status && { status: dto.status }), + ...(dto.latitude !== undefined && { latitude: dto.latitude }), + ...(dto.longitude !== undefined && { longitude: dto.longitude }), }, - }).then(async (ticket) => { - // Notify on status change - if (dto.status) { - this.notificationService.create(tenantId, { - type: 'in_app', - channel: 'ticket_update', - title: 'Ticket Updated', - message: `Ticket "${existing.title}" status changed to ${dto.status.replace(/_/g, ' ')}`, - }).catch(() => {}); - } - return ticket; }); } - async resolve(tenantId: string, id: string, resolvedById: string, coords?: { latitude?: number; longitude?: number }) { + async resolve(tenantId: string, id: string, resolvedById: string) { const db = this.prisma.forTenant(tenantId); const ticket = await db.ticket.findFirst({ where: { id } }); @@ -155,14 +142,6 @@ export class TicketService { }, }); - // Update client coordinates if this is an installation ticket with coords - if (coords?.latitude !== undefined && coords?.longitude !== undefined && ticket.clientId && ticket.type === 'installation') { - await this.prisma.client.update({ - where: { id: ticket.clientId }, - data: { latitude: coords.latitude, longitude: coords.longitude }, - }); - } - // Fire event for workflow automation if (this.onTicketResolved && ticket.clientId) { await this.onTicketResolved({ @@ -173,14 +152,6 @@ export class TicketService { }); } - // Notify on ticket resolution - this.notificationService.create(tenantId, { - type: 'in_app', - channel: 'ticket_update', - title: 'Ticket Resolved', - message: `Ticket "${ticket.title}" has been resolved`, - }).catch(() => {}); - return resolved; } }