Skip to content

Commit

Permalink
fix: rename select option brake view group
Browse files Browse the repository at this point in the history
  • Loading branch information
magrinj committed Dec 3, 2024
1 parent 7ff1876 commit 73100fb
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';

import { In } from 'typeorm';
import { EntityManager, In } from 'typeorm';

import {
FieldMetadataComplexOption,
Expand All @@ -27,6 +27,7 @@ export class FieldMetadataRelatedRecordsService {
public async updateRelatedViewGroups(
oldFieldMetadata: FieldMetadataEntity,
newFieldMetadata: FieldMetadataEntity,
transactionManager?: EntityManager,
) {
if (
!isSelectFieldMetadataType(newFieldMetadata.type) ||
Expand Down Expand Up @@ -68,7 +69,7 @@ export class FieldMetadataRelatedRecordsService {
}),
);

await viewGroupRepository.insert(viewGroupsToCreate);
await viewGroupRepository.insert(viewGroupsToCreate, transactionManager);

for (const { old: oldOption, new: newOption } of updated) {
const viewGroup = view.viewGroups.find(
Expand All @@ -86,15 +87,19 @@ export class FieldMetadataRelatedRecordsService {
{
fieldValue: newOption.value,
},
transactionManager,
);
}

const valuesToDelete = deleted.map((option) => option.value);

await viewGroupRepository.delete({
fieldMetadataId: newFieldMetadata.id,
fieldValue: In(valuesToDelete),
});
await viewGroupRepository.delete(
{
fieldMetadataId: newFieldMetadata.id,
fieldValue: In(valuesToDelete),
},
transactionManager,
);
}
}

Expand Down Expand Up @@ -147,7 +152,9 @@ export class FieldMetadataRelatedRecordsService {

return await viewRepository.find({
where: {
kanbanFieldMetadataId: fieldMetadata.id,
viewGroups: {
fieldMetadataId: fieldMetadata.id,
},
},
relations: ['viewGroups'],
});
Expand Down

0 comments on commit 73100fb

Please sign in to comment.