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

Feat/metadata adjustments #16

Merged
merged 41 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
683ac28
feat: Menu template field and migration
Feb 15, 2023
27ca894
feat: MenuItem template field and migration
Feb 15, 2023
e6c958b
feat: TemplateFormat enum
Feb 15, 2023
d928277
feat: Menu templateFormat field and migration
Feb 15, 2023
0d5137c
feat: MenuItem templateFormat field and migration
Feb 15, 2023
7df12e1
feat: UpdateMenuInput template and templateFormat fields
Feb 15, 2023
765cdf1
feat: UpdateMenuInput and UpdateMenuItemInput template and templateFo…
Feb 15, 2023
b0e3be7
feat: MenuItem cascade on update and delete parent
Feb 16, 2023
aaa8a9f
feat: MenuMeta object
Feb 16, 2023
f006fe2
refactor: Meta scalar -> MenuMeta object
Feb 16, 2023
bc7ec29
refactor: MenuItemAction -> InputAction
Feb 16, 2023
77b9d25
feat: menu meta inputs
Feb 16, 2023
7bfb5d4
feat: MenusService create meta with ids
Feb 17, 2023
bd93d42
feat: MenusService update handle meta
Feb 17, 2023
c9c055b
feat: MenuSubscriber beforeInsert and beforeUpdate validate meta uniq…
Feb 17, 2023
00cc3d8
fix: meta ids generation
Feb 17, 2023
ba4544d
fix: UpdateMenuMetaInput nullable fields
Feb 17, 2023
bd04876
feat: Menu meta types cannot be changed validation on update
Feb 17, 2023
ad50714
fix: Menu meta validation on update
Feb 17, 2023
b1c4f09
fix: Menu meta nullable
Feb 17, 2023
6fe6919
feat: IMenuItemMeta key -> index
Feb 17, 2023
65dbb9e
feat: MenuItem meta nullable
Feb 17, 2023
cab010c
fix: MenuItems menuId not nullable
Feb 17, 2023
df17acd
feat: CreateMenuItemInput meta nullable
Feb 17, 2023
96920dd
fix: setting menuId and menu for every MenuItem on MenuSubscriber aft…
Feb 17, 2023
6198a9d
refactor: MenuItemsService update -> save
Feb 17, 2023
2c73d05
feat: MenuItemSubscriber set meta ids before insert and update
Feb 17, 2023
d7be976
fix: MenuItem create and update inputs enabled validation
Feb 17, 2023
c997e43
feat: MenuItem service and subscriber with new meta
Feb 17, 2023
74a4b35
feat: MenuItemSubscriber validateMeta with correct error response
Feb 18, 2023
f608ec8
feat: MenuSubscriber validate meta return constraints
Feb 18, 2023
13e5ed7
feat: MenuItemSubscriber validateMenuItem label and order isUnique va…
Feb 18, 2023
68867d6
feat: Menu create cascade creation of MenuItem children
Feb 18, 2023
182f8e8
feat: MenuMeta enabled field
Feb 18, 2023
78e2617
fix: MenuSubscriber meta validation
Feb 19, 2023
41cce07
fix: MenuSubscriber delete meta
Feb 19, 2023
63b6f17
fix: MenusService update items filter current item from siblings
Feb 19, 2023
a890174
fix: MenuItemSubscriber beforeUpdate infinite loop
Feb 19, 2023
37c31fd
fix: MenuItemSubscriber validateMenuItem filter delete action
Feb 19, 2023
3ae6e7c
fix: MenuSubscriber beforeUpdate updatedMeta had no default value for…
Feb 19, 2023
5df9ac8
fix: MenuItemSubscriber validate required meta only when meta is enabled
Feb 19, 2023
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
13 changes: 13 additions & 0 deletions migrations/1676498966137-AddTemplateToMenu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

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

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`menus\` ADD \`template\` text NULL`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`menus\` DROP COLUMN \`template\``);
}
}
17 changes: 17 additions & 0 deletions migrations/1676499215895-AddTemplateToMenuItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

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

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`menu_items\` ADD \`template\` text NULL`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`menu_items\` DROP COLUMN \`template\``,
);
}
}
19 changes: 19 additions & 0 deletions migrations/1676500037896-AddTemplateFormatToMenu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

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

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`menus\` ADD \`template_format\` text NULL`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`menus\` DROP COLUMN \`template_format\``,
);
}
}
19 changes: 19 additions & 0 deletions migrations/1676500338399-AddTemplateFormatToMenuItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

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

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`menu_items\` ADD \`template_format\` text NULL`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`menu_items\` DROP COLUMN \`template_format\``,
);
}
}
25 changes: 25 additions & 0 deletions migrations/1676580016840-AddCascadeConstraintsToMenuItemParent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

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

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`menu_items\` DROP FOREIGN KEY \`FK_8e20ca40202c116fdafe92cdc4e\``,
);
await queryRunner.query(
`ALTER TABLE \`menu_items\` ADD CONSTRAINT \`FK_8e20ca40202c116fdafe92cdc4e\` FOREIGN KEY (\`parent_id\`) REFERENCES \`menu_items\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`menu_items\` DROP FOREIGN KEY \`FK_8e20ca40202c116fdafe92cdc4e\``,
);
await queryRunner.query(
`ALTER TABLE \`menu_items\` ADD CONSTRAINT \`FK_8e20ca40202c116fdafe92cdc4e\` FOREIGN KEY (\`parent_id\`) REFERENCES \`menu_items\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
}
}
17 changes: 17 additions & 0 deletions migrations/1676608475006-AddNullableMetaToMenu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

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

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`menus\` CHANGE \`meta\` \`meta\` text NULL`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`menus\` CHANGE \`meta\` \`meta\` text NOT NULL`,
);
}
}
19 changes: 19 additions & 0 deletions migrations/1676609999446-AddNullableMetaToMenuItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

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

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`menu_items\` CHANGE \`meta\` \`meta\` text NULL`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`menu_items\` CHANGE \`meta\` \`meta\` text NOT NULL`,
);
}
}
31 changes: 31 additions & 0 deletions migrations/1676619443659-AddNotNullableMenuToMenuItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

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

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`menu_items\` DROP FOREIGN KEY \`FK_ba71edc684a901b4bc9d9228f42\``,
);
await queryRunner.query(
`ALTER TABLE \`menu_items\` CHANGE \`menu_id\` \`menu_id\` int NOT NULL`,
);
await queryRunner.query(
`ALTER TABLE \`menu_items\` ADD CONSTRAINT \`FK_ba71edc684a901b4bc9d9228f42\` FOREIGN KEY (\`menu_id\`) REFERENCES \`menus\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`menu_items\` DROP FOREIGN KEY \`FK_ba71edc684a901b4bc9d9228f42\``,
);
await queryRunner.query(
`ALTER TABLE \`menu_items\` CHANGE \`menu_id\` \`menu_id\` int NULL`,
);
await queryRunner.query(
`ALTER TABLE \`menu_items\` ADD CONSTRAINT \`FK_ba71edc684a901b4bc9d9228f42\` FOREIGN KEY (\`menu_id\`) REFERENCES \`menus\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`,
);
}
}
5 changes: 5 additions & 0 deletions src/common/enums/template-format.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum TemplateFormat {
JSON = 'json',
XML = 'xml',
PLAIN = 'plain',
}
8 changes: 8 additions & 0 deletions src/common/errors/field-validation.error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ class FieldValidationError extends GraphQLError {

return new FieldValidationError(composeErrors(errors));
}

