Bug fixes for new database system

This commit is contained in:
DJj123dj
2024-11-25 19:24:48 +01:00
parent b22f7b2de7
commit 3e928ed06e
11 changed files with 161 additions and 180 deletions
+8 -6
View File
@@ -8,24 +8,26 @@ export const loadAllTickets = async () => {
const tickets = await ticketDatabase.getCategory("openticket:ticket")
if (!tickets) return
tickets.forEach((ticket) => {
for (const ticket of tickets){
console.log(ticket.value)
try {
openticket.tickets.add(loadTicket(ticket.value))
openticket.tickets.add(await loadTicket(ticket.value))
}catch (err){
process.emit("uncaughtException",err)
process.emit("uncaughtException",new api.ODSystemError("Failed to load ticket from database! => id: "+ticket.key+"\n ===> "+err))
}
})
}
}
export const loadTicket = (ticket:api.ODTicketJson) => {
const backupOption = optionDatabase.exists("openticket:used-option",ticket.option) ? api.ODTicketOption.fromJson(optionDatabase.get("openticket:used-option",ticket.option) as api.ODOptionJson) : null
export const loadTicket = async (ticket:api.ODTicketJson) => {
const backupOption = (await optionDatabase.exists("openticket:used-option",ticket.option)) ? api.ODTicketOption.fromJson(await optionDatabase.get("openticket:used-option",ticket.option) as api.ODOptionJson) : null
const configOption = openticket.options.get(ticket.option)
//check if option is of type "ticket"
if (configOption && !(configOption instanceof api.ODTicketOption)) throw new api.ODSystemError("Unable to load ticket because option is not of 'ticket' type!")
//manage backup option
if (configOption) optionDatabase.set("openticket:used-option",configOption.id.value,configOption.toJson(openticket.versions.get("openticket:version")))
if (configOption) await optionDatabase.set("openticket:used-option",configOption.id.value,configOption.toJson(openticket.versions.get("openticket:version")))
else if (backupOption) openticket.options.add(backupOption)
else throw new api.ODSystemError("Unable to use backup option! Normal option not found in config!")