Skip to content

Commit

Permalink
fix : params in case of already params in original url
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazi-pikachu committed Sep 4, 2023
1 parent d0961da commit 6976d1b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
7 changes: 4 additions & 3 deletions apps/api/src/app/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ export class AppController {
let reRouteURL: string = response?.reRouteurl;
const redirectedLink: LinkModel = response?.redirectedLink;
// console.log(Object.keys(queryParams));
const params = redirectedLink?.params;
// const params = redirectedLink?.params;
const isParams = new URL(reRouteURL).searchParams.toString() !== "";
if (queryParams && Object.keys(queryParams).length) {
if (params == null) {
if (!isParams) {
reRouteURL += "?";
} else {
reRouteURL += "&";
Expand All @@ -118,7 +119,7 @@ export class AppController {
});
reRouteURL += qparams.join("&") || "";
}
// console.log("ReRouted URL is:",{reRouteURL});
console.log("ReRouted URL is:",{reRouteURL});
if (reRouteURL !== '') {
console.log("Redirected URL is ",{reRouteURL});
this.clickServiceClient
Expand Down
46 changes: 25 additions & 21 deletions apps/api/src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,18 @@ export class AppService {
return { reRouteurl : '' , redirectedLink:null };
// return "";
}
return { reRouteurl : url , redirectedLink:link };

if(params == null){
return { reRouteurl : url , redirectedLink:link };
// return url;
}else {
Object.keys(params).forEach(function(d) {
ret.push(encodeURIComponent(d) + '=' + encodeURIComponent(params[d]));
})
return { reRouteurl : `${url}?${ret.join('&')}` || '' , redirectedLink:link };
// return `${url}?${ret.join('&')}` || '';
}
// if(params == null){
// return { reRouteurl : url , redirectedLink:link };
// // return url;
// }else {
// Object.keys(params).forEach(function(d) {
// ret.push(encodeURIComponent(d) + '=' + encodeURIComponent(params[d]));
// })
// return { reRouteurl : `${url}?${ret.join('&')}` || '' , redirectedLink:link };
// // return `${url}?${ret.join('&')}` || '';
// }
})
.catch(err => {
this.telemetryService.sendEvent(this.configService.get<string>('POSTHOG_DISTINCT_KEY'), "Exception in fetching data from redis falling back to DB", {error: err.message})
Expand Down Expand Up @@ -286,17 +287,20 @@ export class AppService {
}

this.redisUtils.setKey(response[0]);

if(params == null){
return { reRouteurl : url , redirectedLink: null };
// return url;
}else {
Object.keys(params).forEach(function(d) {
ret.push(encodeURIComponent(d) + '=' + encodeURIComponent(params[d]));
})
return { reRouteurl : `${url}?${ret.join('&')}` || '' , redirectedLink:response[0] };
// return `${url}?${ret.join('&')}` || '';
}

return { reRouteurl : url , redirectedLink: response[0] };

// if(params == null){
// return { reRouteurl : url , redirectedLink: null };
// // return url;
// }
// else {
// Object.keys(params).forEach(function(d) {
// ret.push(encodeURIComponent(d) + '=' + encodeURIComponent(params[d]));
// })
// return { reRouteurl : `${url}?${ret.join('&')}` || '' , redirectedLink:response[0] };
// // return `${url}?${ret.join('&')}` || '';
// }
})
.catch(err => {
this.telemetryService.sendEvent(this.configService.get<string>('POSTHOG_DISTINCT_KEY'), "Exception in getLinkFromHashIdOrCustomHashId query", {error: err.message})
Expand Down

0 comments on commit 6976d1b

Please sign in to comment.