src/messages/messages.controller.ts
messages
Methods |
| Async create | |||||||||||||||
create(orgId: string, senderId: string, senderRole: string, dto: CreateMessageDto)
|
|||||||||||||||
Decorators :
@Post()
|
|||||||||||||||
|
Defined in src/messages/messages.controller.ts:41
|
|||||||||||||||
|
Parameters :
Returns :
unknown
|
| Async findMine |
findMine(orgId: string, userId: string, page?: string, limit?: string)
|
Decorators :
@Get()
|
|
Defined in src/messages/messages.controller.ts:52
|
|
Returns :
unknown
|
| Async findSent |
findSent(orgId: string, userId: string, page?: string, limit?: string)
|
Decorators :
@Get('sent')
|
|
Defined in src/messages/messages.controller.ts:80
|
|
Returns :
unknown
|
| Async markRead |
markRead(orgId: string, userId: string, id: string)
|
Decorators :
@Post(':id/read')
|
|
Defined in src/messages/messages.controller.ts:105
|
|
Returns :
unknown
|
| Async remove |
remove(orgId: string, userId: string, id: string)
|
Decorators :
@Delete(':id')
|
|
Defined in src/messages/messages.controller.ts:115
|
|
Returns :
unknown
|
| Async unreadCount |
unreadCount(orgId: string, userId: string)
|
Decorators :
@Get('unread-count')
|
|
Defined in src/messages/messages.controller.ts:96
|
|
Returns :
unknown
|
import {
Controller,
Get,
Post,
Delete,
Body,
Param,
Query,
UseGuards,
} from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
import { MessagesService } from './messages.service';
import { CreateMessageDto } from './dto/create-message.dto';
import { CombinedAuthGuard } from '../auth/guards/combined-auth.guard';
import { RolesGuard } from '../auth/guards/roles.guard';
import { Roles } from '../auth/decorators/roles.decorator';
import { CurrentUser } from '../auth/decorators/current-user.decorator';
@ApiTags('Messages')
@ApiBearerAuth()
@UseGuards(CombinedAuthGuard, RolesGuard)
@Controller('messages')
export class MessagesController {
constructor(private readonly messagesService: MessagesService) {}
@Post()
@Roles(
'DISPATCHER',
'OPERATIONS_MANAGER',
'PLANNER',
'ADMIN',
'SUPER_ADMIN',
'CUSTOMER_SERVICE',
'DRIVER',
)
@ApiOperation({
summary: 'Send a message',
description:
'Dispatchers/admins can start new threads with drivers (provide driverId). Drivers can ONLY reply to existing threads (provide replyToId).',
})
async create(
@CurrentUser('organizationId') orgId: string,
@CurrentUser('id') senderId: string,
@CurrentUser('role') senderRole: string,
@Body() dto: CreateMessageDto,
) {
return this.messagesService.create(orgId, senderId, senderRole, dto);
}
@Get()
@ApiOperation({ summary: 'List my received messages' })
async findMine(
@CurrentUser('organizationId') orgId: string,
@CurrentUser('id') userId: string,
@Query('page') page?: string,
@Query('limit') limit?: string,
) {
return this.messagesService.findMyMessages(
orgId,
userId,
page ? parseInt(page, 10) : 1,
limit ? parseInt(limit, 10) : 20,
);
}
@Get('sent')
// Drivers also need access to their own sent thread (replies they
// wrote to dispatchers). The previous list locked them out and they
// would have seen 403.
@Roles(
'DISPATCHER',
'OPERATIONS_MANAGER',
'PLANNER',
'ADMIN',
'SUPER_ADMIN',
'CUSTOMER_SERVICE',
'DRIVER',
)
@ApiOperation({ summary: 'List messages I sent' })
async findSent(
@CurrentUser('organizationId') orgId: string,
@CurrentUser('id') userId: string,
@Query('page') page?: string,
@Query('limit') limit?: string,
) {
return this.messagesService.findSentMessages(
orgId,
userId,
page ? parseInt(page, 10) : 1,
limit ? parseInt(limit, 10) : 20,
);
}
@Get('unread-count')
@ApiOperation({ summary: 'Unread messages count for badge' })
async unreadCount(
@CurrentUser('organizationId') orgId: string,
@CurrentUser('id') userId: string,
) {
return this.messagesService.getUnreadCount(orgId, userId);
}
@Post(':id/read')
@ApiOperation({ summary: 'Mark a message as read' })
async markRead(
@CurrentUser('organizationId') orgId: string,
@CurrentUser('id') userId: string,
@Param('id') id: string,
) {
return this.messagesService.markRead(orgId, userId, id);
}
@Delete(':id')
@ApiOperation({ summary: 'Delete a message' })
async remove(
@CurrentUser('organizationId') orgId: string,
@CurrentUser('id') userId: string,
@Param('id') id: string,
) {
return this.messagesService.remove(orgId, userId, id);
}
}