Cyrof / Tarot-website

Tarot-website is a modern web application for online tarot reading, built with Next.js, Tailwind CSS, and TypeScript. This project aims to provide an intuitive and engaging platform for tarot enthusiasts and readers.
2 stars 0 forks source link

TTL Not working #7

Closed Cyrof closed 2 months ago

Cyrof commented 2 months ago

Database Time-To-Live (TTL) Not working

The database TTL for documents is not working. Fix is required ASAP.

More Information Required

Cyrof commented 2 months ago

Found Issues

Date is generated here is a date object

        const roomSess : roomSession = {
            room_pin: pin,
            room_sess: sessionId,
            createdAt: new Date(),
        }

but when parse to the api to be handle to save to mongodb here

          const response = await fetch('/api/saveData', {
              method: 'POST',
              headers: { 'Content-Type': 'application/json' },
              body: JSON.stringify(roomSess),
          });

Because of JSON.stringify(roomSess), the data type of the createdAt value becomes a String instead of a Date. Therefore when api saves the data into mongodb, the value of createdAt is a String and thereafter is not recognised by the TTL.

Cyrof commented 2 months ago

Issue resolve in this commit ee2165fd4e06923152dbba431bb624aef7849897.

Added data validation to check for createdAt datatype

        if (typeof body.createdAt === "string"){
            body.createdAt = new Date(body.createdAt);
        }