Skip to content

Commit

Permalink
Feat: New endpoint for getting messageID
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose-Prince committed Nov 14, 2024
1 parent 9bb9ba9 commit b5463dc
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
23 changes: 23 additions & 0 deletions Scrum/Working/src/controller/ChatController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,26 @@ export async function setHiringState(chatID: string, state: boolean) {
throw error;
}
}

export async function getMessageID(chatID: string, time: string) {
const url = `https://${import.meta.env.VITE_API_HOSTI}/api/messageID/?chatID=${chatID}&time=${time}`;

try {
const response = await fetch(url, {
method: 'GET',
headers: {
'api-key': import.meta.env.VITE_API_KEY,
'Content-Type': 'application/json',
}
});

if (!response.ok) {
throw new Error('Failed to get message ID for the given chatID and time');
}

return await response.json();
} catch (error) {
console.error('Error fetching message ID:', error);
throw error;
}
}
19 changes: 19 additions & 0 deletions Scrum/Working/src/controller/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,4 +751,23 @@ export async function setHiringState(idChat, state) {
}
}

export async function getMessageID(chatID, time) {
try {
const query = {
text: `select id_mensaje from mensaje
where id_chat = $1
and to_char("time", 'HH24:MI') = $2`,
values: [chatID, time]
}

const result = await client.query(query);

return result.rows[0]

} catch (error) {
console.error('Error while setting the working state:', error)
throw error
}
}


18 changes: 17 additions & 1 deletion Scrum/Working/src/controller/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b5463dc

Please sign in to comment.