Skip to content

Commit

Permalink
renaming resume automatically resolves duplicate name issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jackgarritano committed Apr 15, 2024
1 parent ef1533b commit c4590b4
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/controllers/resume.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,12 @@ export const updateResume = async (
);
}

if (
resumesFields.itemName != null &&
(await checkDuplicateResumeName(
if (resumesFields.itemName != null) {
resumesFields.itemName = await generateUniqueResumeName(
resumesFields.user,
resumesFields.itemName,
resumeId,
))
) {
throw new HttpError(HttpStatus.BAD_REQUEST, "Duplicate resume name");
resumeId,
);
}

const updatedResume = await ResumeModel.findOneAndUpdate(
Expand Down Expand Up @@ -148,14 +145,15 @@ export const deleteResume = async (user: string, resumeId: string) => {
export const generateUniqueResumeName = async (
user: string,
origName: string,
excludedId: string | null = null,
) => {
if (!(await checkDuplicateResumeName(user, origName))) {
if (!(await checkDuplicateResumeName(user, origName, excludedId))) {
return origName;
}

let counter = 1;
let newName = `${origName} (${counter})`;
while (await checkDuplicateResumeName(user, newName)) {
while (await checkDuplicateResumeName(user, newName, excludedId)) {
counter++;
newName = `${origName} (${counter})`;
}
Expand Down

0 comments on commit c4590b4

Please sign in to comment.