Skip to content

Commit

Permalink
Make it all async
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic-R committed Jul 25, 2024
1 parent 7d9c74d commit 0abcd0c
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions commands/clear_database.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,40 @@ module.exports = {
ephemeral: true,
});
}
prisma.build.findMany().then((builds) => {
if (builds.length === 0) {
return interaction.reply({
content: "The database is already empty.",
ephemeral: true,
});
}
if (interaction.options.getBoolean("backup")) {
const backup = JSON.stringify(builds);
const fs = require("fs");
fs.writeFileSync("backup.json", backup);
interaction.user.send({
content: "Here is your backup.",
files: ["backup.json"],
});
fs.rmSync("backup.json");
}
});
prisma.build.deleteMany().then(() => {
prisma.$executeRaw`ALTER SEQUENCE "Build_id_seq" RESTART WITH 1;`;
prisma.user.updateMany({
data: {
points: 0,
},
}).then(() => {
interaction.reply({
content: "Done.",
ephemeral: true,
});

const builds = await prisma.build.findMany();

if (builds.length === 0) {
return interaction.reply({
content: "The database is already empty.",
ephemeral: true,
});
}

const reason = interaction.getString("reason");
const backup = interaction.getBoolean("backup");

if (backup) {
const backup = JSON.stringify(builds);
const fs = require("fs");
fs.writeFileSync("backup.json", backup);
interaction.user.send({
content: "Here is your backup.",
files: ["backup.json"],
});
fs.rmSync("backup.json");
}

await prisma.build.deleteMany();
await prisma.$executeRaw`ALTER SEQUENCE "Build_id_seq" RESTART WITH 1;`;
await prisma.user.updateMany({
data: {
points: 0,
},
});

interaction.reply({
content: "Done. Reason: " + reason
});
}
};

0 comments on commit 0abcd0c

Please sign in to comment.