Skip to content

Commit

Permalink
(fix)export and import lockStatusSetByUser flag [MRXN23-600]
Browse files Browse the repository at this point in the history
  • Loading branch information
hotzevzl committed Mar 11, 2024
1 parent 70662ea commit fbb9532
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ export const validDataWithGivenPuIds = (
puids: string[],
scenarioId = 'scenario-0000-fake-uuid',
): ScenariosPlanningUnitGeoEntity[] =>
puids.map((id, index) => ({
puids.map((id, _index) => ({
lockStatus: LockStatus.Available,
lockStatusSetByUser: false,
protectedByDefault: false,
scenarioId,
projectPuId: v4(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class ScenarioPlanningUnitSerializer {
defaultStatus: unit.protectedByDefault
? LockStatus.LockedIn
: LockStatus.Available,
setByUser: unit.setByUser,
setByUser: unit.lockStatusSetByUser,
})),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class ScenarioPlanningUnitsService {
where: {
scenarioId,
lockStatus,
setByUser: true,
lockStatusSetByUser: true,
},
});
}
Expand All @@ -63,7 +63,7 @@ export class ScenarioPlanningUnitsService {
},
{
lockStatus: LockStatus.Available,
setByUser: false,
lockStatusSetByUser: false,
},
);

Expand All @@ -75,7 +75,7 @@ export class ScenarioPlanningUnitsService {
},
{
lockStatus: LockStatus.LockedIn,
setByUser: false,
lockStatusSetByUser: false,
},
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const getFixtures = async () => {
projectPuId: pu.id,
scenarioId,
lockStatus: lockStatuses[index] ?? null,
setByUser: [1, 2].includes(index) ? true : false,
lockStatusSetByUser: [1, 2].includes(index) ? true : false,
}),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,23 @@ export class ProjectCostSurfacesPieceExporter implements ExportPieceProcessor {
projectPusMap = await this.getProjectPusMap(input.resourceId);

const fileContent: ProjectCostSurfacesContent = {
costSurfaces: costSurfaces.map(({ id, ...costSurface }) => ({
costSurfaces: costSurfaces.map((costSurface) => ({
...costSurface,
data: costSurfaceData
.filter(
(data: CostSurfaceDataSelectResult) => data.cost_surface_id === id,
(data: CostSurfaceDataSelectResult) =>
data.cost_surface_id === costSurface.id,
)
.map(({ cost_surface_id, projects_pu_id, ...data }) => {
const puid = projectPusMap[projects_pu_id];
return { puid, ...data };
}),
.map(
({
cost_surface_id: _cost_surface_id,
projects_pu_id,
...data
}) => {
const puid = projectPusMap[projects_pu_id];
return { puid, ...data };
},
),
})),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
} from '../pieces/export-piece-processor';

type SelectResult = {
lockin_status?: 1 | 2;
lockin_status?: 0 | 1 | 2;
lock_status_set_by_user?: boolean;
xloc?: number;
yloc?: number;
protected_area?: number;
Expand Down Expand Up @@ -74,6 +75,7 @@ export class ScenarioPlanningUnitsDataPieceExporter
protectedByDefault: row.protected_by_default,
puid: row.puid,
lockinStatus: row.lockin_status,
lockStatusSetByUser: row.lock_status_set_by_user,
xloc: row.xloc,
yloc: row.yloc,
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export class ScenarioPlanningUnitsDataPieceImporter
featureList: puData.featureList,
projectPuId: projectPuIdByPuid[puData.puid],
lockStatus: toLockEnum[puData.lockinStatus ?? 0],
lockStatusSetByUser: puData.lockStatusSetByUser,
protectedArea: puData.protectedArea,
protectedByDefault: puData.protectedByDefault,
xloc: puData.xloc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class ScenarioPlanningUnitsInclusionProcessor
},
{
lockStatus: LockStatus.Available,
setByUser: false,
lockStatusSetByUser: false,
},
);

Expand All @@ -207,7 +207,7 @@ export class ScenarioPlanningUnitsInclusionProcessor
},
{
lockStatus: LockStatus.LockedIn,
setByUser: false,
lockStatusSetByUser: false,
},
);

Expand All @@ -219,7 +219,7 @@ export class ScenarioPlanningUnitsInclusionProcessor
},
{
lockStatus: LockStatus.LockedIn,
setByUser: true,
lockStatusSetByUser: true,
},
);

Expand All @@ -231,7 +231,7 @@ export class ScenarioPlanningUnitsInclusionProcessor
},
{
lockStatus: LockStatus.LockedOut,
setByUser: true,
lockStatusSetByUser: true,
},
);

Expand All @@ -243,7 +243,7 @@ export class ScenarioPlanningUnitsInclusionProcessor
},
{
lockStatus: LockStatus.Available,
setByUser: true,
lockStatusSetByUser: true,
},
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export const createWorld = async (app: INestApplication) => {
where: {
scenarioId,
lockStatus: LockStatus.LockedIn,
setByUser: true,
lockStatusSetByUser: true,
},
})
)
Expand All @@ -252,7 +252,7 @@ export const createWorld = async (app: INestApplication) => {
scenarioId,
lockStatus: LockStatus.LockedIn,
protectedByDefault: true,
setByUser: false,
lockStatusSetByUser: false,
},
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export const scenarioPlanningUnitsDataRelativePath = `scenario-pu-data.json`;
type PlanningUnitData = {
puid: number;
cost: number;
lockinStatus?: 1 | 2;
lockinStatus?: 0 | 1 | 2;
lockStatusSetByUser?: boolean;
xloc?: number;
yloc?: number;
protectedArea?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@ export class ScenariosPlanningUnitGeoEntity {
@PrimaryGeneratedColumn('uuid')
id!: string;

/**
* missing FK
*/
@PrimaryColumn({
type: 'uuid',
name: 'project_pu_id',
})
projectPuId!: string;

/**
* missing FK
* Matches (apidb)scenarios.id
*/
@Column({
type: 'uuid',
Expand All @@ -57,12 +54,12 @@ export class ScenariosPlanningUnitGeoEntity {
name: 'lockin_status',
transformer: {
from(value: number | null): LockStatus {
if (value !== null && (value === 1 || value === 2)) {
if (value !== null && (value === 0 || value === 1 || value === 2)) {
return toLockEnum[value];
}
return LockStatus.Available;
},
to(value: LockStatus): null | 1 | 2 {
to(value: LockStatus): null | 0 | 1 | 2 {
return fromLockEnum[value];
},
},
Expand All @@ -80,7 +77,7 @@ export class ScenariosPlanningUnitGeoEntity {
default: false,
name: `lock_status_set_by_user`,
})
setByUser!: boolean;
lockStatusSetByUser!: boolean;

@Column({
type: 'float8',
Expand Down

0 comments on commit fbb9532

Please sign in to comment.