Skip to content

Commit

Permalink
Merge pull request #580 from hpi-dhc/issue/579-incorrect-backup-recov…
Browse files Browse the repository at this point in the history
…ery-of-version-history

Incorrect backup recovery of version history
  • Loading branch information
jannis-baum authored Apr 4, 2023
2 parents a882bef + 7f83b33 commit 6a07c0f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions anni/src/pages/api/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const api: NextApiHandler = async (req, res) =>
return { successStatus: 200, data };
},
POST: async () => {
const data: Record<string, object> = req.body.data;

await dbConnect();

await Promise.all(
Expand All @@ -35,10 +37,11 @@ const api: NextApiHandler = async (req, res) =>
),
);

const data: Record<string, object> = req.body.data;
await Promise.all(
Object.entries(data).map(([name, docs]) =>
mongoose.models[name].insertMany(docs),
mongoose.models[name].create(docs, {
validateBeforeSave: false,
}),
),
);
return { successStatus: 201 };
Expand Down

0 comments on commit 6a07c0f

Please sign in to comment.