-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
KeziahMoselle
committed
Mar 5, 2023
1 parent
5dc819b
commit 2695d3e
Showing
4 changed files
with
203 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,119 +1,132 @@ | ||
import prisma from "@libs/prisma"; | ||
import alterWeaponToAddCostume from "@utils/alterWeaponToAddCostume"; | ||
import { env } from "env"; | ||
|
||
export async function getAllWeapons() { | ||
const weapons = await prisma.dump.weapon.findMany({ | ||
orderBy: { | ||
release_time: "desc", | ||
}, | ||
where: { | ||
evolution_order: 2, | ||
is_ex_weapon: false, | ||
}, | ||
distinct: "evolution_group_id", | ||
include: { | ||
weapon_stat: { | ||
orderBy: { | ||
level: "desc", | ||
}, | ||
take: 1, | ||
}, | ||
weapon_ability_link: { | ||
where: { | ||
ability_level: 15, | ||
}, | ||
orderBy: { | ||
slot_number: "asc", | ||
}, | ||
include: { | ||
weapon_ability: true, | ||
}, | ||
}, | ||
weapon_skill_link: { | ||
where: { | ||
skill_level: 15, | ||
}, | ||
orderBy: { | ||
slot_number: "asc", | ||
}, | ||
include: { | ||
weapon_skill: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
const weapons = await prisma.dump.weapon.findMany({ | ||
orderBy: { | ||
release_time: "desc", | ||
}, | ||
where: { | ||
evolution_order: 2, | ||
is_ex_weapon: false, | ||
}, | ||
distinct: "evolution_group_id", | ||
include: { | ||
weapon_stat: { | ||
orderBy: { | ||
level: "desc", | ||
}, | ||
take: 1, | ||
}, | ||
weapon_ability_link: { | ||
where: { | ||
OR: [ | ||
{ | ||
slot_number: 4, | ||
}, | ||
{ | ||
ability_level: 15, | ||
}, | ||
], | ||
}, | ||
orderBy: { | ||
slot_number: "asc", | ||
}, | ||
include: { | ||
weapon_ability: true, | ||
}, | ||
}, | ||
weapon_skill_link: { | ||
where: { | ||
skill_level: 15, | ||
}, | ||
orderBy: { | ||
slot_number: "asc", | ||
}, | ||
include: { | ||
weapon_skill: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const exWeapons = await prisma.dump.weapon.findMany({ | ||
orderBy: { | ||
release_time: "desc", | ||
}, | ||
where: { | ||
evolution_order: { | ||
gt: 10, | ||
}, | ||
is_ex_weapon: true, | ||
}, | ||
distinct: "evolution_group_id", | ||
include: { | ||
weapon_stat: { | ||
orderBy: { | ||
level: "desc", | ||
}, | ||
take: 1, | ||
}, | ||
weapon_ability_link: { | ||
where: { | ||
ability_level: 15, | ||
}, | ||
orderBy: { | ||
slot_number: "asc", | ||
}, | ||
include: { | ||
weapon_ability: true, | ||
}, | ||
}, | ||
weapon_skill_link: { | ||
where: { | ||
skill_level: 15, | ||
}, | ||
orderBy: { | ||
slot_number: "asc", | ||
}, | ||
include: { | ||
weapon_skill: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
const exWeapons = await prisma.dump.weapon.findMany({ | ||
orderBy: { | ||
release_time: "desc", | ||
}, | ||
where: { | ||
evolution_order: { | ||
gt: 10, | ||
}, | ||
is_ex_weapon: true, | ||
}, | ||
distinct: "evolution_group_id", | ||
include: { | ||
weapon_stat: { | ||
orderBy: { | ||
level: "desc", | ||
}, | ||
take: 1, | ||
}, | ||
weapon_ability_link: { | ||
where: { | ||
OR: [ | ||
{ | ||
slot_number: 4, | ||
}, | ||
{ | ||
ability_level: 15, | ||
}, | ||
], | ||
}, | ||
orderBy: { | ||
slot_number: "asc", | ||
}, | ||
include: { | ||
weapon_ability: true, | ||
}, | ||
}, | ||
weapon_skill_link: { | ||
where: { | ||
skill_level: 15, | ||
}, | ||
orderBy: { | ||
slot_number: "asc", | ||
}, | ||
include: { | ||
weapon_skill: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const allWeapons = [...weapons, ...exWeapons]; | ||
allWeapons.sort( | ||
// @ts-expect-error date sorting. | ||
(a, b) => new Date(b.release_time) - new Date(a.release_time) | ||
); | ||
const allWeapons = [...weapons, ...exWeapons]; | ||
allWeapons.sort( | ||
// @ts-expect-error date sorting. | ||
(a, b) => new Date(b.release_time) - new Date(a.release_time) | ||
); | ||
|
||
for (const weapon of allWeapons) { | ||
await alterWeaponToAddCostume(weapon) | ||
} | ||
for (const weapon of allWeapons) { | ||
await alterWeaponToAddCostume(weapon); | ||
} | ||
|
||
const abilitiesLookupData = await prisma.dump.weapon_ability.findMany({ | ||
orderBy: { | ||
name: "asc", | ||
}, | ||
select: { | ||
name: true, | ||
}, | ||
distinct: ["name"], | ||
}); | ||
const abilitiesLookupData = await prisma.dump.weapon_ability.findMany({ | ||
orderBy: { | ||
name: "asc", | ||
}, | ||
select: { | ||
name: true, | ||
}, | ||
distinct: ["name"], | ||
}); | ||
|
||
const abilitiesLookup = abilitiesLookupData.reduce((acc, current) => { | ||
acc[current.name] = current.name; | ||
return acc; | ||
}, {}); | ||
const abilitiesLookup = abilitiesLookupData.reduce((acc, current) => { | ||
acc[current.name] = current.name; | ||
return acc; | ||
}, {}); | ||
|
||
return { | ||
weapons: allWeapons, | ||
abilitiesLookup, | ||
} | ||
} | ||
return { | ||
weapons: allWeapons, | ||
abilitiesLookup, | ||
}; | ||
} |