mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 07:35:09 +00:00
Review fixes
This commit is contained in:
@@ -4,43 +4,36 @@ import { TCreateUserNotificationDTO } from "./notification-types";
|
||||
import { TUserNotificationDALFactory } from "./user-notification-dal";
|
||||
|
||||
type TNotificationQueueServiceFactoryDep = {
|
||||
userNotificationDAL: Pick<TUserNotificationDALFactory, "create">;
|
||||
userNotificationDAL: Pick<TUserNotificationDALFactory, "batchInsert">;
|
||||
queueService: TQueueServiceFactory;
|
||||
};
|
||||
|
||||
export type TNotificationQueueServiceFactory = {
|
||||
pushUserNotification: (data: TCreateUserNotificationDTO) => Promise<void>;
|
||||
pushUserNotifications: (data: TCreateUserNotificationDTO[]) => Promise<void>;
|
||||
};
|
||||
|
||||
export const notificationQueueServiceFactory = async ({
|
||||
userNotificationDAL,
|
||||
queueService
|
||||
}: TNotificationQueueServiceFactoryDep): Promise<TNotificationQueueServiceFactory> => {
|
||||
const pushUserNotification = async (data: TCreateUserNotificationDTO) => {
|
||||
await queueService.queuePg(QueueJobs.UserNotification, data);
|
||||
const pushUserNotifications = async (data: TCreateUserNotificationDTO[]) => {
|
||||
await queueService.queuePg(QueueJobs.UserNotification, { notifications: data });
|
||||
};
|
||||
|
||||
await queueService.startPg(
|
||||
QueueJobs.UserNotification,
|
||||
async ([job]) => {
|
||||
const { userId, type, title, body, link } = job.data as TCreateUserNotificationDTO;
|
||||
|
||||
await userNotificationDAL.create({
|
||||
userId,
|
||||
type,
|
||||
title,
|
||||
body,
|
||||
link
|
||||
});
|
||||
const { notifications } = job.data as { notifications: TCreateUserNotificationDTO[] };
|
||||
await userNotificationDAL.batchInsert(notifications);
|
||||
},
|
||||
{
|
||||
batchSize: 100,
|
||||
workerCount: 5,
|
||||
pollingIntervalSeconds: 2
|
||||
batchSize: 1,
|
||||
workerCount: 2,
|
||||
pollingIntervalSeconds: 1
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
pushUserNotification
|
||||
pushUserNotifications
|
||||
};
|
||||
};
|
||||
|
||||
@@ -29,8 +29,8 @@ export const notificationServiceFactory = ({
|
||||
return notifications;
|
||||
};
|
||||
|
||||
const createUserNotification = async (data: TCreateUserNotificationDTO) => {
|
||||
return notificationQueue.pushUserNotification(data);
|
||||
const createUserNotifications = async (data: TCreateUserNotificationDTO[]) => {
|
||||
return notificationQueue.pushUserNotifications(data);
|
||||
};
|
||||
|
||||
const deleteUserNotification = async ({ userId, notificationId }: { userId: string; notificationId: string }) => {
|
||||
@@ -47,23 +47,34 @@ export const notificationServiceFactory = ({
|
||||
await userNotificationDAL.markAllNotificationsAsRead(userId);
|
||||
};
|
||||
|
||||
const markUserNotificationAsRead = async ({ userId, notificationId }: { userId: string; notificationId: string }) => {
|
||||
await userNotificationDAL.update(
|
||||
const updateUserNotification = async ({
|
||||
userId,
|
||||
notificationId,
|
||||
isRead
|
||||
}: {
|
||||
userId: string;
|
||||
notificationId: string;
|
||||
isRead: boolean;
|
||||
}) => {
|
||||
const [updatedNotification] = await userNotificationDAL.update(
|
||||
{
|
||||
id: notificationId,
|
||||
userId
|
||||
},
|
||||
{
|
||||
isRead: true
|
||||
isRead
|
||||
}
|
||||
);
|
||||
|
||||
if (!updatedNotification) throw new NotFoundError({ message: "Notification not found" });
|
||||
return updatedNotification;
|
||||
};
|
||||
|
||||
return {
|
||||
listUserNotifications,
|
||||
createUserNotification,
|
||||
createUserNotifications,
|
||||
deleteUserNotification,
|
||||
markUserNotificationsAsRead,
|
||||
markUserNotificationAsRead
|
||||
updateUserNotification
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export enum NotificationType {
|
||||
ACCESS_APPROVAL_REQUEST = "access-approval-request"
|
||||
ACCESS_APPROVAL_REQUEST = "access-approval-request",
|
||||
ACCESS_APPROVAL_REQUEST_UPDATED = "access-approval-request-updated"
|
||||
}
|
||||
|
||||
export interface TCreateUserNotificationDTO {
|
||||
|
||||
@@ -21,7 +21,7 @@ export const userNotificationDALFactory = (db: TDbClient) => {
|
||||
userId,
|
||||
startDate,
|
||||
endDate,
|
||||
limit = 10000,
|
||||
limit = 1000,
|
||||
offset = 0
|
||||
}: {
|
||||
userId: string;
|
||||
|
||||
Reference in New Issue
Block a user