mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-30 15:17:43 -05:00
principal id script
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"lib": ["dom", "dom.iterable", "esnext", "ES2020"],
|
||||
"types": ["cypress"],
|
||||
"allowJs": false,
|
||||
"skipLibCheck": true,
|
||||
|
||||
Reference in New Issue
Block a user