Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(specification): add ids of underlying entities so that save reuse… #448

Merged
merged 3 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class SpecificationFeatureConfigApiEntity {

@ManyToOne(() => SpecificationApiEntity, {
onDelete: 'CASCADE',
orphanedRowAction: 'delete',
})
@JoinColumn({
name: 'specification_id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class SpecificationFeatureApiEntity {

@ManyToOne(() => SpecificationFeatureConfigApiEntity, {
onDelete: 'CASCADE',
orphanedRowAction: 'delete',
})
@JoinColumn({
name: 'specification_feature_config_id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,17 @@ export class DbSpecificationRepository implements SpecificationRepository {
scenarioId: snapshot.scenarioId,
specificationFeaturesConfiguration: this.specificationFeatureConfigRepo.create(
snapshot.config.map((configuration) => ({
id: configuration.id,
againstFeatureId: configuration.againstFeatureId,
baseFeatureId: configuration.baseFeatureId,
operation: configuration.operation,
splitByProperty: configuration.splitByProperty,
selectSubSets: configuration.selectSubSets,
features: configuration.resultFeatures.map((feature) =>
this.specificationFeatureRepo.create({
id: feature.id,
calculated: feature.calculated,
featureId: feature.id,
featureId: feature.featureId,
}),
),
featuresDetermined: configuration.featuresDetermined,
Expand Down Expand Up @@ -164,6 +166,7 @@ export class DbSpecificationRepository implements SpecificationRepository {
config:
specification.specificationFeaturesConfiguration?.map(
(specificationFeature) => ({
id: specificationFeature.id,
againstFeatureId:
specificationFeature.againstFeatureId ?? undefined,
baseFeatureId: specificationFeature.baseFeatureId,
Expand All @@ -173,7 +176,8 @@ export class DbSpecificationRepository implements SpecificationRepository {
selectSubSets: specificationFeature.selectSubSets ?? undefined,
resultFeatures:
specificationFeature.features?.map((feature) => ({
id: feature.featureId,
id: feature.id,
featureId: feature.featureId,
calculated: feature.calculated,
})) ?? [],
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const getFixtures = async () => {
featuresDetermined: true,
resultFeatures: [
{
id: calculatedFeatureId,
featureId: calculatedFeatureId,
calculated: true,
},
],
Expand All @@ -48,11 +48,11 @@ export const getFixtures = async () => {
featuresDetermined: true,
resultFeatures: [
{
id: calculatedFeatureId,
featureId: calculatedFeatureId,
calculated: true,
},
{
id: nonCalculatedFeatureId,
featureId: nonCalculatedFeatureId,
calculated: false,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ export const getFixtures = async () => {
new DetermineFeatures({
features: [
{
id: calculatedFeatureId,
featureId: calculatedFeatureId,
calculated: true,
},
{
id: nonCalculatedFeatureId,
featureId: nonCalculatedFeatureId,
calculated: false,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class InMemorySpecificationRepo implements SpecificationRepository {
.flatMap((spec) =>
spec.toSnapshot().config.flatMap((config) => ({
specId: spec.id,
features: config.resultFeatures.map((feature) => feature.id),
features: config.resultFeatures.map((feature) => feature.featureId),
})),
)
.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,33 @@ export const getFixtures = () => {

const featuresFromSplit = [
{
id: v4(),
featureId: v4(),
calculated: true,
},
{
id: v4(),
featureId: v4(),
calculated: true,
},
];

const featuresFromStratificationSomeCalculated = [
{
id: v4(),
featureId: v4(),
calculated: true,
},
{
id: nonCalculatedFeature,
featureId: nonCalculatedFeature,
calculated: false,
},
];

const featuresFromStratificationAllCalculated = [
{
id: v4(),
featureId: v4(),
calculated: true,
},
{
id: v4(),
featureId: v4(),
calculated: true,
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const getFixtures = () => {
featuresDetermined: true,
resultFeatures: [
{
id: v4(),
featureId: v4(),
calculated: true,
},
],
Expand All @@ -68,11 +68,11 @@ export const getFixtures = () => {
featuresDetermined: true,
resultFeatures: [
{
id: nonCalculatedFeatureOne,
featureId: nonCalculatedFeatureOne,
calculated: false,
},
{
id: nonCalculatedFeatureTwo,
featureId: nonCalculatedFeatureTwo,
calculated: false,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export enum SpecificationOperation {
}

export interface FeatureState {
id: string;
id?: string;
featureId: string;
calculated: boolean;
}

Expand All @@ -17,6 +18,7 @@ export interface FeatureSubSet {
}

interface FeatureConfigBase {
id?: string;
operation: SpecificationOperation;
baseFeatureId: string;
splitByProperty?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class Specification extends AggregateRoot {
markAsCalculated(featureIds: string[]): void {
this.configuration.forEach((featureConfig) =>
featureConfig.resultFeatures.forEach((feature) => {
if (featureIds.includes(feature.id)) {
if (featureIds.includes(feature.featureId)) {
feature.calculated = true;
}
}),
Expand Down Expand Up @@ -137,7 +137,7 @@ export class Specification extends AggregateRoot {
return this.configuration.flatMap((featureConfig) =>
featureConfig.resultFeatures
.filter((feature) => !feature.calculated)
.map((feature) => feature.id),
.map((feature) => feature.featureId),
);
}
}
14 changes: 10 additions & 4 deletions api/apps/api/test/integration/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,38 @@ export const getFixtures = async () => {
},
config: [
{
id: v4(),
operation: SpecificationOperation.Split,
featuresDetermined: true,
baseFeatureId: splitBaseFeatureId,
resultFeatures: [
{
id: calculatedFeatureId,
id: v4(),
featureId: calculatedFeatureId,
calculated: true,
},
{
id: calculatedForBothFeatureId,
id: v4(),
featureId: calculatedForBothFeatureId,
calculated: true,
},
],
},
{
id: v4(),
operation: SpecificationOperation.Stratification,
featuresDetermined: true,
againstFeatureId: stratificationAgainstFeatureId,
baseFeatureId: stratificationBaseFeatureId,
resultFeatures: [
{
id: nonCalculatedFeatureId,
id: v4(),
featureId: nonCalculatedFeatureId,
calculated: false,
},
{
id: calculatedForBothFeatureId,
id: v4(),
featureId: calculatedForBothFeatureId,
calculated: true,
},
],
Expand Down