Skip to content

Commit

Permalink
Merge pull request #14 from bancodobrasil/feat/add-new-fields
Browse files Browse the repository at this point in the history
Feat/add new fields
  • Loading branch information
ralphg6 authored Feb 9, 2023
2 parents fdbea8e + a5d3499 commit a112180
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
18 changes: 18 additions & 0 deletions migrations/1675881556357-AddDateAndEnabledFieldsToMenuItems.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class AddDateAndEnabledFieldsToMenuItems1675881556357 implements MigrationInterface {
name = 'AddDateAndEnabledFieldsToMenuItems1675881556357'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`menu_items\` ADD \`enabled\` tinyint NOT NULL`);
await queryRunner.query(`ALTER TABLE \`menu_items\` ADD \`start_publication\` datetime NULL`);
await queryRunner.query(`ALTER TABLE \`menu_items\` ADD \`end_publication\` datetime NULL`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`menu_items\` DROP COLUMN \`end_publication\``);
await queryRunner.query(`ALTER TABLE \`menu_items\` DROP COLUMN \`start_publication\``);
await queryRunner.query(`ALTER TABLE \`menu_items\` DROP COLUMN \`enabled\``);
}

}
13 changes: 13 additions & 0 deletions src/menu-items/entities/menu-item.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,17 @@ export class MenuItem {
@Field(() => Int, { nullable: true })
@Column({ nullable: true })
menuId?: number;

@Field(() => Boolean, { nullable: false })
@Column({ nullable: false })
enabled: boolean;

@Field(() => Date, { nullable: true })
@Column({ nullable: true })
startPublication?: Date;

@Field(() => Date, { nullable: true })
@Column({ nullable: true })
endPublication?: Date;

}
17 changes: 17 additions & 0 deletions src/menu-items/inputs/create-menu-item.input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Field, InputType, Int } from '@nestjs/graphql';
import { Type } from 'class-transformer';
import {
IsArray,
IsDate,
IsDefined,
IsObject,
IsOptional,
Expand Down Expand Up @@ -38,4 +39,20 @@ export class CreateMenuItemInput {
@ValidateNested({ each: true })
@Type(() => CreateMenuItemInput)
children?: CreateMenuItemInput[];

@Field(() => Boolean, { nullable: false })
@IsOptional()
enabled?: boolean;

@Field(() => Date, { nullable: true })
@IsDate()
@IsOptional()
startPublication?: Date;


@Field(() => Date, { nullable: true })
@IsDate()
@IsOptional()
endPublication?: Date;

}
14 changes: 14 additions & 0 deletions src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,21 @@ type MenuItem {
children: [MenuItem!]
parentId: Int
menuId: Int
enabled: Boolean!
startPublication: DateTime
endPublication: DateTime
}

"""
The `JSONObject` scalar type represents JSON objects as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).
"""
scalar JSONObject

"""
A date-time string at UTC, such as 2019-12-03T09:54:33Z, compliant with the date-time format.
"""
scalar DateTime

type Query {
menus(first: Int, after: String, last: Int, before: String, sort: MenuSort, direction: Direction): MenuConnection!
menu(id: Int!): Menu!
Expand Down Expand Up @@ -80,6 +88,9 @@ input CreateMenuItemInput {
meta: JSONObject!
parentId: Int
children: [CreateMenuItemInput!]
enabled: Boolean!
startPublication: DateTime
endPublication: DateTime
}

input UpdateMenuInput {
Expand All @@ -94,6 +105,9 @@ input UpdateMenuItemInput {
order: Int
meta: JSONObject
parentId: Int
enabled: Boolean
startPublication: DateTime
endPublication: DateTime
action: String!
id: Int
children: [UpdateMenuItemInput!]
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3066,7 +3066,7 @@ cjs-module-lexer@^1.0.0:

class-transformer@^0.5.1:
version "0.5.1"
resolved "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz"
resolved "https://registry.yarnpkg.com/class-transformer/-/class-transformer-0.5.1.tgz#24147d5dffd2a6cea930a3250a677addf96ab336"
integrity sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==

class-validator@^0.14.0:
Expand Down

0 comments on commit a112180

Please sign in to comment.