Skip to content

Commit

Permalink
Merge pull request #8 from DIMO-Network/feature/DEVR-98-expoded-zapie…
Browse files Browse the repository at this point in the history
…r-webhook-url

[DEVR-98] Zapier Webhook URL exposed
  • Loading branch information
YokySantiago authored Aug 20, 2024
2 parents 9fc6bf1 + c03fe53 commit 2081e41
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ PGDATABASE=<YOUR_PG_DATABASE>
PGPASSWORD=<YOUR_PG_PASSWORD>
PGPORT=<YOUR_PG_PORT>

ZAPIER_LEAD_WEBHOOK_PATH=<ZAPIER LEAD GENERATION PATH, empty for dev environments>

NEXTAUTH_SECRET=<YOUR_NEXTAUTH_SECRET>
NEXTAUTH_URL=http://localhost:3000/
```
Expand Down
3 changes: 2 additions & 1 deletion src/app/api/me/complete/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { finishUpUserRegistration } from '@/controllers/company.controller';
import { User } from '@/models/user.model';
import { Attributes } from 'sequelize';
import { Token } from '@/types/auth';
import { fleetGeneration } from '@/controllers/lead.controller';

export async function PUT(request: NextRequest) {
const token = (await getToken({ req: request })) as Token;
Expand All @@ -23,7 +24,7 @@ export async function PUT(request: NextRequest) {
const company = await finishUpUserRegistration(userId, incomingCompany);
await associateTeam(user, company);
const userCompleteInfo = await getCompanyAndTeam(user);
// fleetGeneration(userCompleteInfo);
fleetGeneration(userCompleteInfo);

return Response.json(userCompleteInfo);
}
10 changes: 8 additions & 2 deletions src/controllers/lead.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ const zapierRestClient = axios.create({

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const fleetGeneration = (userData: any) => {
if (_.isEmpty(userData)) return null;
const { ZAPIER_LEAD_WEBHOOK_PATH: zapierPath = '' } = process.env;
if (_.isEmpty(userData) || _.isEmpty(zapierPath)) {
console.log(`Skipping Lead generation for user ${userData.id}`, {
user: userData,
});
return null;
}

// eslint-disable-next-line no-console
console.log(`Creating Lead for user ${userData.id}`, { user: userData });
return zapierRestClient
.post('hooks/catch/18609896/37bp6qs/', userData)
.post(zapierPath, userData)
.then(({ data }) =>
// eslint-disable-next-line no-console
console.log(`Lead information sent for user ${userData.id}`, {
Expand Down

0 comments on commit 2081e41

Please sign in to comment.