-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from TEDx-SJEC/discount
Discount
- Loading branch information
Showing
10 changed files
with
170 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `discountPercentage` to the `Referral` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- RedefineTables | ||
PRAGMA defer_foreign_keys=ON; | ||
PRAGMA foreign_keys=OFF; | ||
CREATE TABLE "new_Referral" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"code" TEXT NOT NULL, | ||
"discountPercentage" TEXT NOT NULL, | ||
"createdby_id" TEXT NOT NULL, | ||
"usedby_id" TEXT, | ||
"isUsed" BOOLEAN NOT NULL DEFAULT false, | ||
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
CONSTRAINT "Referral_createdby_id_fkey" FOREIGN KEY ("createdby_id") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE, | ||
CONSTRAINT "Referral_usedby_id_fkey" FOREIGN KEY ("usedby_id") REFERENCES "User" ("id") ON DELETE SET NULL ON UPDATE CASCADE | ||
); | ||
INSERT INTO "new_Referral" ("code", "created_at", "createdby_id", "id", "isUsed", "usedby_id") SELECT "code", "created_at", "createdby_id", "id", "isUsed", "usedby_id" FROM "Referral"; | ||
DROP TABLE "Referral"; | ||
ALTER TABLE "new_Referral" RENAME TO "Referral"; | ||
CREATE UNIQUE INDEX "Referral_code_key" ON "Referral"("code"); | ||
PRAGMA foreign_keys=ON; | ||
PRAGMA defer_foreign_keys=OFF; |
26 changes: 26 additions & 0 deletions
26
prisma/migrations/20240917061033_discount_percentage/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `discountPercentage` on the `Referral` table. All the data in the column will be lost. | ||
*/ | ||
-- RedefineTables | ||
PRAGMA defer_foreign_keys=ON; | ||
PRAGMA foreign_keys=OFF; | ||
CREATE TABLE "new_Referral" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"code" TEXT NOT NULL, | ||
"discount_percentage" TEXT NOT NULL DEFAULT '20', | ||
"createdby_id" TEXT NOT NULL, | ||
"usedby_id" TEXT, | ||
"isUsed" BOOLEAN NOT NULL DEFAULT false, | ||
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
CONSTRAINT "Referral_createdby_id_fkey" FOREIGN KEY ("createdby_id") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE, | ||
CONSTRAINT "Referral_usedby_id_fkey" FOREIGN KEY ("usedby_id") REFERENCES "User" ("id") ON DELETE SET NULL ON UPDATE CASCADE | ||
); | ||
INSERT INTO "new_Referral" ("code", "created_at", "createdby_id", "id", "isUsed", "usedby_id") SELECT "code", "created_at", "createdby_id", "id", "isUsed", "usedby_id" FROM "Referral"; | ||
DROP TABLE "Referral"; | ||
ALTER TABLE "new_Referral" RENAME TO "Referral"; | ||
CREATE UNIQUE INDEX "Referral_code_key" ON "Referral"("code"); | ||
PRAGMA foreign_keys=ON; | ||
PRAGMA defer_foreign_keys=OFF; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
"use server"; | ||
import prisma from "@/server/db"; | ||
|
||
export const saveCoupon = async (coupon: string, id: string) => { | ||
export const saveCoupon = async (coupon: string, id: string, discount: string = "20") => { | ||
const resp = await prisma.referral.create({ | ||
data: { | ||
code: coupon, | ||
isUsed: false, | ||
createdById: id, | ||
discountPercentage: discount, | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"use client" | ||
|
||
import * as React from "react" | ||
import * as CheckboxPrimitive from "@radix-ui/react-checkbox" | ||
import { CheckIcon } from "@radix-ui/react-icons" | ||
|
||
import { cn } from "@/lib/utils" | ||
|
||
const Checkbox = React.forwardRef< | ||
React.ElementRef<typeof CheckboxPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root> | ||
>(({ className, ...props }, ref) => ( | ||
<CheckboxPrimitive.Root | ||
ref={ref} | ||
className={cn( | ||
"peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground", | ||
className | ||
)} | ||
{...props} | ||
> | ||
<CheckboxPrimitive.Indicator | ||
className={cn("flex items-center justify-center text-current")} | ||
> | ||
<CheckIcon className="h-4 w-4" /> | ||
</CheckboxPrimitive.Indicator> | ||
</CheckboxPrimitive.Root> | ||
)) | ||
Checkbox.displayName = CheckboxPrimitive.Root.displayName | ||
|
||
export { Checkbox } |