feat(secret-reminders): addressed PR suggestions and improvements

This commit is contained in:
Carlos Monastyrski
2025-07-04 11:58:09 -03:00
parent 0efc314f33
commit e2559f10bc
26 changed files with 276 additions and 186 deletions
+7 -3
View File
@@ -740,7 +740,8 @@ export const fnSecretBulkDelete = async ({
tx,
actorId,
secretDAL,
secretQueueService
secretQueueService,
projectId
}: TFnSecretBulkDelete) => {
const deletedSecrets = await secretDAL.deleteMany(
inputSecrets.map(({ type, secretBlindIndex }) => ({
@@ -756,7 +757,10 @@ export const fnSecretBulkDelete = async ({
deletedSecrets
.filter(({ secretReminderRepeatDays }) => Boolean(secretReminderRepeatDays))
.map(({ id, secretReminderRepeatDays }) =>
secretQueueService.removeSecretReminder({ secretId: id, repeatDays: secretReminderRepeatDays as number }, tx)
secretQueueService.removeSecretReminder(
{ secretId: id, repeatDays: secretReminderRepeatDays as number, projectId },
tx
)
)
);
@@ -1211,7 +1215,7 @@ export const fnDeleteProjectSecretReminders = async (
: (secret as { secretReminderRepeatDays: number }).secretReminderRepeatDays;
if (repeatDays) {
await reminderService.deleteReminderBySecretId(secret.id);
await reminderService.deleteReminderBySecretId(secret.id, projectId);
}
}
};
+13 -5
View File
@@ -186,7 +186,7 @@ export const secretQueueFactory = ({
const removeSecretReminder = async ({ deleteRecipients = true, ...dto }: TRemoveSecretReminderDTO, tx?: Knex) => {
if (deleteRecipients) {
await reminderService.deleteReminderBySecretId(dto.secretId, tx);
await reminderService.deleteReminderBySecretId(dto.secretId, dto.projectId, tx);
}
};
@@ -223,7 +223,12 @@ export const secretQueueFactory = ({
.replace(":", "-");
};
const addSecretReminder = async ({ oldSecret, newSecret, secretReminderRecipients }: TCreateSecretReminderDTO) => {
const addSecretReminder = async ({
oldSecret,
newSecret,
projectId,
secretReminderRecipients
}: TCreateSecretReminderDTO) => {
try {
if (oldSecret.id !== newSecret.id) {
throw new BadRequestError({
@@ -243,7 +248,8 @@ export const secretQueueFactory = ({
secretId: newSecret.id,
message: newSecret.secretReminderNote,
repeatDays: newSecret.secretReminderRepeatDays,
recipients: secretReminderRecipients
recipients: secretReminderRecipients,
projectId
});
} catch (err) {
logger.error(err, "Failed to create secret reminder.");
@@ -254,7 +260,7 @@ export const secretQueueFactory = ({
}
};
const handleSecretReminder = async ({ newSecret, oldSecret }: THandleReminderDTO) => {
const handleSecretReminder = async ({ newSecret, oldSecret, projectId }: THandleReminderDTO) => {
const { secretReminderRepeatDays, secretReminderNote, secretReminderRecipients } = newSecret;
if (newSecret.type !== SecretType.Personal && secretReminderRepeatDays !== undefined) {
@@ -265,6 +271,7 @@ export const secretQueueFactory = ({
await addSecretReminder({
oldSecret,
newSecret,
projectId,
secretReminderRecipients: secretReminderRecipients ?? [],
deleteRecipients: false
});
@@ -275,7 +282,8 @@ export const secretQueueFactory = ({
) {
await removeSecretReminder({
secretId: oldSecret.id,
repeatDays: oldSecret.secretReminderRepeatDays
repeatDays: oldSecret.secretReminderRepeatDays,
projectId
});
}
}
@@ -393,7 +393,8 @@ export const secretServiceFactory = ({
id: secrets[0].id,
...inputSecret
},
oldSecret: secrets[0]
oldSecret: secrets[0],
projectId
});
const tags = inputSecret.tags ? await secretTagDAL.findManyTagsById(projectId, inputSecret.tags) : [];
@@ -548,7 +549,8 @@ export const secretServiceFactory = ({
await secretQueueService.removeSecretReminder(
{
repeatDays: secret.secretReminderRepeatDays,
secretId: secret.id
secretId: secret.id,
projectId
},
tx
);
@@ -1074,7 +1076,8 @@ export const secretServiceFactory = ({
await secretQueueService.removeSecretReminder(
{
repeatDays: secret.secretReminderRepeatDays,
secretId: secret.id
secretId: secret.id,
projectId
},
tx
);
@@ -404,11 +404,13 @@ export type TFnSecretBlindIndexCheckV2 = {
export type THandleReminderDTO = {
newSecret: TPartialInputSecret;
oldSecret: TPartialSecret;
projectId: string;
};
export type TCreateSecretReminderDTO = {
oldSecret: TPartialSecret;
newSecret: TPartialSecret;
projectId: string;
secretReminderRecipients: string[];
deleteRecipients?: boolean;
@@ -417,6 +419,7 @@ export type TCreateSecretReminderDTO = {
export type TRemoveSecretReminderDTO = {
secretId: string;
repeatDays: number;
projectId: string;
deleteRecipients?: boolean;
};