Skip to content

Commit dbb3c50

Browse files
committed
core: domain_star: check existance
1 parent 442a000 commit dbb3c50

File tree

1 file changed

+7
-4
lines changed
  • packages/hydrooj/src/handler

1 file changed

+7
-4
lines changed

packages/hydrooj/src/handler/home.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,15 +517,18 @@ class HomeDomainHandler extends Handler {
517517
this.response.body = { ddocs, canManage, role };
518518
}
519519

520-
@param('id', Types.String)
520+
@param('id', Types.DomainId)
521521
@param('star', Types.Boolean)
522522
async postStar({ }, id: string, star = false) {
523-
if (star) await user.setById(this.user._id, { pinnedDomains: [...this.user.pinnedDomains, id] });
524-
else user.setById(this.user._id, { pinnedDomains: this.user.pinnedDomains.filter((i) => i !== id) });
523+
if (star) {
524+
const ddoc = await domain.get(id);
525+
if (!ddoc) throw new NotFoundError(id);
526+
await user.setById(this.user._id, { pinnedDomains: [...this.user.pinnedDomains, id] });
527+
} else user.setById(this.user._id, { pinnedDomains: this.user.pinnedDomains.filter((i) => i !== id) });
525528
this.back({ star });
526529
}
527530

528-
@param('id', Types.String)
531+
@param('id', Types.DomainId)
529532
async postLeave({ }, id: string) {
530533
if (id === 'system') throw new BadRequestError();
531534
const ddoc = await domain.get(id);

0 commit comments

Comments
 (0)