Skip to content

Commit 96a6d22

Browse files
ErlendSaebrage-andreas
authored andcommitted
Lint + moved notifcation type
1 parent ab8abbd commit 96a6d22

5 files changed

Lines changed: 28 additions & 21 deletions

File tree

apps/rpc/src/modules/notification/notification-repository.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import type {
33
Notification,
44
NotificationId,
55
NotificationWrite,
6-
UserId,
76
NotificationRecipientId,
87
NotificationRecipient,
9-
} from "@dotkomonline/types"
8+
UserNotification,
9+
} from "./notification"
10+
11+
import type { UserId } from "@dotkomonline/types"
1012

1113
export interface NotificationRepository {
1214
findById(handle: DBHandle, notificationId: NotificationId): Promise<Notification | null>
@@ -26,8 +28,8 @@ export interface NotificationRepository {
2628
recipientId: NotificationRecipientId,
2729
userId: UserId
2830
): Promise<NotificationRecipient | null>
29-
findAllforUser(handle: DBHandle, userId: UserId): Promise<Notification[]>
30-
getUnreadCountforUser(handle: DBHandle, userId: UserId): Promise<number>
31+
findAllForUser(handle: DBHandle, userId: UserId): Promise<UserNotification[]>
32+
getUnreadCountForUser(handle: DBHandle, userId: UserId): Promise<number>
3133
markAsRead(handle: DBHandle, notificationId: NotificationId, userId: UserId): Promise<void>
3234
markAllAsRead(handle: DBHandle, userId: UserId): Promise<void>
3335
}
@@ -96,17 +98,17 @@ export function getNotificationRepository(): NotificationRepository {
9698
})
9799
},
98100

99-
async getUnreadCountforUser(handle, userId) {
100-
await handle.notificationRecipient.count({
101-
where: { userId, readAt: null },
102-
})
103-
},
104-
105101
async getUnreadCountForUser(handle, userId) {
106102
return handle.notificationRecipient.count({
107103
where: { userId, readAt: null },
108104
})
109105
},
106+
async markAsRead(handle, notificationId, userId) {
107+
await handle.notificationRecipient.updateMany({
108+
where: { notificationId, userId, readAt: null },
109+
data: { readAt: new Date() },
110+
})
111+
},
110112

111113
async markAllAsRead(handle, userId) {
112114
await handle.notificationRecipient.updateMany({

apps/rpc/src/modules/notification/notification-router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { NotificationSchema, NotificationWriteSchema, UserNotificationSchema } from "@dotkomonline/types"
21
import type { inferProcedureInput, inferProcedureOutput } from "@trpc/server"
32
import { z } from "zod"
43
import { isEditor } from "../../authorization"
54
import { withAuditLogEntry, withAuthentication, withAuthorization, withDatabaseTransaction } from "../../middlewares"
65
import { procedure, t } from "../../trpc"
6+
import { NotificationSchema, NotificationWriteSchema } from "./notification"
77

88
export type GetNotificationInput = inferProcedureInput<typeof getNotificationProcedure>
99
export type GetNotificationOutput = inferProcedureOutput<typeof getNotificationProcedure>

apps/rpc/src/modules/notification/notification-service.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import type { DBHandle } from "@dotkomonline/db"
2-
import { NotFoundError } from "../../error"
3-
import type { Notification, NotificationId } from "@dotkomonline/types"
2+
import type {
3+
Notification,
4+
NotificationId,
5+
NotificationRecipient,
6+
NotificationRecipientId,
7+
NotificationWrite,
8+
UserNotification,
9+
} from "./notification"
10+
import type { UserId } from "@dotkomonline/types"
411
import type { NotificationRepository } from "./notification-repository"
512

613
export interface NotificationService {
@@ -21,8 +28,8 @@ export interface NotificationService {
2128
recipientId: NotificationRecipientId,
2229
userId: UserId
2330
): Promise<NotificationRecipient | null>
24-
findAllforUser(handle: DBHandle, userId: UserId): Promise<Notification[]>
25-
getUnreadCountforUser(handle: DBHandle, userId: UserId): Promise<number>
31+
findAllForUser(handle: DBHandle, userId: UserId): Promise<UserNotification[]>
32+
getUnreadCountForUser(handle: DBHandle, userId: UserId): Promise<number>
2633
markAsRead(handle: DBHandle, notificationId: NotificationId, userId: UserId): Promise<void>
2734
markAllAsRead(handle: DBHandle, userId: UserId): Promise<void>
2835
}
@@ -37,7 +44,6 @@ export function getNotificationService(notificationRepository: NotificationRepos
3744
},
3845

3946
async update(handle, notificationId, notificationData) {
40-
const notification = await notificationRepository.findById(handle, notificationId)
4147
return await notificationRepository.update(handle, notificationId, notificationData)
4248
},
4349

@@ -57,12 +63,12 @@ export function getNotificationService(notificationRepository: NotificationRepos
5763
return await notificationRepository.findRecipient(handle, recipientId, userId)
5864
},
5965

60-
async findAllforUser(handle, userId) {
61-
return await notificationRepository.findAllforUser(handle, userId)
66+
async findAllForUser(handle, userId) {
67+
return await notificationRepository.findAllForUser(handle, userId)
6268
},
6369

64-
async getUnreadCountforUser(handle, userId) {
65-
return await notificationRepository.getUnreadCountforUser(handle, userId)
70+
async getUnreadCountForUser(handle, userId) {
71+
return await notificationRepository.getUnreadCountForUser(handle, userId)
6672
},
6773

6874
async markAsRead(handle, notificationId, userId) {
File renamed without changes.

packages/types/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@ export * from "./task"
1414
export * from "./user"
1515
export * from "./audit-log"
1616
export * from "./workspace-sync"
17-
export * from "./notification"

0 commit comments

Comments
 (0)