Skip to content

Commit fd4bc4e

Browse files
committed
chore: update migrate table review
1 parent 1a02b8a commit fd4bc4e

File tree

4 files changed

+139
-26
lines changed

4 files changed

+139
-26
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `content` on the `Review` table. All the data in the column will be lost.
5+
- You are about to drop the column `createdById` on the `Review` table. All the data in the column will be lost.
6+
- You are about to drop the column `deletedAt` on the `Review` table. All the data in the column will be lost.
7+
- You are about to drop the column `deletedById` on the `Review` table. All the data in the column will be lost.
8+
- You are about to drop the column `revieweeId` on the `Review` table. All the data in the column will be lost.
9+
- You are about to drop the column `updatedById` on the `Review` table. All the data in the column will be lost.
10+
- Added the required column `productId` to the `Review` table without a default value. This is not possible if the table is not empty.
11+
- Added the required column `serviceSeller` to the `Review` table without a default value. This is not possible if the table is not empty.
12+
- Added the required column `serviceShip` to the `Review` table without a default value. This is not possible if the table is not empty.
13+
- Added the required column `userId` to the `Review` table without a default value. This is not possible if the table is not empty.
14+
15+
*/
16+
-- CreateEnum
17+
CREATE TYPE "public"."ReviewBadReason" AS ENUM ('DAMAGED_PRODUCT', 'FAKE_PRODUCT', 'NOT_AS_DESCRIBED', 'POOR_QUALITY');
18+
19+
-- DropForeignKey
20+
ALTER TABLE "public"."Review" DROP CONSTRAINT "Review_createdById_fkey";
21+
22+
-- DropForeignKey
23+
ALTER TABLE "public"."Review" DROP CONSTRAINT "Review_deletedById_fkey";
24+
25+
-- DropForeignKey
26+
ALTER TABLE "public"."Review" DROP CONSTRAINT "Review_revieweeId_fkey";
27+
28+
-- DropForeignKey
29+
ALTER TABLE "public"."Review" DROP CONSTRAINT "Review_updatedById_fkey";
30+
31+
-- DropIndex
32+
DROP INDEX "public"."Review_createdById_idx";
33+
34+
-- DropIndex
35+
DROP INDEX "public"."Review_revieweeId_idx";
36+
37+
-- AlterTable
38+
ALTER TABLE "public"."Product" ADD COLUMN "rating1Count" INTEGER NOT NULL DEFAULT 0,
39+
ADD COLUMN "rating2Count" INTEGER NOT NULL DEFAULT 0,
40+
ADD COLUMN "rating3Count" INTEGER NOT NULL DEFAULT 0,
41+
ADD COLUMN "rating4Count" INTEGER NOT NULL DEFAULT 0,
42+
ADD COLUMN "rating5Count" INTEGER NOT NULL DEFAULT 0;
43+
44+
-- AlterTable
45+
ALTER TABLE "public"."Review" DROP COLUMN "content",
46+
DROP COLUMN "createdById",
47+
DROP COLUMN "deletedAt",
48+
DROP COLUMN "deletedById",
49+
DROP COLUMN "revieweeId",
50+
DROP COLUMN "updatedById",
51+
ADD COLUMN "isAnonymous" BOOLEAN NOT NULL DEFAULT false,
52+
ADD COLUMN "message" TEXT,
53+
ADD COLUMN "productId" INTEGER NOT NULL,
54+
ADD COLUMN "reason" "public"."ReviewBadReason",
55+
ADD COLUMN "serviceSeller" INTEGER NOT NULL,
56+
ADD COLUMN "serviceShip" INTEGER NOT NULL,
57+
ADD COLUMN "skuId" INTEGER,
58+
ADD COLUMN "userId" INTEGER NOT NULL;
59+
60+
-- CreateIndex
61+
CREATE INDEX "Product_shopId_idx" ON "public"."Product"("shopId");
62+
63+
-- CreateIndex
64+
CREATE INDEX "Review_userId_idx" ON "public"."Review"("userId");
65+
66+
-- CreateIndex
67+
CREATE INDEX "Review_productId_idx" ON "public"."Review"("productId");
68+
69+
-- CreateIndex
70+
CREATE INDEX "Review_skuId_idx" ON "public"."Review"("skuId");

