Skip to content

Commit

Permalink
feat(api): update debris to use the database instead of manual link
Browse files Browse the repository at this point in the history
  • Loading branch information
KeziahMoselle committed Jan 23, 2023
1 parent 3171484 commit b7b7466
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/pages/api/costume/debris/[id].ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
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

Expand All @@ -18,19 +12,16 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
})
}

const link = await prisma.nrg.costumes_link.findUnique({
where: {
costume_id: Number(id),
}
})

const debris = await prisma.dump.debris.findUnique({
const costume = await prisma.dump.costume.findUnique({
where: {
debris_id: link.debris_id,
costume_id: Number(id)
},
include: {
debris: true,
}
})

return res.status(200).json(debris)
return res.status(200).json(costume.debris)
} catch (error) {
console.error(error)
return res.status(500).json({
Expand Down

0 comments on commit b7b7466

Please sign in to comment.