Skip to content

Commit

Permalink
feat(api): add endpoint for weapon's costume
Browse files Browse the repository at this point in the history
  • Loading branch information
KeziahMoselle committed Dec 11, 2022
1 parent fa59e44 commit b112a2a
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions src/pages/api/weapon/costume/[id].ts
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,
})
}
}
}

0 comments on commit b112a2a

Please sign in to comment.