Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/order/dto/order-delivery.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import {
ApiPropertyOptional,
IntersectionType,
} from '@nestjs/swagger';
import { IsDateString, IsOptional, IsString, IsUUID } from 'class-validator';
import {
IsDateString,
IsLatitude,
IsLongitude,
IsOptional,
IsString,
IsUUID,
} from 'class-validator';
import { PaginationQueryDTO } from 'src/utils/dto/pagination.dto';
import { Expose, Transform, Type } from 'class-transformer';
import { BaseUserDTO } from 'src/user/dto/user.dto';
Expand Down Expand Up @@ -180,3 +187,17 @@ export class UpdateDeliveryWsDTO {
@IsOptional()
employeeId?: string;
}

export class UpdateCoordinatesWsDTO {
@ApiProperty({ description: 'ID of the order delivery' })
@IsUUID()
orderId: string;

@ApiProperty({ description: 'Latitude of the delivery location' })
@IsLatitude()
latitude: number;

@ApiProperty({ description: 'Longitude of the delivery location' })
@IsLongitude()
longitude: number;
}
33 changes: 32 additions & 1 deletion src/order/order.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
import { Roles } from 'src/auth/roles.decorador';
import { UserRole } from 'src/user/entities/user.entity';
import { WebsocketExceptionsFilter } from './ws.filters';
import { UpdateDeliveryWsDTO } from './dto/order-delivery.dto';
import {
UpdateCoordinatesWsDTO,
UpdateDeliveryWsDTO,
} from './dto/order-delivery.dto';
import { OrderDeliveryService } from './services/order-delivery.controller';

@WebSocketGateway({
Expand All @@ -43,11 +46,11 @@
) {}

handleConnection(client: Socket) {
this.authService.validateUserWs(client);

Check warning on line 49 in src/order/order.gateway.ts

View workflow job for this annotation

GitHub Actions / lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}

handleDisconnect(client: Socket) {
this.authService.disconnectUserWs(client);

Check warning on line 53 in src/order/order.gateway.ts

View workflow job for this annotation

GitHub Actions / lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}

@UseFilters(new WebsocketExceptionsFilter())
Expand Down Expand Up @@ -122,4 +125,32 @@
client.to(client.id).emit('error', error);
});
}

@UseFilters(new WebsocketExceptionsFilter())
@UsePipes(
new ValidationPipe({
exceptionFactory: (errors) => new WsException(errors),
}),
)
@UseGuards(AuthGuardWs, RolesGuardWs)
@Roles(UserRole.DELIVERY)
@SubscribeMessage('updateCoordinates')
updateCoordinates(
@ConnectedSocket() client: Socket,
@MessageBody() data: UpdateCoordinatesWsDTO,
) {
this.orderService
.findOneWithUser(data.orderId)
.then((order) => {
if (order.user.wsId) {
client.to(order.user.wsId).emit('coordinatesUpdated', {
latitude: data.latitude,
longitude: data.longitude,
});
}
})
.catch((error) => {
client.to(client.id).emit('error', error);
});
}
}
Loading