Fixed: Add new modifier category error
This commit is contained in:
parent
4e3362c614
commit
9b55d037f2
@ -42,7 +42,7 @@ def save(
|
||||
item = ModifierCategory(
|
||||
name=data.name,
|
||||
minimum=data.minimum,
|
||||
maximum=data.maximum,
|
||||
maximum=None if data.maximum == 0 else data.maximum,
|
||||
is_active=data.is_active,
|
||||
)
|
||||
db.add(item)
|
||||
@ -72,7 +72,7 @@ def update(
|
||||
item: ModifierCategory = db.query(ModifierCategory).filter(ModifierCategory.id == id_).first()
|
||||
item.name = data.name
|
||||
item.minimum = data.minimum
|
||||
item.maximum = data.maximum
|
||||
item.maximum = None if data.maximum == 0 else data.maximum
|
||||
item.is_active = data.is_active
|
||||
add_products(item, data.menu_categories, db)
|
||||
db.commit()
|
||||
@ -88,13 +88,13 @@ def update(
|
||||
raise
|
||||
|
||||
|
||||
@router.delete("/{id_}", response_model=schemas.ModifierCategoryIn)
|
||||
@router.delete("/{id_}", response_model=schemas.ModifierCategoryBlank)
|
||||
def delete(
|
||||
id_: uuid.UUID,
|
||||
date_: date = Depends(effective_date),
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["modifiers"]),
|
||||
) -> schemas.ModifierCategoryIn:
|
||||
) -> schemas.ModifierCategoryBlank:
|
||||
try:
|
||||
item: ModifierCategory = db.query(ModifierCategory).filter(ModifierCategory.id == id_).first()
|
||||
db.delete(item)
|
||||
@ -111,13 +111,13 @@ def delete(
|
||||
raise
|
||||
|
||||
|
||||
@router.get("", response_model=schemas.ModifierCategoryIn)
|
||||
@router.get("", response_model=schemas.ModifierCategoryBlank)
|
||||
def show_blank(
|
||||
db: Session = Depends(get_db),
|
||||
date_: date = Depends(effective_date),
|
||||
user: UserToken = Security(get_user, scopes=["modifiers"]),
|
||||
) -> schemas.ModifierCategoryIn:
|
||||
return modifier_category_info(date_, db=db)
|
||||
) -> schemas.ModifierCategoryBlank:
|
||||
return modifier_category_blank(date_, db=db)
|
||||
|
||||
|
||||
@router.get("/list")
|
||||
@ -259,7 +259,7 @@ def modifier_category_info(item: ModifierCategory, date_: date, db: Session) ->
|
||||
)
|
||||
|
||||
|
||||
def modifier_category_blank(date_: date, db: Session) -> schemas.ModifierCategoryIn:
|
||||
def modifier_category_blank(date_: date, db: Session) -> schemas.ModifierCategoryBlank:
|
||||
menu_categories = (
|
||||
db.query(MenuCategory)
|
||||
.join(MenuCategory.products)
|
||||
@ -282,7 +282,7 @@ def modifier_category_blank(date_: date, db: Session) -> schemas.ModifierCategor
|
||||
)
|
||||
.all()
|
||||
)
|
||||
return schemas.ModifierCategoryIn(
|
||||
return schemas.ModifierCategoryBlank(
|
||||
name="",
|
||||
minimum=0,
|
||||
maximum=0,
|
||||
|
@ -16,7 +16,6 @@ class ModifierCategoryIn(BaseModel):
|
||||
menu_categories: Optional[List[MenuCategoryLink]]
|
||||
|
||||
class Config:
|
||||
fields = {"id_": "id"}
|
||||
anystr_strip_whitespace = True
|
||||
alias_generator = to_camel
|
||||
|
||||
@ -31,6 +30,14 @@ class ModifierCategory(ModifierCategoryIn):
|
||||
alias_generator = to_camel
|
||||
|
||||
|
||||
class ModifierCategoryBlank(ModifierCategoryIn):
|
||||
name: str
|
||||
|
||||
class Config:
|
||||
anystr_strip_whitespace = True
|
||||
alias_generator = to_camel
|
||||
|
||||
|
||||
class ModifierCategoryLink(BaseModel):
|
||||
id_: uuid.UUID = Field(...)
|
||||
name: Optional[str]
|
||||
|
Loading…
x
Reference in New Issue
Block a user