Skip to content

Commit

Permalink
send discord logs when someone is deleting something in scert workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
deepansh96 committed Dec 3, 2024
1 parent 046cee3 commit f385bfd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/components/Editor/ItemEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,15 @@ import QuestionTypeDropdown from "@/components/Editor/QuestionTypeDropdown.vue";
import InputText from "@/components/UI/Text/InputText.vue";
import TimeInput from "@/components/UI/Text/TimeInput.vue";
import Textarea from "@/components/UI/Text/Textarea.vue";
import GenericUtilities from "@/services/Functional/Utilities/Generic.js";
import GenericUtilities, { sendLogToDiscord } from "@/services/Functional/Utilities/Generic.js";
import ItemFunctionalService from "@/services/Functional/Item.js";
import {
convertSecondsToISOTime,
convertISOTimeToSeconds,
} from "@/services/Functional/Utilities/Generic.js";
import { useToast } from "vue-toastification";
import MathFieldPopup from "@/components/Editor/MathFieldPopup.vue";
import { mapState} from "vuex";
export default {
name: "ItemEditor",
Expand Down Expand Up @@ -571,6 +572,10 @@ export default {
deleteOption(optionIndex) {
// emit a request for option deletion, pass the optionIndex
// as a payload -- will be listened to by Editor.vue
sendLogToDiscord(
`${this.userId} - is deleting the option ${optionIndex} of item ${this.itemDetailList[this.localSelectedItemIndex].id}`,
this.activeWorkspace
);
this.$emit("delete-option", optionIndex);
},
getCorrectOptionTooltip(optionIndex) {
Expand Down Expand Up @@ -603,6 +608,10 @@ export default {
* emits a request to delete the selected item
*/
deleteSelectedItem() {
sendLogToDiscord(
`${this.userId} - is deleting the item ${this.itemDetailList[this.localSelectedItemIndex].id}`,
this.activeWorkspace
);
this.$emit("delete-selected-item");
},
/**
Expand Down Expand Up @@ -647,6 +656,7 @@ export default {
},
computed: {
...mapState("auth", ["activeWorkspace", "userId"]),
textToSendToMathField() {
// returns the text to be sent to the math field
if (this.mathEditorTarget == "questionText") return this.questionText;
Expand Down
23 changes: 23 additions & 0 deletions src/services/Functional/Utilities/Generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,26 @@ export async function getVideoDuration(videoId) {
ErrorHandling.handleAPIErrors(error);
}
}

export function sendLogToDiscord(message, workspaceId) {
console.log(workspaceId, message);
if (workspaceId !== "scertH") return;

const webhookPayload = {
webhook_url: "https://discord.com/api/webhooks/1308380999587205142/Hhl6KeKDisGiV39DL4J0wNpoy46fuy6OUKFIpkfdxjKh0u8NVhEF6sktMuLHovYN8jGG",
message: message
};

return axios.post(
"https://eoseqzluy7too2a6xhu4oe6yki0xnetl.lambda-url.ap-south-1.on.aws/",
webhookPayload
)
.then(() => {
console.log("Successfully sent logs to Discord");
return { success: true, error: null };
})
.catch((error) => {
console.error("Failed to send to Discord:", error);
return { success: false, error: `Failed to send to Discord: ${error.message}` };
});
}

0 comments on commit f385bfd

Please sign in to comment.