| 550 | @param('avatar', Types.Content, true) |
| 551 | // eslint-disable-next-line ts/no-shadow |
| 552 | async post(_: string, id: string, name: string, bulletin: string, avatar: string) { |
| 553 | const doc = await domain.get(id); |
| 554 | if (doc) throw new DomainAlreadyExistsError(id); |
| 555 | avatar ||= this.user.avatar || `gravatar:${this.user.mail}`; |
| 556 | const domainId = await domain.add(id, this.user._id, name, bulletin); |
| 557 | // When this domain is deleted but previously added to user's list we shouldn't push it again |
| 558 | const push = !this.user.pinnedDomains?.includes(domainId); |
| 559 | await Promise.all([ |
| 560 | domain.edit(domainId, { avatar }), |
| 561 | domain.setUserRole(domainId, this.user._id, 'root'), |
| 562 | push |
| 563 | ? user.setById(this.user._id, undefined, undefined, { pinnedDomains: domainId }) |
| 564 | : Promise.resolve(), |
| 565 | ]); |
| 566 | this.response.redirect = this.url('domain_dashboard', { domainId }); |
| 567 | this.response.body = { domainId }; |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | class HomeMessagesHandler extends Handler { |