137 lines
2.8 KiB
TypeScript
137 lines
2.8 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
import { CurrentUser } from '../auth/current-user.decorator';
|
|
import {
|
|
CreateTicketDto,
|
|
CreateTicketMessageDto,
|
|
ListTicketsQueryDto,
|
|
UpdateTicketDto,
|
|
} from './dto';
|
|
import { TicketsService } from './tickets.service';
|
|
|
|
@Controller('tickets')
|
|
@UseGuards(JwtAuthGuard)
|
|
export class TicketsController {
|
|
constructor(private readonly ticketsService: TicketsService) {}
|
|
|
|
@Get()
|
|
list(
|
|
@CurrentUser()
|
|
user: { userId: string; organizationId: string; role: string },
|
|
@Query() query: ListTicketsQueryDto,
|
|
) {
|
|
return this.ticketsService.list(
|
|
{
|
|
userId: user.userId,
|
|
organizationId: user.organizationId,
|
|
role: user.role,
|
|
},
|
|
{
|
|
q: query.q,
|
|
status: query.status,
|
|
priority: query.priority,
|
|
personId: query.personId,
|
|
assigneeId: query.assigneeId,
|
|
sla: query.sla,
|
|
page: query.page ?? 1,
|
|
limit: query.limit ?? 50,
|
|
},
|
|
);
|
|
}
|
|
|
|
@Get(':id')
|
|
get(
|
|
@CurrentUser()
|
|
user: { userId: string; organizationId: string; role: string },
|
|
@Param('id') id: string,
|
|
) {
|
|
return this.ticketsService.get(
|
|
{
|
|
userId: user.userId,
|
|
organizationId: user.organizationId,
|
|
role: user.role,
|
|
},
|
|
id,
|
|
);
|
|
}
|
|
|
|
@Post()
|
|
create(
|
|
@CurrentUser()
|
|
user: { userId: string; organizationId: string; role: string },
|
|
@Body() dto: CreateTicketDto,
|
|
) {
|
|
return this.ticketsService.create(
|
|
{
|
|
userId: user.userId,
|
|
organizationId: user.organizationId,
|
|
role: user.role,
|
|
},
|
|
dto,
|
|
);
|
|
}
|
|
|
|
@Patch(':id')
|
|
update(
|
|
@CurrentUser()
|
|
user: { userId: string; organizationId: string; role: string },
|
|
@Param('id') id: string,
|
|
@Body() dto: UpdateTicketDto,
|
|
) {
|
|
return this.ticketsService.update(
|
|
{
|
|
userId: user.userId,
|
|
organizationId: user.organizationId,
|
|
role: user.role,
|
|
},
|
|
id,
|
|
dto,
|
|
);
|
|
}
|
|
|
|
@Delete(':id')
|
|
async remove(
|
|
@CurrentUser()
|
|
user: { userId: string; organizationId: string; role: string },
|
|
@Param('id') id: string,
|
|
) {
|
|
await this.ticketsService.remove(
|
|
{
|
|
userId: user.userId,
|
|
organizationId: user.organizationId,
|
|
role: user.role,
|
|
},
|
|
id,
|
|
);
|
|
return { ok: true };
|
|
}
|
|
|
|
@Post(':id/messages')
|
|
addMessage(
|
|
@CurrentUser()
|
|
user: { userId: string; organizationId: string; role: string },
|
|
@Param('id') id: string,
|
|
@Body() dto: CreateTicketMessageDto,
|
|
) {
|
|
return this.ticketsService.addMessage(
|
|
{
|
|
userId: user.userId,
|
|
organizationId: user.organizationId,
|
|
role: user.role,
|
|
},
|
|
id,
|
|
dto,
|
|
);
|
|
}
|
|
}
|