static constraints = {
IS_UNIQUE: 'isUnique',
// Menu Meta
META_TYPE_CANNOT_BE_CHANGED: 'metaTypeCannotBeChanged',
// Menu Item Meta
META_REQUIRED: 'metaRequired',
};
}

export default FieldValidationError;
8 changes: 8 additions & 0 deletions src/common/schema/enums/input-action.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { registerEnumType } from '@nestjs/graphql';

export enum InputAction {
CREATE = 'CREATE',
UPDATE = 'UPDATE',
DELETE = 'DELETE',
}
registerEnumType(InputAction, { name: 'InputAction' });
46 changes: 0 additions & 46 deletions src/common/schema/scalars/meta.scalar.ts

This file was deleted.

16 changes: 4 additions & 12 deletions src/common/types/model.type.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { InputAction } from '../schema/enums/input-action.enum';

export enum MenuMetaType {
TEXT = 'text',
NUMBER = 'number',
Expand All @@ -20,18 +22,8 @@ export enum MenuMetaType {
// OBJECT = 'object',
}

export interface IMenuMeta {
name: string;
required: boolean;
type: MenuMetaType;
}

export interface IMenuItemMeta {
[key: string]: unknown;
[index: number]: unknown;
}

export enum MenuItemAction {
CREATE = 'create',
UPDATE = 'update',
DELETE = 'delete',
}
export type WithAction<T> = T & { action?: InputAction };
25 changes: 19 additions & 6 deletions src/menu-items/entities/menu-item.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Field, Int, ObjectType } from '@nestjs/graphql';
import { TemplateFormat } from 'src/common/enums/template-format.enum';
import { GraphQLJSONObject } from 'src/common/schema/scalars/json.scalar';
import { IMenuItemMeta } from 'src/common/types';
import { Menu } from 'src/menus/entities/menu.entity';
Expand Down Expand Up @@ -26,11 +27,12 @@ export class MenuItem {
@Column()
order: number;

@Field(() => GraphQLJSONObject)
@Field(() => GraphQLJSONObject, { nullable: true })
@Column('text', {
nullable: true,
transformer: { from: JSON.parse, to: JSON.stringify },
})
meta: IMenuItemMeta;
meta?: IMenuItemMeta;

@Field(() => [MenuItem], { nullable: true })
@OneToMany(() => MenuItem, (menuItem) => menuItem.parent, {
Expand All @@ -39,7 +41,11 @@ export class MenuItem {
})
children?: MenuItem[];

@ManyToOne(() => MenuItem, (menuItem) => menuItem.children, { lazy: true })
@ManyToOne(() => MenuItem, (menuItem) => menuItem.children, {
lazy: true,
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
})
@JoinColumn()
parent?: MenuItem;

Expand All @@ -56,8 +62,8 @@ export class MenuItem {
@JoinColumn()
menu: Menu;

@Field(() => Int, { nullable: true })
@Column({ nullable: true })
@Field(() => Int)
@Column()
menuId?: number;

@Field(() => Boolean, { nullable: false })
Expand All @@ -71,5 +77,12 @@ export class MenuItem {
@Field(() => Date, { nullable: true })
@Column({ nullable: true })
endPublication?: Date;


@Field(() => String, { nullable: true })
@Column('text', { nullable: true })
template?: string;

@Field(() => String, { nullable: true })
@Column('text', { nullable: true })
templateFormat?: TemplateFormat;
}
Loading