Skip to main content

Endpoints for working with gallery

VIDEO RESULT after completing all actions on the "SingleCollection" page.

image.png


To start creating this page, let's begin by creating the endpoint.

Need to add an endpoint that will return all objects from the table where the property "deleted" is false. Additionally, you want the data to be sorted in a way that the newer data is returned first, followed by older data.

image.png

  • function
msg.payload = {
    deleted: false
}

msg.sort = { _id: -1 }
return msg;
  • mongo in

image.png

  • function

In this function, you need to calculate how many hours and minutes are remaining until the link to the image expires. The expiration period is approximately 1 hour.

const result = [];
for (const image of msg.payload) {

    const timeDiff = new Date(image.expireTime).getTime() - new Date().getTime();
    const hours = Math.floor(timeDiff / (1000 * 60 * 60));
    const minutes = Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60));
    const timeLeft = `${hours} h ${minutes} min`;
    image.expireIn = timeDiff > 0 ? timeLeft : 0;
    result.push(image);
}

msg.payload = result;

return msg;
  • http response