Skip to content

Commit

Permalink
Merge pull request #17 from beabee-communityrm/fix/delete-callout-var…
Browse files Browse the repository at this point in the history
…iant

fix: callout variants can't be removed
  • Loading branch information
wpf500 authored Jul 17, 2024
2 parents 82475c1 + e0ca61f commit 8fa5c56
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions apps/backend/src/core/services/CalloutsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,27 +334,28 @@ class CalloutsService {
};

return await runTransaction(async (em) => {
let newId = id;
try {
if (id) {
const result = await em.getRepository(Callout).update(id, fixedData);
if (newId) {
const result = await em
.getRepository(Callout)
.update(newId, fixedData);
if (result.affected === 0) {
throw new NotFoundError();
}
} else {
const result = await em.getRepository(Callout).insert(fixedData);
id = result.identifiers[0].id as string;
newId = result.identifiers[0].id as string;
}
} catch (err) {
throw isDuplicateIndex(err, "slug")
? new DuplicateId(data.slug || "") // Slug can't actually be undefined here
: err;
}

// Type checker doesn't understand that id is defined here
const newId = id;

if (variants) {
await em.getRepository(CalloutVariant).save(
await em.getRepository(CalloutVariant).delete({ calloutId: newId });
await em.getRepository(CalloutVariant).insert(
Object.entries(variants).map(([name, variant]) => ({
...variant,
name,
Expand Down

0 comments on commit 8fa5c56

Please sign in to comment.