Minor improvements on new reminders api

This commit is contained in:
Carlos Monastyrski
2025-07-14 16:48:05 -03:00
parent 6449699f03
commit bd4968b60d
10 changed files with 40 additions and 84 deletions
@@ -2,6 +2,7 @@
import { ForbiddenError } from "@casl/ability";
import { Knex } from "knex";
import { TableName } from "@app/db/schemas";
import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service-types";
import { ProjectPermissionSecretActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission";
import { BadRequestError } from "@app/lib/errors";
@@ -21,7 +22,7 @@ type TReminderServiceFactoryDep = {
smtpService: TSmtpService;
projectMembershipDAL: Pick<TProjectMembershipDALFactory, "findAllProjectMembers">;
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
secretV2BridgeDAL: Pick<TSecretV2BridgeDALFactory, "invalidateSecretCacheByProjectId">;
secretV2BridgeDAL: Pick<TSecretV2BridgeDALFactory, "invalidateSecretCacheByProjectId" | "findOneWithTags">;
};
export const reminderServiceFactory = ({
@@ -136,13 +137,16 @@ export const reminderServiceFactory = ({
actorId,
actorOrgId,
actorAuthMethod,
projectId,
reminder
}: TCreateReminderDTO) => {
const secret = await secretV2BridgeDAL.findOneWithTags({ [`${TableName.SecretV2}.id` as "id"]: reminder.secretId });
if (!secret) {
throw new BadRequestError({ message: `Secret ${reminder.secretId} not found` });
}
const { permission } = await permissionService.getProjectPermission({
actor,
actorId,
projectId,
projectId: secret.projectId,
actorAuthMethod,
actorOrgId
});
@@ -150,30 +154,32 @@ export const reminderServiceFactory = ({
const response = await createReminderInternal({
...reminder,
projectId
projectId: secret.projectId
});
return response;
};
const getReminder: TReminderServiceFactory["getReminder"] = async ({
secretId,
projectId,
actor,
actorId,
actorOrgId,
actorAuthMethod
}: {
secretId: string;
projectId: string;
actor: ActorType;
actorId: string;
actorOrgId: string;
actorAuthMethod: ActorAuthMethod;
}) => {
const secret = await secretV2BridgeDAL.findOneWithTags({ [`${TableName.SecretV2}.id` as "id"]: secretId });
if (!secret) {
throw new BadRequestError({ message: `Secret ${secretId} not found` });
}
const { permission } = await permissionService.getProjectPermission({
actor,
actorId,
projectId,
projectId: secret.projectId,
actorAuthMethod,
actorOrgId
});
@@ -228,40 +234,29 @@ export const reminderServiceFactory = ({
actorId,
actorOrgId,
actorAuthMethod,
secretId,
projectId
secretId
}: {
actor: ActorType;
actorId: string;
actorOrgId: string;
actorAuthMethod: ActorAuthMethod;
secretId: string;
projectId: string;
}) => {
const secret = await secretV2BridgeDAL.findOneWithTags({ [`${TableName.SecretV2}.id` as "id"]: secretId });
if (!secret) {
throw new BadRequestError({ message: `Secret ${secretId} not found` });
}
const { permission } = await permissionService.getProjectPermission({
actor,
actorId,
projectId,
projectId: secret.projectId,
actorAuthMethod,
actorOrgId
});
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionSecretActions.Edit, ProjectPermissionSub.Secrets);
await reminderDAL.delete({ secretId });
await secretV2BridgeDAL.invalidateSecretCacheByProjectId(projectId);
};
const removeReminderRecipients: TReminderServiceFactory["removeReminderRecipients"] = async (
secretId: string,
projectId: string,
tx?: Knex
) => {
const reminder = await reminderDAL.findOne({ secretId }, tx);
if (!reminder) {
return;
}
await reminderRecipientDAL.delete({ reminderId: reminder.id }, tx);
await secretV2BridgeDAL.invalidateSecretCacheByProjectId(projectId);
await secretV2BridgeDAL.invalidateSecretCacheByProjectId(secret.projectId);
};
const deleteReminderBySecretId: TReminderServiceFactory["deleteReminderBySecretId"] = async (
@@ -354,7 +349,6 @@ export const reminderServiceFactory = ({
getReminder,
sendDailyReminders,
deleteReminder,
removeReminderRecipients,
deleteReminderBySecretId,
batchCreateReminders,
createReminderInternal
@@ -17,7 +17,6 @@ export type TCreateReminderDTO = {
actorId: string;
actorOrgId: string;
actorAuthMethod: ActorAuthMethod;
projectId: string;
reminder: {
secretId?: string;
message?: string | null;
@@ -37,28 +36,19 @@ export type TBatchCreateReminderDTO = {
}[];
export interface TReminderServiceFactory {
createReminder: ({
actor,
actorId,
actorOrgId,
actorAuthMethod,
projectId,
reminder
}: TCreateReminderDTO) => Promise<{
createReminder: ({ actor, actorId, actorOrgId, actorAuthMethod, reminder }: TCreateReminderDTO) => Promise<{
id: string;
created: boolean;
}>;
getReminder: ({
secretId,
projectId,
actor,
actorId,
actorOrgId,
actorAuthMethod
}: {
secretId: string;
projectId: string;
actor: ActorType;
actorId: string;
actorOrgId: string;
@@ -72,19 +62,15 @@ export interface TReminderServiceFactory {
actorId,
actorOrgId,
actorAuthMethod,
secretId,
projectId
secretId
}: {
actor: ActorType;
actorId: string;
actorOrgId: string;
actorAuthMethod: ActorAuthMethod;
secretId: string;
projectId: string;
}) => Promise<void>;
removeReminderRecipients: (secretId: string, projectId: string, tx?: Knex) => Promise<void>;
deleteReminderBySecretId: (secretId: string, projectId: string, tx?: Knex) => Promise<void>;
batchCreateReminders: (
@@ -344,7 +344,6 @@ export const secretV2BridgeServiceFactory = ({
actorId,
actorOrgId,
actorAuthMethod,
projectId,
reminder: {
secretId: secret.id,
message: inputSecret.secretReminderNote,
@@ -558,7 +557,6 @@ export const secretV2BridgeServiceFactory = ({
actorId,
actorOrgId,
actorAuthMethod,
projectId,
reminder: {
secretId: secret.id,
message: inputSecret.secretReminderNote,
+1 -4
View File
@@ -111,10 +111,7 @@ type TSecretQueueFactoryDep = {
resourceMetadataDAL: Pick<TResourceMetadataDALFactory, "insertMany" | "delete">;
folderCommitService: Pick<TFolderCommitServiceFactory, "createCommit">;
secretSyncQueue: Pick<TSecretSyncQueueFactory, "queueSecretSyncsSyncSecretsByPath">;
reminderService: Pick<
TReminderServiceFactory,
"createReminderInternal" | "deleteReminderBySecretId" | "removeReminderRecipients"
>;
reminderService: Pick<TReminderServiceFactory, "createReminderInternal" | "deleteReminderBySecretId">;
};
export type TGetSecrets = {
@@ -1859,7 +1859,6 @@ export const secretServiceFactory = ({
actorId,
actorOrgId,
actorAuthMethod,
projectId,
reminder: {
secretId: secret.id,
message: secretReminderNote,
@@ -2269,7 +2268,6 @@ export const secretServiceFactory = ({
actorId,
actorOrgId,
actorAuthMethod,
projectId,
reminder: {
secretId: secrets.find(
(el) =>