Skip to content
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
@@ -0,0 +1,19 @@
import { type MigrationInterface, type QueryRunner } from 'typeorm';

export class ChangeNavigationMenuItemPositionToDoublePrecision1771499112046
implements MigrationInterface
{
name = 'ChangeNavigationMenuItemPositionToDoublePrecision1771499112046';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "core"."navigationMenuItem" ALTER COLUMN "position" TYPE double precision`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "core"."navigationMenuItem" ALTER COLUMN "position" TYPE integer`,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class NavigationMenuItemEntity
@Column({ nullable: true, type: 'uuid' })
folderId: string | null;

@Column({ nullable: false })
@Column({ nullable: false, type: 'double precision' })
position: number;

@CreateDateColumn({ type: 'timestamptz' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,12 @@ export class FlatNavigationMenuItemValidatorService {

if (
isDefined(flatNavigationMenuItem.position) &&
(!Number.isInteger(flatNavigationMenuItem.position) ||
flatNavigationMenuItem.position < 0)
!Number.isFinite(flatNavigationMenuItem.position)
) {
validationResult.errors.push({
code: NavigationMenuItemExceptionCode.INVALID_NAVIGATION_MENU_ITEM_INPUT,
message: t`Position must be a non-negative integer`,
userFriendlyMessage: msg`Position must be a non-negative integer`,
message: t`Position must be a finite number`,
userFriendlyMessage: msg`Position must be a finite number`,
});
}

Expand Down Expand Up @@ -307,14 +306,11 @@ export class FlatNavigationMenuItemValidatorService {

const positionUpdate = flatEntityUpdate.position;

if (
isDefined(positionUpdate) &&
(!Number.isInteger(positionUpdate) || positionUpdate < 0)
) {
if (isDefined(positionUpdate) && !Number.isFinite(positionUpdate)) {
validationResult.errors.push({
code: NavigationMenuItemExceptionCode.INVALID_NAVIGATION_MENU_ITEM_INPUT,
message: t`Position must be a non-negative integer`,
userFriendlyMessage: msg`Position must be a non-negative integer`,
message: t`Position must be a finite number`,
userFriendlyMessage: msg`Position must be a finite number`,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,3 @@ exports[`NavigationMenuItem creation should fail when creating with missing targ
}
`;

exports[`NavigationMenuItem creation should fail when creating with negative position 1`] = `
{
"extensions": {
"code": "NOT_FOUND",
"subCode": "RELATION_UNIVERSAL_IDENTIFIER_NOT_FOUND",
"userFriendlyMessage": "An error occurred.",
},
"message": "Could not find objectMetadata for given targetObjectMetadataId",
"name": "NotFoundError",
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -71,38 +71,3 @@ exports[`NavigationMenuItem update should fail when updating with missing id 1`]
"name": "ValidationError",
}
`;

exports[`NavigationMenuItem update should fail when updating with negative position 1`] = `
{
"extensions": {
"code": "METADATA_VALIDATION_FAILED",
"errors": {
"navigationMenuItem": [
{
"errors": [
{
"code": "INVALID_NAVIGATION_MENU_ITEM_INPUT",
"message": "Position must be a non-negative integer",
"userFriendlyMessage": "Position must be a non-negative integer",
},
],
"flatEntityMinimalInformation": {
"universalIdentifier": Any<String>,
},
"metadataName": "navigationMenuItem",
"status": "fail",
"type": "update",
},
],
},
"message": "Validation failed for 1 navigationMenuItem",
"summary": {
"navigationMenuItem": 1,
"totalErrors": 1,
},
"userFriendlyMessage": "Metadata validation failed",
},
"message": "Multiple validation errors occurred while updating navigation menu item",
"name": "GraphQLError",
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,6 @@ const failingNavigationMenuItemCreationTestCases: EachTestingContext<TestContext
},
},
},
{
title: 'when creating with negative position',
context: {
input: {
targetRecordId: faker.string.uuid(),
targetObjectMetadataId: faker.string.uuid(),
position: -1,
},
},
},
];

describe('NavigationMenuItem creation should fail', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,6 @@ describe('NavigationMenuItem update should fail', () => {
}),
},
},
{
title: 'when updating with negative position',
context: {
input: (testSetup) => ({
id: testSetup.testNavigationMenuItemId,
update: {
position: -1,
},
}),
},
},
];

it.each(eachTestingContextFilter(failingNavigationMenuItemUpdateTestCases))(
Expand Down