Skip to content

Commit

Permalink
Merge pull request #51 from yuvrajsab/fix-click-count-with-query-params
Browse files Browse the repository at this point in the history
LGTM
  • Loading branch information
ChakshuGautam authored Apr 19, 2023
2 parents 0d0aacb + 8d22a21 commit 26eb452
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
25 changes: 13 additions & 12 deletions apps/api/src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ export class AppService {
client.get(key).then(async (value: string) => {
const updateClick = await this.prisma.link.updateMany({
where: {
OR: [
{
hashid: parseInt(key),
},
{
customHashId: key
}
],
},
OR: [
{
hashid: Number.isNaN(Number(key)) ? -1 : parseInt(key),
},
{
customHashId: key,
},
],
},
data: {
clicks: parseInt(value),
},
})
})
});
});
}
}

Expand Down Expand Up @@ -117,6 +117,7 @@ export class AppService {
select: {
url: true,
params: true,
hashid: true,
},
take: 1
})
Expand All @@ -125,7 +126,7 @@ export class AppService {
const params = response[0].params
const ret = [];

this.updateClicks(hashid);
this.updateClicks(response[0].hashid.toString());

if(params == null){
return url;
Expand Down
17 changes: 16 additions & 1 deletion apps/api/src/app/interceptors/addROToResponseInterceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { ConfigService } from '@nestjs/config';
import { map, Observable } from 'rxjs';
import { TelemetryService } from '../telemetry/telemetry.service';
import { URLSearchParams } from 'url';

// Nestjs Lifecyle - https://i.stack.imgur.com/2lFhd.jpg

Expand Down Expand Up @@ -35,7 +36,21 @@ import { TelemetryService } from '../telemetry/telemetry.service';
map((data) => {
let name: string;
console.log(`Execution Time: ${Date.now() - now}ms`)
this.telemetryService.sendEvent(this.configService.get<string>('POSTHOG_DISTINCT_KEY'), `${req.raw.url} Execution Time`, {routeName:name, executionTime: `${Date.now() - now}ms`})

const rawUrl = decodeURIComponent(req.raw.url);
const url = rawUrl.split("?")?.[0];
const urlSearchParams = new URLSearchParams(rawUrl.split("?")?.[1]);

this.telemetryService.sendEvent(
this.configService.get<string>("POSTHOG_DISTINCT_KEY"),
`${url} Execution Time`,
{
routeName: name,
executionTime: `${Date.now() - now}ms`,
url: req.url,
queryParams: Object.fromEntries(urlSearchParams.entries()),
}
);
return data;
}),
);
Expand Down

0 comments on commit 26eb452

Please sign in to comment.