Skip to content

Commit

Permalink
Merge pull request #17 from purwadhikafullstack/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
jordansmrd authored Jul 17, 2024
2 parents 02b6981 + b599b2f commit b6ac563
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 5 additions & 0 deletions apps/api/src/actions/discount.action.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DISCOUNT_UNIT } from "@/constants/discount.constant";
import { HttpException } from '@/exceptions/HttpException';
import {
IDiscount,
Expand All @@ -19,6 +20,10 @@ const createDiscountAction = async (
discountData: IDiscount,
): Promise<Discount> => {
try {
if (discountData.unit === DISCOUNT_UNIT.percentage && discountData.amount > 100) {
throw new Error("Amount can not more than 100%");
}

const discount = await createDiscountQuery(discountData);
return discount;
} catch (err) {
Expand Down
8 changes: 8 additions & 0 deletions apps/api/src/constants/discount.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ export const DISCOUNT_TYPE: {
buy1Get1: "Buy 1 Get 1",
freeShipping: "Free Shipping",
referralCode: "Referral Code",
}

export const DISCOUNT_UNIT: {
amount: string;
percentage: string;
} = {
amount: "Amount",
percentage: "Percentage",
}
9 changes: 1 addition & 8 deletions apps/web/src/app/admin/(store-admin)/discounts/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ const Page = () => {
<Card my={10}>
<CardBody>
<Flex gap={4} pb={8}>
<Input
placeholder="Search..."
value={filters.keyword}
onChange={(e) =>
setFilters({ ...filters, keyword: e.target.value, page: 1 })
}
/>
<Input
placeholder="Search..."
value={filters.keyword}
Expand Down Expand Up @@ -169,7 +162,7 @@ const Page = () => {
<Button
colorScheme="blue"
onClick={() => {
router.push(`/admin/stores/discounts`);
router.push(`/admin/discounts/edit/${discount.id}`);
}}
>
Edit
Expand Down

0 comments on commit b6ac563

Please sign in to comment.