Some linting

This commit is contained in:
Daniel Hougaard
2023-11-28 00:09:31 +04:00
parent 20210d7471
commit 5ae3b66e2e
2 changed files with 45 additions and 44 deletions
+16 -18
View File
@@ -362,14 +362,7 @@ export const createSecretRaw = async (req: Request, res: Response) => {
export const updateSecretByNameRaw = async (req: Request, res: Response) => { export const updateSecretByNameRaw = async (req: Request, res: Response) => {
const { const {
params: { secretName }, params: { secretName },
body: { body: { secretValue, environment, secretPath, type, workspaceId, skipMultilineEncoding }
secretValue,
environment,
secretPath,
type,
workspaceId,
skipMultilineEncoding,
}
} = await validateRequest(reqValidator.UpdateSecretByNameRawV3, req); } = await validateRequest(reqValidator.UpdateSecretByNameRawV3, req);
await checkSecretsPermission({ await checkSecretsPermission({
@@ -696,7 +689,7 @@ export const updateSecretByName = async (req: Request, res: Response) => {
secretKeyCiphertext, secretKeyCiphertext,
skipMultilineEncoding, skipMultilineEncoding,
secretReminderCron, secretReminderCron,
secretReminderNote, secretReminderNote
}, },
params: { secretName } params: { secretName }
} = await validateRequest(reqValidator.UpdateSecretByNameV3, req); } = await validateRequest(reqValidator.UpdateSecretByNameV3, req);
@@ -716,7 +709,6 @@ export const updateSecretByName = async (req: Request, res: Response) => {
if (membership && type !== "personal") { if (membership && type !== "personal") {
const secretApprovalPolicy = await getSecretPolicyOfBoard(workspaceId, environment, secretPath); const secretApprovalPolicy = await getSecretPolicyOfBoard(workspaceId, environment, secretPath);
if (secretApprovalPolicy) { if (secretApprovalPolicy) {
// ? QUESTION // ? QUESTION
// ? Here we could also expand upon the reminders feature, by adding it to the approval process. // ? Here we could also expand upon the reminders feature, by adding it to the approval process.
const secretApprovalRequest = await generateSecretApprovalRequest({ const secretApprovalRequest = await generateSecretApprovalRequest({
@@ -750,7 +742,7 @@ export const updateSecretByName = async (req: Request, res: Response) => {
} }
} }
if(type !== "personal") { if (type !== "personal") {
const existingSecret = await SecretService.getSecret({ const existingSecret = await SecretService.getSecret({
secretName, secretName,
workspaceId: new Types.ObjectId(workspaceId), workspaceId: new Types.ObjectId(workspaceId),
@@ -760,22 +752,28 @@ export const updateSecretByName = async (req: Request, res: Response) => {
authData: req.authData authData: req.authData
}); });
if((secretReminderCron && existingSecret.secretReminderCron !== secretReminderCron) || (secretReminderNote && existingSecret.secretReminderNote !== secretReminderNote)) { if (
(secretReminderCron && existingSecret.secretReminderCron !== secretReminderCron) ||
(secretReminderNote && existingSecret.secretReminderNote !== secretReminderNote)
) {
await createReminder(existingSecret, { await createReminder(existingSecret, {
_id: existingSecret._id, _id: existingSecret._id,
secretReminderCron, secretReminderCron,
secretReminderNote, secretReminderNote,
workspace: existingSecret.workspace, workspace: existingSecret.workspace
}) });
} else if(secretReminderCron === null && secretReminderNote === null && existingSecret.secretReminderCron) { } else if (
secretReminderCron === null &&
secretReminderNote === null &&
existingSecret.secretReminderCron
) {
await deleteReminder({ await deleteReminder({
_id: existingSecret._id, _id: existingSecret._id,
secretReminderCron: existingSecret.secretReminderCron, secretReminderCron: existingSecret.secretReminderCron
}) });
} }
} }
const secret = await SecretService.updateSecret({ const secret = await SecretService.updateSecret({
secretName, secretName,
workspaceId: new Types.ObjectId(workspaceId), workspaceId: new Types.ObjectId(workspaceId),
+28 -25
View File
@@ -1,33 +1,36 @@
import { ISecret } from "../models";
import {
createSecretReminderCron,
deleteSecretReminderCron,
updateSecretReminderCron
} from "../queues/reminders/sendSecretReminders";
import { ISecret } from "../models" type TPartialSecret = Pick<
import { createSecretReminderCron, deleteSecretReminderCron, updateSecretReminderCron } from "../queues/reminders/sendSecretReminders" ISecret,
"_id" | "secretReminderCron" | "secretReminderNote" | "workspace"
>;
type TPartialSecret = Pick<ISecret, "_id" | "secretReminderCron" | "secretReminderNote" | "workspace"> type TPartialSecretDeleteReminder = Pick<ISecret, "_id" | "secretReminderCron">;
type TPartialSecretDeleteReminder = Pick<ISecret, | "_id" | "secretReminderCron">
export const createReminder = async (oldSecret: TPartialSecret, newSecret: TPartialSecret) => { export const createReminder = async (oldSecret: TPartialSecret, newSecret: TPartialSecret) => {
if(oldSecret._id !== newSecret._id) { if (oldSecret._id !== newSecret._id) {
throw new Error("Secret id's don't match") throw new Error("Secret id's don't match");
} }
if(!newSecret.secretReminderCron) { if (!newSecret.secretReminderCron) {
throw new Error("No cron provided") throw new Error("No cron provided");
} }
const secretId = oldSecret._id.toString() const secretId = oldSecret._id.toString();
const workspaceId = oldSecret.workspace.toString() const workspaceId = oldSecret.workspace.toString();
if(oldSecret.secretReminderCron) { if (oldSecret.secretReminderCron) {
// This will first delete the existing cron job, and then create a new one. // This will first delete the existing cron job, and then create a new one.
await updateSecretReminderCron({ await updateSecretReminderCron({
workspaceId, workspaceId,
secretId, secretId,
cron: newSecret.secretReminderCron, cron: newSecret.secretReminderCron,
note: newSecret.secretReminderNote note: newSecret.secretReminderNote
}) });
} else { } else {
// This will create a new cron job. // This will create a new cron job.
await createSecretReminderCron({ await createSecretReminderCron({
@@ -35,21 +38,21 @@ export const createReminder = async (oldSecret: TPartialSecret, newSecret: TPart
secretId, secretId,
cron: newSecret.secretReminderCron, cron: newSecret.secretReminderCron,
note: newSecret.secretReminderNote note: newSecret.secretReminderNote
}) });
} }
} };
export const deleteReminder = async (secret: TPartialSecretDeleteReminder) => { export const deleteReminder = async (secret: TPartialSecretDeleteReminder) => {
if(!secret._id) { if (!secret._id) {
throw new Error("No secret id provided") throw new Error("No secret id provided");
} }
if(!secret.secretReminderCron) { if (!secret.secretReminderCron) {
throw new Error("No cron provided") throw new Error("No cron provided");
} }
await deleteSecretReminderCron({ await deleteSecretReminderCron({
secretId: secret._id.toString(), secretId: secret._id.toString(),
cron: secret.secretReminderCron, cron: secret.secretReminderCron
}) });
} };