Skip to content

Commit

Permalink
Adds quest input validation
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpolman committed Aug 8, 2024
1 parent cad1887 commit 9281c67
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const controller = async (req: Request, res: Response) => {
const variant = req.params.variant as unknown as QuestVariant;
const questId = req.params.questId as string;

let quest = await QuestService.findById(variant, questId);
quest = await QuestService.update(quest, req.body, req.file);
const quest = await QuestService.findById(variant, questId);
const result = await QuestService.update(quest, req.body, req.file);

res.json(quest);
res.json(result);
};

export { controller, validation };
2 changes: 1 addition & 1 deletion apps/api/src/app/models/Quest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const questSchema = {
description: String,
image: String,
index: Number,
expiryDate: Date,
expiryDate: { type: Date, default: '', nullable: false },
infoLinks: [{ label: String, url: String }],
locks: { type: [{ questId: String, variant: Number }], default: [] },
isPublished: { type: Boolean, default: false },
Expand Down
8 changes: 8 additions & 0 deletions apps/api/src/app/util/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ export const defaults = {
.optional()
.isBoolean()
.customSanitizer((value) => JSON.parse(value)),
body('isReviewEnabled')
.optional()
.isBoolean()
.customSanitizer((value) => JSON.parse(value)),
body('isIPLimitEnabled')
.optional()
.isBoolean()
.customSanitizer((value) => JSON.parse(value)),
check('file')
.optional()
.custom((value, { req }) => {
Expand Down

0 comments on commit 9281c67

Please sign in to comment.