Skip to content

Commit

Permalink
Fes 107 create the quick api to create menu item for testing (#105)
Browse files Browse the repository at this point in the history
* change db, create dtos and route

* add logic to create menu item

---------

Co-authored-by: NHT <[email protected]>
  • Loading branch information
nfesta2023 and hoangtuan910 authored Apr 8, 2024
1 parent 05092a9 commit 4cebb8e
Show file tree
Hide file tree
Showing 12 changed files with 641 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

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

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE Menu_Item
ADD COLUMN standard_price INT NULL AFTER units_sold;
`);

await queryRunner.query(`ALTER TABLE Menu_Item
ADD COLUMN min_price INT NULL AFTER standard_price,
ADD COLUMN max_price INT NULL AFTER min_price;
`);

await queryRunner.query(`ALTER TABLE Menu_Item_Attribute_Value
ADD COLUMN price_variance INT NULL AFTER note,
ADD COLUMN is_standard TINYINT NULL AFTER price_variance;`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE Menu_Item
DROP COLUMN standard_price;
`);

await queryRunner.query(`ALTER TABLE Menu_Item
DROP COLUMN max_price,
DROP COLUMN min_price;
`);

await queryRunner.query(`ALTER TABLE Menu_Item_Attribute_Value
DROP COLUMN is_standard,
DROP COLUMN price_variance;`);
}
}
1 change: 0 additions & 1 deletion src/dependency/momo/momo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ export class MomoService {
throw new CustomRpcException(201, error.response?.data);
}
const momoOrderResult = response.data;
this.logger.debug('momoOrderResult: ', momoOrderResult);
if (momoOrderResult.resultCode === 0) {
// ABLE TO CALL API MOMO AND GET SUCESSFUL RESPONSE
const momoResult = {
Expand Down
18 changes: 18 additions & 0 deletions src/entity/menu-item-attribute-ingredient.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Entity, PrimaryColumn, CreateDateColumn } from 'typeorm';

@Entity('Menu_Item_Attribute_Ingredient')
export class MenuItemAttributeIngredient {
@PrimaryColumn()
public attribute_id: number;

@PrimaryColumn()
public ingredient_id: number;

@CreateDateColumn({
type: 'datetime',
nullable: false,
unique: false,
default: () => 'CURRENT_TIMESTAMP',
})
public created_at: Date;
}
6 changes: 6 additions & 0 deletions src/entity/menu-item-attribute-value.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export class MenuItemAttributeValue {
@Column({ type: 'varchar', length: 255, nullable: true, unique: false })
public note: string;

@Column({ type: 'int', nullable: true, unique: false })
public price_variance: number;

@Column({ type: 'tinyint', nullable: true, unique: false })
public is_standard: number;

@CreateDateColumn({
type: 'datetime',
nullable: false,
Expand Down
9 changes: 9 additions & 0 deletions src/entity/menu-item.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ export class MenuItem {
@Column({ type: 'int', nullable: true, unique: false })
public units_sold: number;

@Column({ type: 'int', nullable: true, unique: false })
public standard_price: number;

@Column({ type: 'int', nullable: true, unique: false })
public min_price: number;

@Column({ type: 'int', nullable: true, unique: false })
public max_price: number;

@CreateDateColumn({
type: 'datetime',
nullable: false,
Expand Down
6 changes: 3 additions & 3 deletions src/entity/sku.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class SKU {
nullable: true,
unique: false,
})
public protein_g: number;
public protein_g: string;

@Column({
type: 'decimal',
Expand All @@ -66,7 +66,7 @@ export class SKU {
nullable: true,
unique: false,
})
public fat_g: number;
public fat_g: string;

@Column({
type: 'decimal',
Expand All @@ -75,7 +75,7 @@ export class SKU {
nullable: true,
unique: false,
})
public carbohydrate_g: number;
public carbohydrate_g: string;

@CreateDateColumn({
type: 'datetime',
Expand Down
80 changes: 80 additions & 0 deletions src/feature/food/dto/create-menu-item-request.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
enum IsoLangCode {
VIE = 'vie',
ENG = 'eng',
}

export interface RecipeItem {
ingredient_id: number;

quantity: number;

unit_id: number;
}

interface PortionCustomizationValue {
value: number;

unit_id: number;

price_variance: number; //Can be negative

is_standard: boolean;
}

export interface PortionCustomizationItem {
name: string;

corresponding_ingredients: number[];

value: PortionCustomizationValue[];
}

export interface PriceSetting {
standard: number;
min: number;
max: number;
}
export interface TasteCustomizationItem {
taste_id: string;
taste_values: string[];
}

export class CreateMenuItemRequest {
restaurant_id: number; //REQUIRED

ISO_language_code: IsoLangCode; //REQUIRED

name: string; //REQUIRED

short_name: string; //REQUIRED

description: string; //REQUIRED

main_cooking_method: string; //REQUIRED

preparing_time_minutes: number; //REQUIRED

cooking_time_minutes: number; //REQUIRED

is_vegetarian: boolean; //REQUIRED

res_category_id: number; //REQUIRED

image_url: string; //REQUIRED

other_image_url: string[]; //OPTIONAL

basic_customization: string[]; //REQUIRED

recipe: RecipeItem[]; //REQUIRED

portion_customization: PortionCustomizationItem[]; //REQUIRED

price: PriceSetting; //REQUIRED

taste_customization: TasteCustomizationItem[]; //REQUIRED

packaging: number[]; //REQUIRED

secret_key: string; //OPTIONAL
}
3 changes: 3 additions & 0 deletions src/feature/food/dto/create-menu-item-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class CreateMenuItemResponse {
message: string;
}
50 changes: 50 additions & 0 deletions src/feature/food/food.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { GetAvailableFoodByRestaurantResponse } from './dto/get-available-food-b
import { GetSimilarFoodRequest } from './dto/get-similar-food-request.dto';
import { GetSimilarFoodResponse } from './dto/get-similar-food-response.dto';
import { CustomRpcExceptionFilter } from 'src/filters/custom-rpc-exception.filter';
import { CreateMenuItemRequest } from './dto/create-menu-item-request.dto';
import { CreateMenuItemResponse } from './dto/create-menu-item-response.dto';

@Controller()
export class FoodController {
Expand Down Expand Up @@ -106,4 +108,52 @@ export class FoodController {
);
return await this.foodService.buildSimilarFoodResponse(similarMenuItemIds);
}

@MessagePattern({ cmd: 'create_menu_item_from_restaurant' })
@UseFilters(new CustomRpcExceptionFilter())
async createMenuItemFromRestaurant(
data: CreateMenuItemRequest,
): Promise<CreateMenuItemResponse> {
const {
restaurant_id,
ISO_language_code,
name,
short_name,
description,
main_cooking_method,
preparing_time_minutes,
cooking_time_minutes,
is_vegetarian,
res_category_id,
image_url,
other_image_url = [],
basic_customization,
recipe,
portion_customization,
price,
taste_customization,
packaging,
} = data;
await this.foodService.createMenuItemFromRestaurant(
restaurant_id,
ISO_language_code,
name,
short_name,
description,
main_cooking_method,
preparing_time_minutes,
cooking_time_minutes,
is_vegetarian,
res_category_id,
image_url,
other_image_url,
basic_customization,
recipe,
portion_customization,
price,
taste_customization,
packaging,
);
return { message: 'create menu item successfullly' };
}
}
Loading

0 comments on commit 4cebb8e

Please sign in to comment.