Skip to content

Commit

Permalink
Fixed export
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Groß <mail@gross-johannes.de>
  • Loading branch information
jo-gross committed Nov 15, 2023
1 parent c8a1dd8 commit d0d7bc3
Showing 1 changed file with 58 additions and 11 deletions.
69 changes: 58 additions & 11 deletions pages/api/workspaces/[workspaceId]/admin/backups/export.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,66 @@ import prisma from '../../../../../../lib/prisma';
import { BackupStructure } from './backupStructure';

export default async function handle(req: NextApiRequest, res: NextApiResponse) {
const workspaceId = req.query.workspaceId as string | undefined;

if (req.method === 'GET') {
const cocktailRecipes = await prisma.cocktailRecipe.findMany({ where: { workspaceId } });
const cocktailRecipeSteps = await prisma.cocktailRecipeStep.findMany({
where: {
cocktailRecipeId: {
in: cocktailRecipes.map((recipe) => recipe.id),
},
},
});

const cards = await prisma.cocktailCard.findMany({ where: { workspaceId } });
const cardGroups = await prisma.cocktailCardGroup.findMany({
where: {
cocktailCardId: {
in: cards.map((card) => card.id),
},
},
});

const calculations = await prisma.cocktailCalculation.findMany({ where: { workspaceId } });

const backup: BackupStructure = {
garnish: await prisma.garnish.findMany(),
ingredient: await prisma.ingredient.findMany(),
glass: await prisma.glass.findMany(),
cocktailRecipe: await prisma.cocktailRecipe.findMany(),
cocktailRecipeStep: await prisma.cocktailRecipeStep.findMany(),
cocktailRecipeGarnish: await prisma.cocktailRecipeGarnish.findMany(),
cocktailRecipeIngredient: await prisma.cocktailRecipeIngredient.findMany(),
cocktailCard: await prisma.cocktailCard.findMany(),
cocktailCardGroup: await prisma.cocktailCardGroup.findMany(),
cocktailCardGroupItem: await prisma.cocktailCardGroupItem.findMany(),
calculation: await prisma.cocktailCalculation.findMany(),
garnish: await prisma.garnish.findMany({ where: { workspaceId } }),
ingredient: await prisma.ingredient.findMany({ where: { workspaceId } }),
glass: await prisma.glass.findMany({ where: { workspaceId } }),
cocktailRecipe: cocktailRecipes,
cocktailRecipeStep: cocktailRecipeSteps,
cocktailRecipeGarnish: await prisma.cocktailRecipeGarnish.findMany({
where: {
cocktailRecipeId: {
in: cocktailRecipes.map((recipe) => recipe.id),
},
},
}),
cocktailRecipeIngredient: await prisma.cocktailRecipeIngredient.findMany({
where: {
cocktailRecipeStepId: {
in: cocktailRecipeSteps.map((step) => step.id),
},
},
}),
cocktailCard: cards,
cocktailCardGroup: cardGroups,
cocktailCardGroupItem: await prisma.cocktailCardGroupItem.findMany({
where: {
cocktailCardGroupId: {
in: cardGroups.map((group) => group.id),
},
},
}),
calculation: calculations,
calculationItems: await prisma.cocktailCalculationItems.findMany({
where: {
calculationId: {
in: calculations.map((calculation) => calculation.id),
},
},
}),
};

return res.json(backup);
Expand Down

0 comments on commit d0d7bc3

Please sign in to comment.