2022-12-14 15:14:41 +00:00
|
|
|
import StatusPageSubscriber from 'Model/Models/StatusPageSubscriber';
|
|
|
|
import StatusPageSubscriberService, {
|
|
|
|
Service as StatusPageSubscriberServiceType,
|
|
|
|
} from '../Services/StatusPageSubscriberService';
|
|
|
|
import {
|
|
|
|
ExpressRequest,
|
|
|
|
ExpressResponse,
|
|
|
|
NextFunction,
|
|
|
|
} from '../Utils/Express';
|
|
|
|
import BaseAPI from './BaseAPI';
|
|
|
|
import Response from '../Utils/Response';
|
|
|
|
|
|
|
|
export default class StatusPageSubscriberAPI extends BaseAPI<
|
|
|
|
StatusPageSubscriber,
|
|
|
|
StatusPageSubscriberServiceType
|
|
|
|
> {
|
|
|
|
public constructor() {
|
|
|
|
super(StatusPageSubscriber, StatusPageSubscriberService);
|
|
|
|
|
|
|
|
this.router.get(
|
2022-12-20 07:13:36 +00:00
|
|
|
`${new this.entityType()
|
2022-12-15 06:37:15 +00:00
|
|
|
.getCrudApiPath()
|
|
|
|
?.toString()}/unsubscribe/:id`,
|
2022-12-14 15:14:41 +00:00
|
|
|
async (
|
|
|
|
req: ExpressRequest,
|
|
|
|
res: ExpressResponse,
|
|
|
|
next: NextFunction
|
|
|
|
) => {
|
|
|
|
try {
|
|
|
|
await this.service.updateOneBy({
|
|
|
|
query: {
|
|
|
|
_id: req.params['id'] as string,
|
|
|
|
},
|
|
|
|
data: {
|
|
|
|
isUnsubscribed: true,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
isRoot: true,
|
|
|
|
ignoreHooks: true,
|
2022-12-15 06:37:15 +00:00
|
|
|
},
|
2022-12-14 15:14:41 +00:00
|
|
|
});
|
|
|
|
|
2022-12-15 06:37:15 +00:00
|
|
|
return Response.sendHtmlResponse(
|
|
|
|
req,
|
|
|
|
res,
|
|
|
|
'<html><body><p> You have been unsubscribed.</p><body><html>'
|
|
|
|
);
|
2022-12-14 15:14:41 +00:00
|
|
|
} catch (err) {
|
|
|
|
next(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|