Refactor unsubscribe URL generation in StatusPageSubscriberService

This commit is contained in:
Simon Larsen 2023-12-19 11:43:41 +00:00
parent 32e72a8817
commit 59ab24ba36
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
8 changed files with 13 additions and 48 deletions

View File

@ -189,12 +189,7 @@ export class Service extends DatabaseService<Model> {
.isPublicStatusPage
? 'true'
: 'false',
unsubscribeUrl: new URL(httpProtocol, host)
.addRoute(
'/api/status-page-subscriber/unsubscribe/' +
createdItem._id.toString()
)
.toString(),
unsubscribeUrl: this.getUnsubscribeLink(URL.fromString(statusPageURL), createdItem.id!).toString()
},
subject: 'You have been subscribed to ' + statusPageName,
},
@ -229,5 +224,10 @@ export class Service extends DatabaseService<Model> {
props: props,
});
}
public getUnsubscribeLink(statusPageUrl: URL, statusPageSubscriberId: ObjectID): URL {
return URL.fromString(statusPageUrl.toString()).addRoute('/update-subscription/'+statusPageSubscriberId.toString());
}
}
export default new Service();

View File

@ -132,12 +132,7 @@ RunCron(
continue;
}
const unsubscribeUrl: string = new URL(httpProtocol, host)
.addRoute(
'/api/status-page-subscriber/unsubscribe/' +
subscriber._id.toString()
)
.toString();
const unsubscribeUrl: string = StatusPageSubscriberService.getUnsubscribeLink(URL.fromString(statusPageURL), subscriber.id!).toString();;
if (subscriber.subscriberPhone) {
const sms: SMS = {

View File

@ -190,12 +190,7 @@ RunCron(
continue;
}
const unsubscribeUrl: string = new URL(httpProtocol, host)
.addRoute(
'/api/status-page-subscriber/unsubscribe/' +
subscriber._id.toString()
)
.toString();
const unsubscribeUrl: string = StatusPageSubscriberService.getUnsubscribeLink(URL.fromString(statusPageURL), subscriber.id!).toString();
if (subscriber.subscriberEmail) {
// send email here.

View File

@ -212,12 +212,7 @@ RunCron(
continue;
}
const unsubscribeUrl: string = new URL(httpProtocol, host)
.addRoute(
'/api/status-page-subscriber/unsubscribe/' +
subscriber._id.toString()
)
.toString();
const unsubscribeUrl: string = StatusPageSubscriberService.getUnsubscribeLink(URL.fromString(statusPageURL), subscriber.id!).toString();;
if (subscriber.subscriberPhone) {
const sms: SMS = {

View File

@ -220,12 +220,7 @@ RunCron(
continue;
}
const unsubscribeUrl: string = new URL(httpProtocol, host)
.addRoute(
'/api/status-page-subscriber/unsubscribe/' +
subscriber._id.toString()
)
.toString();
const unsubscribeUrl: string = StatusPageSubscriberService.getUnsubscribeLink(URL.fromString(statusPageURL), subscriber.id!).toString();;
if (subscriber.subscriberPhone) {
const sms: SMS = {

View File

@ -194,12 +194,7 @@ RunCron(
continue;
}
const unsubscribeUrl: string = new URL(httpProtocol, host)
.addRoute(
'/api/status-page-subscriber/unsubscribe/' +
subscriber._id.toString()
)
.toString();
const unsubscribeUrl: string = StatusPageSubscriberService.getUnsubscribeLink(URL.fromString(statusPageURL), subscriber.id!).toString();;
if (subscriber.subscriberPhone) {
const sms: SMS = {

View File

@ -206,12 +206,7 @@ RunCron(
continue;
}
const unsubscribeUrl: string = new URL(httpProtocol, host)
.addRoute(
'/api/status-page-subscriber/unsubscribe/' +
subscriber._id.toString()
)
.toString();
const unsubscribeUrl: string = StatusPageSubscriberService.getUnsubscribeLink(URL.fromString(statusPageURL), subscriber.id!).toString();;
if (subscriber.subscriberPhone) {
const sms: SMS = {

View File

@ -218,12 +218,7 @@ RunCron(
continue;
}
const unsubscribeUrl: string = new URL(httpProtocol, host)
.addRoute(
'/api/status-page-subscriber/unsubscribe/' +
subscriber._id.toString()
)
.toString();
const unsubscribeUrl: string = StatusPageSubscriberService.getUnsubscribeLink(URL.fromString(statusPageURL), subscriber.id!).toString();;
if (subscriber.subscriberPhone) {
const sms: SMS = {