Skip to content

Commit

Permalink
Create admin operation to fix improperly escaped ratings (#122)
Browse files Browse the repository at this point in the history
* Create admin operation to fix improperly escaped ratings
  • Loading branch information
AddisonTustin authored Apr 28, 2024
1 parent 3c7ac1e commit e49f954
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/backend/src/routers/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ const changeNameParser = z.object({
lastName: z.string(),
});

const fixEscapedCharsParser = z.object({
professors: z
.array(z.string().uuid())
.min(1)
.max(250, "Separate your request into batches of 250 professors."),
});

export const adminRouter = t.router({
removeRating: protectedProcedure
.input(z.object({ professorId: z.string(), ratingId: z.string() }))
Expand Down Expand Up @@ -103,4 +110,22 @@ export const adminRouter = t.router({
await ctx.env.kvDao.removeRating(report.professorId, report.ratingId);
await ctx.env.kvDao.removeReport(input);
}),
fixEscapedChars: protectedProcedure
.input(fixEscapedCharsParser)
.mutation(async ({ ctx, input }) => {
for (const profId of input.professors) {
// eslint-disable-next-line no-await-in-loop
const professor = await ctx.env.kvDao.getProfessor(profId);
for (const [course, ratings] of Object.entries(professor.reviews)) {
professor.reviews[course] = ratings.map((rating) => {
// eslint-disable-next-line
rating.rating = rating.rating.replaceAll("\\'", "'").replaceAll('\\"', '"');
return rating;
});
}

// eslint-disable-next-line no-await-in-loop
await ctx.env.kvDao.putProfessor(professor, true);
}
}),
});

0 comments on commit e49f954

Please sign in to comment.