Skip to content

Commit

Permalink
fix(folders): check for uniqueness on update
Browse files Browse the repository at this point in the history
  • Loading branch information
AndySakov committed Nov 19, 2024
1 parent c53492f commit 2d4b59c
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions src/jobs/jobs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2751,7 +2751,7 @@ export class JobsService {
if (existing) {
return {
success: false,
message: "Folder already exists",
message: "Folder with that name already exists",
};
} else {
const result = await this.neogma.queryRunner.run(
Expand Down Expand Up @@ -2811,8 +2811,17 @@ export class JobsService {
dto: UpdateJobFolderInput,
): Promise<ResponseWithOptionalData<JobpostFolder>> {
try {
const result = await this.neogma.queryRunner.run(
`
const existing = data(
await this.getUserJobFolderById(sluggify(dto.name)),
);
if (existing) {
return {
success: false,
message: "Folder with that name already exists",
};
} else {
const result = await this.neogma.queryRunner.run(
`
MATCH (folder:JobpostFolder {id: $id})
SET folder.id = $newId
SET folder.name = $name
Expand All @@ -2828,22 +2837,23 @@ export class JobsService {
RETURN folder { .* } as folder
`,
{ id, ...dto, newId: sluggify(dto.name) },
);
{ id, ...dto, newId: sluggify(dto.name) },
);

const res = result.records[0]?.get("folder");
if (res) {
const details = data(await this.getUserJobFolderById(id));
return {
success: true,
message: "Job folder updated successfully",
data: details,
};
} else {
return {
success: false,
message: "Job folder update failed",
};
const res = result.records[0]?.get("folder");
if (res) {
const details = data(await this.getUserJobFolderById(id));
return {
success: true,
message: "Job folder updated successfully",
data: details,
};
} else {
return {
success: false,
message: "Job folder update failed",
};
}
}
} catch (err) {
Sentry.withScope(scope => {
Expand Down

0 comments on commit 2d4b59c

Please sign in to comment.