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
18 changes: 18 additions & 0 deletions src/order/dto/order-delivery.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,21 @@ export class OrderDeliveryEmployeeDTO extends IntersectionType(
@Type(() => EmployeeDTO)
employee: EmployeeDTO;
}

export class UpdateDeliveryWsDTO {
@ApiProperty({ description: 'ID of the order delivery' })
@IsString()
@IsUUID()
id: string;

@ApiPropertyOptional({ description: 'New delivery status' })
@IsOptional()
@IsString()
deliveryStatus?: string;

@ApiPropertyOptional({
description: 'indicate the delivery is rejected (employee unassign)',
})
@IsOptional()
employeeId?: string;
}
39 changes: 31 additions & 8 deletions src/order/order.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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';

@WebSocketGateway({
cors: {
Expand All @@ -40,11 +41,11 @@
) {}

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

Check warning on line 44 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 48 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 All @@ -60,16 +61,38 @@
@ConnectedSocket() client: Socket,
@MessageBody() data: UpdateOrderStatusWsDTO,
) {
this.orderService.update(data.id, data.status).then((order) => {
if (!order) {
this.server.to(client.id).emit('error', {
message: 'Order not found',
data: { id: data.id },
});
}
this.orderService.findOneWithUser(data.id).then((order) => {

Check warning on line 64 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
this.orderService.getUserByOrderId(order.id).then((user) => {

Check warning on line 65 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
if (user.wsId) {
client.to(user.wsId).emit('order', order);
client
.to(user.wsId)
.emit('orderUpdated', { orderId: order.id, status: data.status });
}
});
});
}

@UseFilters(new WebsocketExceptionsFilter())
@UsePipes(
new ValidationPipe({
exceptionFactory: (errors) => new WsException(errors),
}),
)
@UseGuards(AuthGuardWs, RolesGuardWs)
@Roles(UserRole.ADMIN, UserRole.BRANCH_ADMIN)
@SubscribeMessage('updateDelivery')
updateDelivery(
@ConnectedSocket() client: Socket,
@MessageBody() data: UpdateDeliveryWsDTO,
) {
this.orderService.getDelivery(data.id).then((delivery) => {

Check warning on line 88 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
this.orderService.getUserByOrderId(delivery.order.id).then((user) => {

Check warning on line 89 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
if (user.wsId) {
client.to(user.wsId).emit('deliveryUpdated', {
orderDeliveryId: delivery.id,
status: data.deliveryStatus,
employeeId: delivery.employee.id,
});
}
});
});
Expand Down
Loading