-
-
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.
feat(api): add endpoint for weapon's costume
- Loading branch information
1 parent
fa59e44
commit b112a2a
Showing
1 changed file
with
86 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
import prisma from "@libs/prisma"; | ||
|
||
export interface CostumeLink { | ||
costume_id?: number; | ||
weapon_id?: number; | ||
debris_id?: number; | ||
} | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
const { id } = req.query | ||
|
||
if (req.method === 'GET') { | ||
try { | ||
if (!id) { | ||
return res.status(400).json({ | ||
error: 'Missing id.', | ||
}) | ||
} | ||
|
||
const link = await prisma.nrg.costumes_link.findFirst({ | ||
where: { | ||
weapon_id: Number(id), | ||
} | ||
}) | ||
|
||
const costume = await prisma.dump.costume.findUnique({ | ||
where: { | ||
costume_id: link.costume_id, | ||
}, | ||
include: { | ||
character: true, | ||
costume_ability_link: { | ||
where: { | ||
OR: [ | ||
{ | ||
ability_level: 4, | ||
AND: { | ||
ability_slot: { | ||
lte: 2 | ||
} | ||
} | ||
}, | ||
{ | ||
ability_level: 1, | ||
AND: { | ||
ability_slot: { | ||
equals: 3, | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
orderBy: { | ||
ability_slot: "asc", | ||
}, | ||
include: { | ||
costume_ability: true, | ||
}, | ||
}, | ||
costume_skill_link: { | ||
where: { | ||
skill_level: 15, | ||
}, | ||
include: { | ||
costume_skill: true, | ||
}, | ||
}, | ||
costume_stat: { | ||
take: 1, | ||
orderBy: { | ||
level: "desc", | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
return res.status(200).json(costume) | ||
} catch (error) { | ||
console.error(error) | ||
return res.status(500).json({ | ||
error: error.message, | ||
}) | ||
} | ||
} | ||
} |