2026-09-06 13:50:05 +03:30
|
|
|
import {
|
|
|
|
|
Body,
|
|
|
|
|
Controller,
|
|
|
|
|
Get,
|
|
|
|
|
NotFoundException,
|
|
|
|
|
Param,
|
|
|
|
|
Post,
|
|
|
|
|
Res,
|
|
|
|
|
StreamableFile,
|
|
|
|
|
} from '@nestjs/common';
|
|
|
|
|
import type { Response } from 'express';
|
2026-08-29 21:06:30 +03:30
|
|
|
import { SubmitLeadFormDto } from './dto';
|
|
|
|
|
import { LeadFormsService } from './lead-forms.service';
|
2026-09-06 13:50:05 +03:30
|
|
|
import { LocalFileStorage } from '../storage/local-file.storage';
|
2026-08-29 21:06:30 +03:30
|
|
|
|
|
|
|
|
@Controller('public/forms')
|
|
|
|
|
export class PublicLeadFormsController {
|
2026-09-06 13:50:05 +03:30
|
|
|
constructor(
|
|
|
|
|
private readonly leadFormsService: LeadFormsService,
|
|
|
|
|
private readonly files: LocalFileStorage,
|
|
|
|
|
) {}
|
2026-08-29 21:06:30 +03:30
|
|
|
|
|
|
|
|
@Get(':token')
|
|
|
|
|
get(@Param('token') token: string) {
|
|
|
|
|
return this.leadFormsService.getPublic(token);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-06 13:50:05 +03:30
|
|
|
@Get(':token/cover')
|
|
|
|
|
async cover(
|
|
|
|
|
@Param('token') token: string,
|
|
|
|
|
@Res({ passthrough: true }) res: Response,
|
|
|
|
|
) {
|
|
|
|
|
const row = await this.leadFormsService.getByToken(token);
|
|
|
|
|
if (!row?.coverStorageKey) throw new NotFoundException('کاور پیدا نشد');
|
|
|
|
|
res.set({ 'Content-Type': 'image/jpeg', 'Cache-Control': 'public, max-age=3600' });
|
|
|
|
|
return new StreamableFile(this.files.openReadStream(row.coverStorageKey));
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-29 21:06:30 +03:30
|
|
|
@Post(':token/submit')
|
|
|
|
|
submit(@Param('token') token: string, @Body() dto: SubmitLeadFormDto) {
|
|
|
|
|
return this.leadFormsService.submit(token, dto.values ?? {});
|
|
|
|
|
}
|
|
|
|
|
}
|