Encountering an error message that says, "Cannot read property 'indexOf' of undefined". Despite receiving the journey passport ID in the view, it seems like the journey passport ID is not being passed to the function. Additionally, console.logs are not showing up for some unknown reason. Any assistance on this issue would be highly appreciated!
Shown below is my HTML code calling the 'userLikes' filter:
(Full code available at: https://github.com/cdtdesign/TCP-Express/blob/master/views/blog.html)
<a class="like-button" title="Like">
<i class="fa fa-heart {{journey.passport_id | userLikes}}"></i>
</a>
{% if user.passport_id == journey.passport_id %}
<a href="#modal-text/{{ String(journey._id) }}#update" title="Edit">
<i class="fa fa-pencil journeyEditButton"></i>
</a>
<a title="Delete">
<i class="fa fa-close journeyDeleteButton" style="font-size:2.875rem;" data-journey-id="{{ String(journey._id) }}"></i>
</a>
{% endif %}
The problematic JavaScript section is as follows:
(Full code link: https://github.com/cdtdesign/TCP-Express/blob/master/routes/blog.js)
if (req.user) {
swig.setFilter('userLikes', function(journeyPassportID) {
if (req.user.journeys_liked.indexOf(journeyPassportID) != -1) {
return 'liked';
}
});
In addition, here's the relevant code snippet from my Journey model where the passport_id is defined:
var journeySchema = new Schema({
uuid: {
type: String,
default: uuid.v4()
},
travel_token: {
type: String,
default: randomstring.generate()
},
passport_id: String,
traveler_name: String,
title: String,
date: Date,
body: String,
description_filename: String,
header_image_filename: String,
users_who_like: Array,
tags: String,
shortlink: String,
deleted_at: String,
created_at: {
type: Date,
default: Date.now
},
updated_at: {
type: Date,
default: Date.now
}
});