-
-
Save Kamilczak020/cdf3da925a955010b07ca690e3a7329a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function getMessagesQuery(roomId: number, userId: number, responseId: number, timestamp: moment.Moment) { | |
let query = 'SELECT * FROM messages'; | |
let queryObjects = []; | |
if (isNaN(roomId) && isNaN(userId) && isNaN(responseId) && !timestamp.isValid()) { | |
return query; | |
} | |
if (roomId !== undefined) { | |
queryObjects.push(`room_id = ${roomId}`); | |
} | |
if (userId !== undefined) { | |
queryObjects.push(`message_id = ${userId}`); | |
} | |
if (responseId !== undefined) { | |
queryObjects.push(`response_id = ${responseId}`); | |
} | |
if (timestamp.isValid()) { | |
queryObjects.push(`timestamp = '${timestamp.format('YYYY-MM-DD')}'`); | |
} | |
query += ' WHERE '; | |
query += queryObjects.join(' AND '); | |
return query; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment