Repository: FlowiseAI/Flowise
File: packages/server/src/index.ts (TypeScript)

Code before:
        endDate?: string
    ): Promise<ChatMessage[]> {
        let fromDate
        if (startDate) fromDate = new Date(startDate)

        let toDate
        if (endDate) toDate = new Date(endDate)

        return await this.AppDataSource.getRepository(ChatMessage).find({
            where: {
                chatflowid,
                chatType,
                chatId,
                memoryType: memoryType ?? undefined,
                sessionId: sessionId ?? undefined,
                createdDate: toDate && fromDate ? Between(fromDate, toDate) : undefined
            },
            order: {
                createdDate: sortOrder === 'DESC' ? 'DESC' : 'ASC'
            }
        })
    }

    /**
     * Method that add chat messages.
     * @param {Partial<IChatMessage>} chatMessage
     */
    async addChatMessage(chatMessage: Partial<IChatMessage>): Promise<ChatMessage> {
        const newChatMessage = new ChatMessage()
        Object.assign(newChatMessage, chatMessage)

        const chatmessage = this.AppDataSource.getRepository(ChatMessage).create(newChatMessage)
        return await this.AppDataSource.getRepository(ChatMessage).save(chatmessage)
    }

    async upsertVector(req: Request, res: Response, isInternal: boolean = false) {
        try {
            const chatflowid = req.params.id
            let incomingInput: IncomingInput = req.body

            const chatflow = await this.AppDataSource.getRepository(ChatFlow).findOneBy({
                id: chatflowid
            })
            if (!chatflow) return res.status(404).send(`Chatflow ${chatflowid} not found`)

            if (!isInternal) {
                const isKeyValidated = await this.validateKey(req, chatflow)
                if (!isKeyValidated) return res.status(401).send('Unauthorized')
            }

            const files = (req.files as any[]) || []

Review comment (suggestion):
couldn't remember why we have the `isNull()` in the first place, but would you be able to check from the View Message dialog on UI, that it still works as expected

Code after:
        sessionId?: string,
        startDate?: string,
        endDate?: string,
        messageId?: string
    ): Promise<ChatMessage[]> {
        const setDateToStartOrEndOfDay = (dateTimeStr: string, setHours: 'start' | 'end') => {
            const date = new Date(dateTimeStr)
            if (isNaN(date.getTime())) {
                return undefined
            }
            setHours === 'start' ? date.setHours(0, 0, 0, 0) : date.setHours(23, 59, 59, 999)
            return date
        }

        let fromDate
        if (startDate) fromDate = setDateToStartOrEndOfDay(startDate, 'start')

        let toDate
        if (endDate) toDate = setDateToStartOrEndOfDay(endDate, 'end')

        return await this.AppDataSource.getRepository(ChatMessage).find({
            where: {
                chatflowid,
                chatType,
                chatId,
                memoryType: memoryType ?? undefined,
                sessionId: sessionId ?? undefined,
                ...(fromDate && { createdDate: MoreThanOrEqual(fromDate) }),
                ...(toDate && { createdDate: LessThanOrEqual(toDate) }),
                id: messageId ?? undefined
            },
            order: {
                createdDate: sortOrder === 'DESC' ? 'DESC' : 'ASC'
            }
        })
    }

    /**
     * Method that add chat messages.
     * @param {Partial<IChatMessage>} chatMessage
     */
    async addChatMessage(chatMessage: Partial<IChatMessage>): Promise<ChatMessage> {
        const newChatMessage = new ChatMessage()
        Object.assign(newChatMessage, chatMessage)

        const chatmessage = this.AppDataSource.getRepository(ChatMessage).create(newChatMessage)
        return await this.AppDataSource.getRepository(ChatMessage).save(chatmessage)
    }

    async upsertVector(req: Request, res: Response, isInternal: boolean = false) {
        try {