chore: rename approverUserIds to approvers in registerSecretApprovalPolicy

This commit is contained in:
Alfonso Hernandez
2024-07-17 16:49:54 +02:00
parent c90ecd336c
commit 6818c8730f
3 changed files with 12 additions and 12 deletions
@@ -25,10 +25,10 @@ export const registerSecretApprovalPolicyRouter = async (server: FastifyZodProvi
.optional() .optional()
.nullable() .nullable()
.transform((val) => (val ? removeTrailingSlash(val) : val)), .transform((val) => (val ? removeTrailingSlash(val) : val)),
approverUserIds: z.string().array().min(1), approvers: z.string().array().min(1),
approvals: z.number().min(1).default(1) approvals: z.number().min(1).default(1)
}) })
.refine((data) => data.approvals <= data.approverUserIds.length, { .refine((data) => data.approvals <= data.approvers.length, {
path: ["approvals"], path: ["approvals"],
message: "The number of approvals should be lower than the number of approvers." message: "The number of approvals should be lower than the number of approvers."
}), }),
@@ -66,7 +66,7 @@ export const registerSecretApprovalPolicyRouter = async (server: FastifyZodProvi
body: z body: z
.object({ .object({
name: z.string().optional(), name: z.string().optional(),
approverUserIds: z.string().array().min(1), approvers: z.string().array().min(1),
approvals: z.number().min(1).default(1), approvals: z.number().min(1).default(1),
secretPath: z secretPath: z
.string() .string()
@@ -74,7 +74,7 @@ export const registerSecretApprovalPolicyRouter = async (server: FastifyZodProvi
.nullable() .nullable()
.transform((val) => (val ? removeTrailingSlash(val) : val)) .transform((val) => (val ? removeTrailingSlash(val) : val))
}) })
.refine((data) => data.approvals <= data.approverUserIds.length, { .refine((data) => data.approvals <= data.approvers.length, {
path: ["approvals"], path: ["approvals"],
message: "The number of approvals should be lower than the number of approvers." message: "The number of approvals should be lower than the number of approvers."
}), }),
@@ -45,12 +45,12 @@ export const secretApprovalPolicyServiceFactory = ({
actorOrgId, actorOrgId,
actorAuthMethod, actorAuthMethod,
approvals, approvals,
approverUserIds, approvers,
projectId, projectId,
secretPath, secretPath,
environment environment
}: TCreateSapDTO) => { }: TCreateSapDTO) => {
if (approvals > approverUserIds.length) if (approvals > approvers.length)
throw new BadRequestError({ message: "Approvals cannot be greater than approvers" }); throw new BadRequestError({ message: "Approvals cannot be greater than approvers" });
const { permission } = await permissionService.getProjectPermission( const { permission } = await permissionService.getProjectPermission(
@@ -78,7 +78,7 @@ export const secretApprovalPolicyServiceFactory = ({
tx tx
); );
await secretApprovalPolicyApproverDAL.insertMany( await secretApprovalPolicyApproverDAL.insertMany(
approverUserIds.map((approverUserId) => ({ approvers.map((approverUserId) => ({
approverUserId, approverUserId,
policyId: doc.id policyId: doc.id
})), })),
@@ -90,7 +90,7 @@ export const secretApprovalPolicyServiceFactory = ({
}; };
const updateSecretApprovalPolicy = async ({ const updateSecretApprovalPolicy = async ({
approverUserIds, approvers,
secretPath, secretPath,
name, name,
actorId, actorId,
@@ -122,10 +122,10 @@ export const secretApprovalPolicyServiceFactory = ({
}, },
tx tx
); );
if (approverUserIds) { if (approvers) {
await secretApprovalPolicyApproverDAL.delete({ policyId: doc.id }, tx); await secretApprovalPolicyApproverDAL.delete({ policyId: doc.id }, tx);
await secretApprovalPolicyApproverDAL.insertMany( await secretApprovalPolicyApproverDAL.insertMany(
approverUserIds.map((approverUserId) => ({ approvers.map((approverUserId) => ({
approverUserId, approverUserId,
policyId: doc.id policyId: doc.id
})), })),
@@ -4,7 +4,7 @@ export type TCreateSapDTO = {
approvals: number; approvals: number;
secretPath?: string | null; secretPath?: string | null;
environment: string; environment: string;
approverUserIds: string[]; approvers: string[];
projectId: string; projectId: string;
name: string; name: string;
} & Omit<TProjectPermission, "projectId">; } & Omit<TProjectPermission, "projectId">;
@@ -13,7 +13,7 @@ export type TUpdateSapDTO = {
secretPolicyId: string; secretPolicyId: string;
approvals?: number; approvals?: number;
secretPath?: string | null; secretPath?: string | null;
approverUserIds: string[]; approvers: string[];
name?: string; name?: string;
} & Omit<TProjectPermission, "projectId">; } & Omit<TProjectPermission, "projectId">;