Skip to content

Commit 1878d3e

Browse files
committed
refactor(api): delete only archived notifications in deleteAll
1 parent ff5fd8e commit 1878d3e

File tree

5 files changed

+32
-27
lines changed

5 files changed

+32
-27
lines changed

api/src/graphql/generated/api/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ export type Mutation = {
632632
connectSignIn: Scalars['Boolean']['output'];
633633
connectSignOut: Scalars['Boolean']['output'];
634634
createNotification: Notification;
635+
/** Deletes all archived notifications on server. */
635636
deleteAllNotifications: NotificationOverview;
636637
deleteNotification: NotificationOverview;
637638
/** Delete a user */

api/src/graphql/schema/types/notifications/notifications.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ type Query {
1717
type Mutation {
1818
createNotification(input: NotificationData!): Notification!
1919
deleteNotification(id: String!, type: NotificationType!): NotificationOverview!
20+
"""
21+
Deletes all archived notifications on server.
22+
"""
2023
deleteAllNotifications: NotificationOverview!
2124
"""
2225
Marks a notification as archived.

api/src/unraid-api/graph/resolvers/notifications/notifications.resolver.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { Args, Mutation, Query, ResolveField, Resolver, Subscription } from '@ne
33

44
import { UseRoles } from 'nest-access-control';
55

6-
import type {
6+
import { AppError } from '@app/core/errors/app-error';
7+
import { createSubscription, PUBSUB_CHANNEL } from '@app/core/pubsub';
8+
import {
79
NotificationData,
810
NotificationFilter,
911
NotificationOverview,
1012
NotificationType,
1113
} from '@app/graphql/generated/api/types';
12-
import { AppError } from '@app/core/errors/app-error';
13-
import { createSubscription, PUBSUB_CHANNEL } from '@app/core/pubsub';
1414
import { Importance } from '@app/graphql/generated/client/graphql';
1515

1616
import { NotificationsService } from './notifications.service';
@@ -74,7 +74,7 @@ export class NotificationsResolver {
7474

7575
@Mutation()
7676
public async deleteAllNotifications(): Promise<NotificationOverview> {
77-
return this.notificationsService.deleteAllNotifications();
77+
return this.notificationsService.deleteNotifications(NotificationType.ARCHIVE);
7878
}
7979

8080
@Mutation()

api/src/unraid-api/graph/resolvers/notifications/notifications.service.ts

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -292,33 +292,34 @@ export class NotificationsService {
292292
}
293293

294294
/**
295-
* Deletes all notifications from disk, but preserves
296-
* notification directories.
295+
* Deletes all notifications of a specific type and resets their overview stats.
297296
*
298-
* Resets the notification overview to all zeroes.
297+
* @param type - The type of notifications to delete (UNREAD or ARCHIVE)
298+
* @remarks Ensures the notifications directory exists before emptying it
299299
*/
300-
public async deleteAllNotifications() {
301-
const { UNREAD, ARCHIVE } = this.paths();
302-
// ensures the directory exists before deleting
303-
await emptyDir(ARCHIVE);
304-
await emptyDir(UNREAD);
305-
NotificationsService.overview = {
306-
unread: {
307-
alert: 0,
308-
info: 0,
309-
warning: 0,
310-
total: 0,
311-
},
312-
archive: {
313-
alert: 0,
314-
info: 0,
315-
warning: 0,
316-
total: 0,
317-
},
300+
public async deleteNotifications(type: NotificationType) {
301+
await emptyDir(this.paths()[type]);
302+
NotificationsService.overview[type.toLowerCase()] = {
303+
alert: 0,
304+
info: 0,
305+
warning: 0,
306+
total: 0,
318307
};
319308
return this.getOverview();
320309
}
321310

311+
/**
312+
* Deletes all notifications from disk while preserving the directory structure.
313+
* Resets overview stats to zero.
314+
*
315+
* @returns The updated notification overview stats
316+
*/
317+
public async deleteAllNotifications() {
318+
await this.deleteNotifications(NotificationType.ARCHIVE);
319+
await this.deleteNotifications(NotificationType.UNREAD);
320+
return this.getOverview();
321+
}
322+
322323
/**------------------------------------------------------------------------
323324
* CRUD: Updating Notifications
324325
*------------------------------------------------------------------------**/
@@ -700,7 +701,7 @@ export class NotificationsService {
700701
}
701702

702703
private parseNotificationDateToIsoDate(unixStringSeconds: string | undefined): Date | null {
703-
const timeStamp = Number(unixStringSeconds)
704+
const timeStamp = Number(unixStringSeconds);
704705
if (unixStringSeconds && !Number.isNaN(timeStamp)) {
705706
return new Date(timeStamp * 1_000);
706707
}

web/components/Notifications/Sidebar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const confirmAndArchiveAll = async () => {
2222
2323
const confirmAndDeleteAll = async () => {
2424
if (
25-
confirm('This will permanently delete all notifications currently on your Unraid server. Continue?')
25+
confirm('This will permanently delete all archived notifications currently on your Unraid server. Continue?')
2626
) {
2727
await deleteAll();
2828
}

0 commit comments

Comments
 (0)