mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-24 23:19:39 -05:00
fix gear script
This commit is contained in:
parent
38fff6234b
commit
900e07a546
|
|
@ -14,6 +14,7 @@
|
|||
"mongo": "ts-node prisma/scripts/dataFromMongo.ts",
|
||||
"top500": "ts-node prisma/scripts/top500jsons.ts",
|
||||
"league": "ts-node prisma/scripts/leagueJsons.ts",
|
||||
"fixgear": "ts-node prisma/scripts/fixGear.ts",
|
||||
"prettier": "prettier --write .",
|
||||
"e2e": "cypress open",
|
||||
"extract": "lingui extract",
|
||||
|
|
|
|||
63
prisma/scripts/fixGear.ts
Normal file
63
prisma/scripts/fixGear.ts
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import prisma from "../client";
|
||||
|
||||
async function main() {
|
||||
const builds = await prisma.build.findMany({});
|
||||
|
||||
const buildsToUpdate: {
|
||||
id: number;
|
||||
headGear: string | null;
|
||||
clothingGear: string | null;
|
||||
shoesGear: string | null;
|
||||
}[] = [];
|
||||
|
||||
builds.forEach((build) => {
|
||||
const trimmedHead =
|
||||
typeof build.headGear === "string"
|
||||
? build.headGear.trim()
|
||||
: build.headGear;
|
||||
const trimmedClothing =
|
||||
typeof build.clothingGear === "string"
|
||||
? build.clothingGear.trim()
|
||||
: build.clothingGear;
|
||||
const trimmedShoes =
|
||||
typeof build.shoesGear === "string"
|
||||
? build.shoesGear.trim()
|
||||
: build.shoesGear;
|
||||
|
||||
if (
|
||||
trimmedHead === build.headGear &&
|
||||
trimmedClothing === build.clothingGear &&
|
||||
trimmedShoes === build.shoesGear
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
buildsToUpdate.push({
|
||||
id: build.id,
|
||||
headGear: trimmedHead,
|
||||
clothingGear: trimmedClothing,
|
||||
shoesGear: trimmedShoes,
|
||||
});
|
||||
});
|
||||
|
||||
console.log(buildsToUpdate[0]);
|
||||
|
||||
await Promise.all(
|
||||
buildsToUpdate.map((build) =>
|
||||
prisma.build.update({
|
||||
where: { id: build.id },
|
||||
data: {
|
||||
headGear: build.headGear,
|
||||
clothingGear: build.clothingGear,
|
||||
shoesGear: build.shoesGear,
|
||||
},
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => console.error(e))
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user