prisma/schema.prisma

Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,8 @@ model User {
104104
payments Payment[]
105105
messagesSent Message[] @relation("FromUser")
106106
messagesReceived Message[] @relation("ToUser")
107-
reviews Review[] @relation("Reviewer")
108-
deletedreviews Review[] @relation("ReviewDeletedBy")
109-
reviewees Review[] @relation("Reviewee")
110107
salesReports SellerSalesReport[]
111108
notifications Notification[]
112-
Review Review[]
113109
UserVoucher UserVoucher[]
114110
Transaction Transaction[]
115111
AddressLabel AddressLabel[]
@@ -370,8 +366,15 @@ model Product {
370366
images String[]
371367
/// [Variants]
372368
variants Json
369+
373370
rating Float? @default(0.0)
374371
ratingCount Int @default(0)
372+
rating1Count Int @default(0)
373+
rating2Count Int @default(0)
374+
rating3Count Int @default(0)
375+
rating4Count Int @default(0)
376+
rating5Count Int @default(0)
377+
375378
totalViews Int @default(0)
376379
slugId String @unique
377380
@@ -401,6 +404,7 @@ model Product {
401404
ProductSKUSnapshot ProductSKUSnapshot[]
402405
403406
@@index([deletedAt])
407+
@@index([shopId])
404408
}
405409

406410
model ProductLike {
@@ -795,29 +799,29 @@ model BannerDesign {
795799
@@index([shopId])
796800
}
797801

798-
model Review {
799-
id Int @id @default(autoincrement())
800-
revieweeId Int
801-
orderItemId Int @unique
802-
rating Int
803-
content String
804-
images String[]
805-
reviewee User @relation("Reviewee", fields: [revieweeId], references: [id], onDelete: Cascade, onUpdate: NoAction)
802+
// model Review {
803+
// id Int @id @default(autoincrement())
804+
// revieweeId Int
805+
// orderItemId Int @unique
806+
// rating Int
807+
// content String
808+
// images String[]
809+
// reviewee User @relation("Reviewee", fields: [revieweeId], references: [id], onDelete: Cascade, onUpdate: NoAction)
806810

807-
createdById Int
808-
createdBy User @relation("Reviewer", fields: [createdById], references: [id], onDelete: Cascade, onUpdate: NoAction)
809-
updatedById Int?
810-
updatedBy User? @relation(fields: [updatedById], references: [id], onDelete: Cascade, onUpdate: NoAction)
811-
deletedById Int?
812-
deletedBy User? @relation("ReviewDeletedBy", fields: [deletedById], references: [id], onDelete: Cascade, onUpdate: NoAction)
811+
// createdById Int
812+
// createdBy User @relation("Reviewer", fields: [createdById], references: [id], onDelete: Cascade, onUpdate: NoAction)
813+
// updatedById Int?
814+
// updatedBy User? @relation(fields: [updatedById], references: [id], onDelete: Cascade, onUpdate: NoAction)
815+
// deletedById Int?
816+
// deletedBy User? @relation("ReviewDeletedBy", fields: [deletedById], references: [id], onDelete: Cascade, onUpdate: NoAction)
813817

814-
deletedAt DateTime?
815-
createdAt DateTime @default(now())
816-
updatedAt DateTime @updatedAt
818+
// deletedAt DateTime?
819+
// createdAt DateTime @default(now())
820+
// updatedAt DateTime @updatedAt
817821

818-
@@index([revieweeId])
819-
@@index([createdById])
820-
}
822+
// @@index([revieweeId])
823+
// @@index([createdById])
824+
// }
821825

822826
model Language {
823827
id Int @id @default(autoincrement())
@@ -1078,6 +1082,32 @@ model ProductTranslation {
10781082
@@index([productId])
10791083
}
10801084

1085+
model Review {
1086+
id Int @id @default(autoincrement())
1087+
orderItemId Int @unique
1088+
userId Int
1089+
productId Int
1090+
skuId Int?
1091+
1092+
rating Int
1093+
message String?
1094+
reason ReviewBadReason?
1095+
1096+
serviceSeller Int // Chất lượng bán hàng
1097+
serviceShip Int // Chất lượng giao hàng
1098+
1099+
images String[] // Danh sách URL ảnh (không lưu FILE)
1100+
1101+
isAnonymous Boolean @default(false) // Người dùng muốn ẩn danh
1102+
1103+
createdAt DateTime @default(now())
1104+
updatedAt DateTime @updatedAt
1105+
1106+
@@index([userId])
1107+
@@index([productId])
1108+
@@index([skuId])
1109+
}
1110+
10811111
// Enums
10821112
enum ValueTypeDiscount {
10831113
PERCENTAGE
@@ -1218,3 +1248,10 @@ enum platformType {
12181248
MOBILE
12191249
DESKTOP
12201250
}
1251+
1252+
enum ReviewBadReason {
1253+
DAMAGED_PRODUCT // Hàng lỗi hoặc bị hư hỏng
1254+
FAKE_PRODUCT // Sản phẩm giả mạo
1255+
NOT_AS_DESCRIBED // Sản phẩm không như mô tả
1256+
POOR_QUALITY // Sản phẩm chất lượng kém
1257+
}

src/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { SearchModule } from './modules/search/search.module';
3232
const modules = [
3333
AuthModule,
3434
UserModule,
35-
MediaModule,
35+
// MediaModule,
3636
RoleModule,
3737
PermissionModule,
3838
LanguageModule,

src/main.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ async function bootstrap() {
1515
app.use(cookieParser());
1616

1717
app.enableCors({
18-
origin: 'http://localhost:3000',
18+
origin: [
19+
'http://localhost:3000',
20+
'http://localhost:8081',
21+
'http://192.168.1.124:8081',
22+
'exp://192.168.1.124:8081',
23+
'expo://192.168.1.124:8081',
24+
],
1925
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
2026
credentials: true,
2127
});

0 commit comments

Comments
 (0)