Skip to content

Commit

Permalink
fix: enable status updates
Browse files Browse the repository at this point in the history
  • Loading branch information
schweinryder committed Feb 28, 2024
1 parent 928bb09 commit 44063cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/elastic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,11 @@ class Elastic {
}
}

/*async updateDocumentState(url: string, newState: string) {
async updateDocumentState(documentId: string, newState: string) {
try {
await this.client.update({
index: this.indexName,
id: documentId,
body: {
doc: {
state: newState
Expand All @@ -133,7 +134,7 @@ class Elastic {
} catch (error) {
console.error(`Error updating document state for Document ID ${documentId}:`, error);
}
}*/
}
}

export default new Elastic(config)
13 changes: 12 additions & 1 deletion src/workers/discordReview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ const worker = new Worker(
job.updateProgress(40)

discord.client.on('interactionCreate', async (interaction) => {
let reportState = ''
if (interaction.isButton() && interaction.customId === 'approve') {
reportState = 'approved'
interaction.update({
content: 'Approved!',
embeds: [],
components: [],
})
} else if (interaction.isButton() && interaction.customId === 'edit') {
reportState = 'edited'
const input = new TextInputBuilder()
.setCustomId('editInput')
.setLabel(`Granska utsläppsdata`)
Expand Down Expand Up @@ -115,14 +118,22 @@ const worker = new Worker(
}
} else if (interaction.isButton() && interaction.customId === 'reject') {
// todo diskutera vad vill vill händer. ska man ens få rejecta?
reportState = 'rejected'
interaction.update({
content: 'Rejected!',
embeds: [],
components: [],
})
}
})

if (reportState !== '') {
try {
await elastic.updateDocumentState(job.data.documentId, reportState)
} catch (error) {
job.log(`Error updating document state: ${error.message}`)
}
}
})
job.updateProgress(100)
},
{
Expand Down

0 comments on commit 44063cd

Please sign in to comment.