principal id script

This commit is contained in:
Kalle (Sendou)
2021-01-20 18:27:43 +02:00
parent 021f1dc7db
commit 6ec6bf9531
2 changed files with 20 additions and 13 deletions

View File

@@ -1,26 +1,33 @@
import prisma from "../client";
import principalToUnique from "./data/league/principal_to_unique.json";
import principalToUnique from "./data/league/uuid2pid.json";
const main = async () => {
const players = await prisma.player.findMany({});
console.log("amount", Object.entries(principalToUnique));
const players = await prisma.player.findMany({
where: { principalId: null },
});
const mapped = Object.entries(principalToUnique).reduce((acc, cur) => {
acc.set("" + cur[1], cur[0]);
acc.set("" + cur[0], cur[1]);
return acc;
}, new Map<string, string>());
let notFound = 0;
await Promise.allSettled(
players
.filter((player) => {
if (mapped.get(player.switchAccountId)) return true;
players.forEach((player) => {
const found = mapped.get(player.switchAccountId);
throw Error(player.switchAccountId);
})
.map((player) =>
prisma.player.update({
where: { switchAccountId: player.switchAccountId },
data: { principalId: mapped.get(player.switchAccountId) },
})
)
);
if (!found) notFound++;
});
console.log("notFound", notFound);
console.log("all done");
};
main()

View File

@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"lib": ["dom", "dom.iterable", "esnext", "ES2020"],
"types": ["cypress"],
"allowJs": false,
"skipLibCheck": true,