37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { AdminBrand } from "../../admin-auth.decorators.js";
|
|
import { Body, Controller, Post, Req } from "@nestjs/common";
|
|
import type { FastifyRequest } from "fastify";
|
|
import { AdminAccessService } from "../../admin-access.service.js";
|
|
import { CreateClientErrorDto } from "../../client-error.dto.js";
|
|
import { AdminClientErrorService } from "./admin-client-error.service.js";
|
|
|
|
@AdminBrand()
|
|
@Controller("admin/client-errors")
|
|
export class AdminClientErrorController {
|
|
constructor(
|
|
private readonly access: AdminAccessService,
|
|
private readonly errors: AdminClientErrorService,
|
|
) {}
|
|
|
|
@Post()
|
|
async create(
|
|
@Req() request: FastifyRequest,
|
|
@Body() body: CreateClientErrorDto,
|
|
): Promise<{ received: true; duplicate: boolean }> {
|
|
const identity = await this.access.requireBrand(request);
|
|
return this.errors.record({
|
|
subject: identity.subject,
|
|
brandId: identity.brandId,
|
|
errorId: body.errorId,
|
|
message: body.message,
|
|
route: body.route,
|
|
componentStack: body.componentStack,
|
|
requestId:
|
|
(request as FastifyRequest & { requestId?: string }).requestId ??
|
|
request.headers["x-request-id"]?.toString() ??
|
|
null,
|
|
userAgent: request.headers["user-agent"]?.toString().slice(0, 300) ?? null,
|
|
});
|
|
}
|
|
}
|