simplify dialog announcement check
This commit is contained in:
parent
47f44a0d4c
commit
e5aabb2978
1 changed files with 10 additions and 10 deletions
|
|
@ -70,11 +70,11 @@ export class AnnouncementService {
|
|||
public async create(values: Partial<MiAnnouncement>, moderator?: MiUser): Promise<{ raw: MiAnnouncement; packed: Packed<'Announcement'> }> {
|
||||
if (values.display === 'dialog') {
|
||||
// Check how many active dialog queries already exist, to enforce a limit
|
||||
const query = this.announcementsRepository.createQueryBuilder('announcement');
|
||||
query.andWhere('announcement.isActive = true');
|
||||
query.andWhere('announcement.display = \'dialog\'');
|
||||
const count = await query.getCount();
|
||||
if (count >= 5) {
|
||||
const dialogCount = await this.announcementsRepository.createQueryBuilder('announcement')
|
||||
.where({ isActive: true })
|
||||
.where({ display: 'dialog' })
|
||||
.getCount();
|
||||
if (dialogCount >= 5) {
|
||||
throw new IdentifiableError('c0d15f15-f18e-4a40-bcb1-f310d58204ee', 'Too many dialog announcements.');
|
||||
}
|
||||
}
|
||||
|
|
@ -135,11 +135,11 @@ export class AnnouncementService {
|
|||
// Check if this operation would produce an active dialog announcement
|
||||
if ((values.display ?? announcement.display) === 'dialog' && (values.isActive ?? announcement.isActive)) {
|
||||
// Check how many active dialog queries already exist, to enforce a limit
|
||||
const query = this.announcementsRepository.createQueryBuilder('announcement');
|
||||
query.andWhere('announcement.isActive = true');
|
||||
query.andWhere('announcement.display = \'dialog\'');
|
||||
const count = await query.getCount();
|
||||
if (count >= 5) {
|
||||
const dialogCount = await this.announcementsRepository.createQueryBuilder('announcement')
|
||||
.where({ isActive: true })
|
||||
.where({ display: 'dialog' })
|
||||
.getCount();
|
||||
if (dialogCount >= 5) {
|
||||
throw new IdentifiableError('c0d15f15-f18e-4a40-bcb1-f310d58204ee', 'Too many dialog announcements.');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue