2022-10-11 17:32:28 +03:00
|
|
|
class AudienceFeedbackService {
|
2022-10-14 17:12:17 +03:00
|
|
|
/** @type URL */
|
|
|
|
#baseURL;
|
2022-10-19 14:21:43 +03:00
|
|
|
/** @type {Object} */
|
|
|
|
#urlService;
|
2022-10-14 17:12:17 +03:00
|
|
|
/**
|
|
|
|
* @param {object} deps
|
|
|
|
* @param {object} deps.config
|
|
|
|
* @param {URL} deps.config.baseURL
|
2022-10-19 14:21:43 +03:00
|
|
|
* @param {object} deps.urlService
|
2022-10-14 17:12:17 +03:00
|
|
|
*/
|
|
|
|
constructor(deps) {
|
|
|
|
this.#baseURL = deps.config.baseURL;
|
2022-10-19 14:21:43 +03:00
|
|
|
this.#urlService = deps.urlService;
|
2022-10-14 17:12:17 +03:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @param {string} uuid
|
|
|
|
* @param {string} postId
|
|
|
|
* @param {0 | 1} score
|
|
|
|
*/
|
|
|
|
buildLink(uuid, postId, score) {
|
2022-10-19 14:21:43 +03:00
|
|
|
let postUrl = this.#urlService.getUrlByResourceId(postId, {absolute: true});
|
|
|
|
|
|
|
|
if (postUrl.match(/\/404\//)) {
|
|
|
|
postUrl = this.#baseURL;
|
|
|
|
}
|
|
|
|
const url = new URL(postUrl);
|
2022-10-26 19:04:11 +03:00
|
|
|
url.hash = `#/feedback/${postId}/${score}/?uuid=${encodeURIComponent(uuid)}`;
|
2022-10-14 17:12:17 +03:00
|
|
|
return url;
|
2022-10-11 17:32:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = AudienceFeedbackService;
|