Connect public lead forms to CRM Leads on submit.
This commit is contained in:
@@ -5,11 +5,12 @@ import {
|
||||
NotFoundException,
|
||||
Param,
|
||||
Post,
|
||||
Req,
|
||||
Res,
|
||||
StreamableFile,
|
||||
} from '@nestjs/common';
|
||||
import type { Response } from 'express';
|
||||
import { SubmitLeadFormDto } from './dto';
|
||||
import type { Request, Response } from 'express';
|
||||
import { LeadFormPublicEventDto, SubmitLeadFormDto } from './dto';
|
||||
import { LeadFormsService } from './lead-forms.service';
|
||||
import { LocalFileStorage } from '../storage/local-file.storage';
|
||||
|
||||
@@ -36,8 +37,32 @@ export class PublicLeadFormsController {
|
||||
return new StreamableFile(this.files.openReadStream(row.coverStorageKey));
|
||||
}
|
||||
|
||||
@Post(':token/event')
|
||||
event(@Param('token') token: string, @Body() dto: LeadFormPublicEventDto) {
|
||||
return this.leadFormsService.recordPublicEvent(token, dto.type);
|
||||
}
|
||||
|
||||
@Post(':token/submit')
|
||||
submit(@Param('token') token: string, @Body() dto: SubmitLeadFormDto) {
|
||||
return this.leadFormsService.submit(token, dto.values ?? {});
|
||||
submit(
|
||||
@Param('token') token: string,
|
||||
@Body() dto: SubmitLeadFormDto,
|
||||
@Req() req: Request,
|
||||
) {
|
||||
const forwarded = req.headers['x-forwarded-for'];
|
||||
const ip =
|
||||
(typeof forwarded === 'string' ? forwarded.split(',')[0]?.trim() : null) ||
|
||||
req.ip ||
|
||||
null;
|
||||
return this.leadFormsService.submit(
|
||||
token,
|
||||
{
|
||||
values: dto.values ?? {},
|
||||
utm: dto.utm,
|
||||
pageUrl: dto.pageUrl,
|
||||
referrer: dto.referrer,
|
||||
website: dto.website,
|
||||
},
|
||||
ip,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user