@smarttj/core 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ export declare enum AskRequestPurpose {
2
+ SUPPORT = "SUPPORT",
3
+ ANALYTICS = "ANALYTICS",
4
+ PRODUCT_MODERATE = "PRODUCT_MODERATE"
5
+ }
6
+ export declare enum AskRequestProvider {
7
+ OPENAI = "OPENAI",
8
+ GEMINI = "GEMINI",
9
+ GROQ = "GROQ"
10
+ }
11
+ export interface AskRequest {
12
+ purpose: AskRequestPurpose;
13
+ prompt: string;
14
+ context?: string;
15
+ model?: string;
16
+ temperature?: number;
17
+ provider?: AskRequestProvider;
18
+ }
19
+ export declare const PRODUCT_MODERATE_PROMPT = "\n\u0422\u044B \u043C\u043E\u0434\u0435\u0440\u0430\u0442\u043E\u0440 \u0438\u043D\u0442\u0435\u0440\u043D\u0435\u0442 \u043C\u0430\u0433\u0430\u0437\u0438\u043D\u0430.\n\u041F\u043E\u043B\u0443\u0447\u0430\u0439 \u0432\u0445\u043E\u0434\u043D\u044B\u0435 \u0434\u0430\u043D\u043D\u044B\u0435 \u0438 \u043F\u0440\u043E\u0432\u0435\u0440\u044F\u0439, \u043C\u043E\u0434\u0435\u0440\u0438\u0440\u0443\u0439.\n\u041F\u0440\u043E\u0432\u0435\u0440 \u0434\u0430\u043D\u043D\u044B\u0445 \u043D\u0430 \u043F\u043E\u0445\u043E\u0436\u0435\u0441\u0442 \u043D\u0430 \u0441\u043F\u0430\u043C \u0438 \u043C\u043E\u0448\u0435\u043D\u043D\u0438\u0447\u0435\u0441\u0442\u0432\n\n\u0412 \u043A\u043E\u043D\u0446\u0435 \u043E\u0446\u0435\u043D\u0438 \u0432\u0430\u043B\u0438\u0434\u043D\u043E\u0441\u0442\u044C \u0434\u0430\u043D\u043D\u044B\u0445 \u0438 \u043E\u043F\u0440\u0430\u0432 true \u0438\u043B\u0438 false.\n1 - \u043C\u043E\u0436\u043D\u043E \u043F\u0443\u0431\u043B\u0438\u043A\u043E\u0432\u0430\u0442, 0 - \u043E\u0442\u043A\u0430\u0437 \u043C\u043E\u0434\u0435\u0440\u0430\u0446\u0438\u0438.\n\u0412 \u0441\u043B\u0443\u0447\u0438 \u043E\u0442\u043A\u0430\u0437\u0430 \u043F\u0440\u043E\u0441\u0442\u043E \u0441\u043A\u0430\u0436\u0438 \u043F\u0440\u0438\u0447\u0438\u043D\u0443 \u0432 text.\n\n\u0424\u043E\u0440\u043C\u0430\u0442 \u043E\u0442\u0432\u0435\u0442\u0430: \u0421\u0442\u0440\u043E\u0433\u043E \u0432 JSON \u0431\u0435\u0437 \u043B\u0438\u0448\u043D\u0438\u0445 \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432 \u0438\u043B\u0438 \u0442\u0435\u043A\u0441\u0442\u043E\u0432\n\u041F\u0440\u0438\u043C\u0435\u0440: { \"text\": \"...\", \"ok\": true | false }\n";
20
+ //# sourceMappingURL=ai.enum.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.enum.d.ts","sourceRoot":"","sources":["../../src/ai/ai.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,gBAAgB,qBAAqB;CACtC;AAED,oBAAY,kBAAkB;IAC5B,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,IAAI,SAAS;CACd;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,iBAAiB,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,kBAAkB,CAAC;CAC/B;AAED,eAAO,MAAM,uBAAuB,woDAWnC,CAAC"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PRODUCT_MODERATE_PROMPT = exports.AskRequestProvider = exports.AskRequestPurpose = void 0;
4
+ var AskRequestPurpose;
5
+ (function (AskRequestPurpose) {
6
+ AskRequestPurpose["SUPPORT"] = "SUPPORT";
7
+ AskRequestPurpose["ANALYTICS"] = "ANALYTICS";
8
+ AskRequestPurpose["PRODUCT_MODERATE"] = "PRODUCT_MODERATE";
9
+ })(AskRequestPurpose || (exports.AskRequestPurpose = AskRequestPurpose = {}));
10
+ var AskRequestProvider;
11
+ (function (AskRequestProvider) {
12
+ AskRequestProvider["OPENAI"] = "OPENAI";
13
+ AskRequestProvider["GEMINI"] = "GEMINI";
14
+ AskRequestProvider["GROQ"] = "GROQ";
15
+ })(AskRequestProvider || (exports.AskRequestProvider = AskRequestProvider = {}));
16
+ exports.PRODUCT_MODERATE_PROMPT = `
17
+ Ты модератор интернет магазина.
18
+ Получай входные данные и проверяй, модерируй.
19
+ Провер данных на похожест на спам и мошенничеств
20
+
21
+ В конце оцени валидность данных и оправ true или false.
22
+ 1 - можно публиковат, 0 - отказ модерации.
23
+ В случи отказа просто скажи причину в text.
24
+
25
+ Формат ответа: Строго в JSON без лишних символов или текстов
26
+ Пример: { "text": "...", "ok": true | false }
27
+ `;
28
+ //# sourceMappingURL=ai.enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.enum.js","sourceRoot":"","sources":["../../src/ai/ai.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,wCAAmB,CAAA;IACnB,4CAAuB,CAAA;IACvB,0DAAqC,CAAA;AACvC,CAAC,EAJW,iBAAiB,aAAjB,iBAAiB,GAAjB,iBAAiB,QAI5B;AAED,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,uCAAiB,CAAA;IACjB,uCAAiB,CAAA;IACjB,mCAAa,CAAA;AACf,CAAC,EAJW,kBAAkB,aAAlB,kBAAkB,GAAlB,kBAAkB,QAI7B;AAWY,QAAA,uBAAuB,GAAG;;;;;;;;;;;CAWtC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./ai.enum";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ai.enum"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B"}
@@ -0,0 +1,2 @@
1
+ export * from "./ai";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ai"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uCAAqB"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@smarttj/core",
3
+ "version": "1.0.1",
4
+ "description": "Shared enums, constants and database schemas for SmartTJ ecosystem",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "prisma/schema.prisma"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "./ai": {
17
+ "types": "./dist/ai/index.d.ts",
18
+ "default": "./dist/ai/index.js"
19
+ },
20
+ "./prisma/schema.prisma": "./prisma/schema.prisma"
21
+ },
22
+ "scripts": {
23
+ "clean": "rimraf dist",
24
+ "build": "npm run clean && tsc",
25
+ "prepare": "npm run build"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "devDependencies": {
31
+ "rimraf": "^6.1.3",
32
+ "typescript": "^7.0.2"
33
+ }
34
+ }
@@ -0,0 +1,776 @@
1
+ generator client {
2
+ provider = "prisma-client-js"
3
+ }
4
+
5
+ datasource db {
6
+ provider = "postgresql"
7
+ }
8
+
9
+ enum UserRole {
10
+ SYSADMIN // Системный администратор, полный доступ ко всем функциям и данным
11
+ USER // Обычный пользователь, может просматривать и заказывать товары, управлять своим профилем
12
+ ADMIN // Администратор, может управлять товарами, заказами и пользователями
13
+ MODERATOR // Модератор, может управлять отзывами и поддержкой
14
+ PARTNER // Партнер, может управлять своими товарами и заказами
15
+ PARTNER_EMPLOYEE // Работник партнера
16
+ }
17
+
18
+ model User {
19
+ id String @id @default(uuid(7))
20
+ phone String
21
+ email String?
22
+ password String?
23
+ name String
24
+ role UserRole @default(USER)
25
+ avatar String?
26
+ avatarId String?
27
+ regionId String?
28
+ bonus Int @default(0)
29
+ emailVerified Boolean @default(false)
30
+ googleId String?
31
+ telegramId String?
32
+
33
+ createdAt DateTime @default(now())
34
+ updatedAt DateTime @updatedAt
35
+
36
+ sessions Session[]
37
+ orders Order[]
38
+ notifications Notification[]
39
+ transactions Transaction[]
40
+ verifications Verification[]
41
+ reviews Review[]
42
+ addresses Address[]
43
+ employee Employee[]
44
+ supportChats SupportChat[]
45
+ operatorChats SupportChat[] @relation("AssignedOperator")
46
+ paymentAttempts PaymentAttempt[]
47
+ region Region? @relation(fields: [regionId], references: [id], onDelete: SetNull)
48
+ partner Partner?
49
+ cart Cart?
50
+
51
+ @@unique([phone, role])
52
+ @@unique([email, role])
53
+ @@unique([googleId, role])
54
+ }
55
+
56
+ model Session {
57
+ id String @id @default(uuid(7))
58
+ userId String
59
+ fingerprint String
60
+ userAgent String?
61
+ ip String?
62
+ expiresAt DateTime
63
+ isActive Boolean @default(true)
64
+ expoPushToken String? @unique
65
+ lastActiveAt DateTime @default(now())
66
+
67
+ createdAt DateTime @default(now())
68
+ updatedAt DateTime @updatedAt
69
+
70
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
71
+
72
+ @@unique([userId, fingerprint])
73
+ }
74
+
75
+ model AuthOtp {
76
+ id String @id @default(uuid(7))
77
+ phone String
78
+ code String
79
+ expiresAt DateTime
80
+ attempts Int @default(0)
81
+
82
+ createdAt DateTime @default(now())
83
+ updatedAt DateTime @updatedAt
84
+ }
85
+
86
+ enum SmsLogPurpose {
87
+ REGISTER // Регистрация нового пользователя
88
+ LOGIN // Вход в аккаунт
89
+ RESET_PASSWORD // Сброс пароля
90
+ }
91
+
92
+ enum SmsLogStatus {
93
+ NEW // In progress
94
+ SENT // Сообщение отправлено
95
+ FAILED // Ошибка при отправке
96
+ }
97
+
98
+ model SmsLog {
99
+ id String @id @default(uuid(7))
100
+ phone String
101
+ message String
102
+ purpose SmsLogPurpose
103
+ provider String?
104
+ status SmsLogStatus
105
+ messageId String?
106
+ error String?
107
+
108
+ createdAt DateTime @default(now())
109
+ updatedAt DateTime @updatedAt
110
+ }
111
+
112
+ enum PartnerStatus {
113
+ IN_MODERATE
114
+ ACTIVE
115
+ BLOCKED
116
+ }
117
+
118
+ enum PartnerIdentification {
119
+ MINIMUM
120
+ STANDART
121
+ MAXIMUM
122
+ }
123
+
124
+ model Partner {
125
+ id String @id @default(uuid(7))
126
+ userId String @unique
127
+ bonus Int @default(0)
128
+ status PartnerStatus @default(IN_MODERATE)
129
+ identification PartnerIdentification @default(MINIMUM)
130
+ title String
131
+ description String @default("")
132
+ logo String?
133
+ logoId String?
134
+ email String?
135
+ phone1 String
136
+ phone2 String?
137
+ address1 String?
138
+ address2 String?
139
+ about String?
140
+ inn String?
141
+
142
+ createdAt DateTime @default(now())
143
+ updatedAt DateTime @updatedAt
144
+
145
+ user User @relation(fields: [userId], references: [id])
146
+ products Product[]
147
+ }
148
+
149
+ enum EmployeeStatus {
150
+ ACTIVE // Активный
151
+ ON_VACATION // В отпуске
152
+ }
153
+
154
+ model Employee {
155
+ id String @id @default(uuid(7))
156
+ userId String
157
+ firstName String
158
+ lastName String
159
+ middleName String?
160
+ birthDate DateTime
161
+ position String
162
+ salary Int
163
+ passportNumber String
164
+ hireDate DateTime @default(now())
165
+ status EmployeeStatus @default(ACTIVE)
166
+
167
+ createdAt DateTime @default(now())
168
+ updatedAt DateTime @updatedAt
169
+
170
+ user User @relation(fields: [userId], references: [id])
171
+ }
172
+
173
+ enum VerificationStatus {
174
+ ACTIVE // Активный
175
+ DELETED // Удаленный
176
+ }
177
+
178
+ model Verification {
179
+ id String @id @default(uuid(7))
180
+ phone String
181
+ code String
182
+ expiresAt DateTime
183
+ status VerificationStatus @default(ACTIVE)
184
+ userId String?
185
+
186
+ createdAt DateTime @default(now())
187
+ updatedAt DateTime @updatedAt
188
+
189
+ user User? @relation(fields: [userId], references: [id])
190
+
191
+ @@index([phone])
192
+ }
193
+
194
+ model Region {
195
+ id String @id @default(uuid(7))
196
+ title String
197
+ order Int @default(1)
198
+ slug String @unique
199
+ parentId String?
200
+ default Boolean @default(false)
201
+
202
+ createdAt DateTime @default(now())
203
+ updatedAt DateTime @updatedAt
204
+
205
+ parent Region? @relation("RegionToSub", fields: [parentId], references: [id], onDelete: Cascade)
206
+ children Region[] @relation("RegionToSub")
207
+ users User[]
208
+ products Product[]
209
+ adresses Address[]
210
+ }
211
+
212
+ model Address {
213
+ id String @id @default(uuid(7))
214
+ userId String
215
+ fullname String
216
+ label String
217
+ address String
218
+ default Boolean @default(false)
219
+ phone String?
220
+ regionId String?
221
+ longitude String?
222
+ latitude String?
223
+
224
+ createdAt DateTime @default(now())
225
+ updatedAt DateTime @updatedAt
226
+
227
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
228
+ region Region? @relation(fields: [regionId], references: [id])
229
+ orders Order[]
230
+
231
+ @@index([userId])
232
+ }
233
+
234
+ enum ProductStatus {
235
+ DRAFT // Черновик
236
+ AUTO_MODERATION // В автоматическом модерации
237
+ MANUAL_MODERATION // В ручном модерации
238
+ ACTIVE // Активный
239
+ INACTIVE // Неактивный
240
+ NOT_AVAILABLE // Нет в наличии
241
+ DELETED // В процессе удаления
242
+ }
243
+
244
+ model Product {
245
+ id String @id @default(uuid(7))
246
+ partnerId String
247
+ title String?
248
+ slug String? @unique
249
+ description String?
250
+ warranty Int?
251
+ categoryId String?
252
+ brandId String?
253
+ modelId String?
254
+ regionId String?
255
+ publishedAt DateTime?
256
+ status ProductStatus @default(DRAFT)
257
+ averageRating Float @default(0)
258
+ reviewsCount Int @default(0)
259
+ soldCount Int @default(0)
260
+ viewsCount Int @default(0)
261
+ deletedAt DateTime?
262
+
263
+ createdAt DateTime @default(now())
264
+ updatedAt DateTime @updatedAt
265
+
266
+ partner Partner @relation(fields: [partnerId], references: [id])
267
+ category Category? @relation(fields: [categoryId], references: [id], onDelete: SetNull)
268
+ brand Brand? @relation(fields: [brandId], references: [id], onDelete: SetNull)
269
+ model Model? @relation(fields: [modelId], references: [id], onDelete: SetNull)
270
+ region Region? @relation(fields: [regionId], references: [id], onDelete: SetNull)
271
+ variants ProductVariant[]
272
+ reviews Review[]
273
+
274
+ @@index([categoryId])
275
+ @@index([brandId])
276
+ @@index([modelId])
277
+ @@index([regionId])
278
+ }
279
+
280
+ model ProductVariant {
281
+ id String @id @default(uuid(7))
282
+ price Int
283
+ discount Int?
284
+ stock Int
285
+ productId String
286
+ code Int @unique @default(autoincrement()) @db.Integer
287
+ variantId String?
288
+ label String?
289
+
290
+ createdAt DateTime @default(now())
291
+ updatedAt DateTime @updatedAt
292
+
293
+ product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
294
+ images Image[]
295
+ cartItems CartItem[]
296
+ orderItems OrderItem[]
297
+ priceHistory ProductPriceHistory[]
298
+ attributes ProductAttribute[]
299
+ reviews Review[]
300
+ variants ProductVariant[] @relation("VariantImageSource")
301
+ variant ProductVariant? @relation("VariantImageSource", fields: [variantId], references: [id], onDelete: SetNull)
302
+
303
+ @@index([code])
304
+ @@index([productId])
305
+ }
306
+
307
+ model ProductPriceHistory {
308
+ id String @id @default(uuid(7))
309
+ variantId String
310
+ price Int
311
+
312
+ createdAt DateTime @default(now())
313
+ updatedAt DateTime @updatedAt
314
+
315
+ variant ProductVariant @relation(fields: [variantId], references: [id], onDelete: Cascade)
316
+
317
+ @@index([variantId])
318
+ }
319
+
320
+ model Review {
321
+ id String @id @default(uuid(7))
322
+ userId String
323
+ productId String
324
+ productVariantId String?
325
+ rating Int
326
+ advantages String @default("")
327
+ flaws String @default("")
328
+ comment String
329
+
330
+ createdAt DateTime @default(now())
331
+ updatedAt DateTime @updatedAt
332
+
333
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
334
+ product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
335
+ productVariant ProductVariant? @relation(fields: [productVariantId], references: [id])
336
+
337
+ @@index([productId])
338
+ }
339
+
340
+ model Category {
341
+ id String @id @default(uuid(7))
342
+ name String
343
+ short_name String
344
+ slug String @unique
345
+ order Int @default(1)
346
+ icon String?
347
+ iconId String?
348
+ parentId String?
349
+ parentKey String @default("ROOT")
350
+
351
+ createdAt DateTime @default(now())
352
+ updatedAt DateTime @updatedAt
353
+
354
+ parent Category? @relation("CategoryToSub", fields: [parentId], references: [id], onDelete: Cascade)
355
+ children Category[] @relation("CategoryToSub")
356
+ products Product[]
357
+ attributes Attribute[]
358
+ }
359
+
360
+ model Brand {
361
+ id String @id @default(uuid(7))
362
+ name String
363
+ slug String @unique
364
+ logo String?
365
+ logoId String?
366
+ order Int @default(1)
367
+ popular Boolean
368
+
369
+ createdAt DateTime @default(now())
370
+ updatedAt DateTime @updatedAt
371
+
372
+ products Product[]
373
+ models Model[]
374
+ }
375
+
376
+ model Model {
377
+ id String @id @default(uuid(7))
378
+ name String
379
+ slug String @unique
380
+ description String?
381
+ image String?
382
+ imageId String?
383
+ brandId String
384
+ order Int @default(1)
385
+ popular Boolean
386
+
387
+ createdAt DateTime @default(now())
388
+ updatedAt DateTime @updatedAt
389
+
390
+ brand Brand @relation(fields: [brandId], references: [id])
391
+ products Product[]
392
+
393
+ @@unique([name, brandId])
394
+ }
395
+
396
+ model Image {
397
+ id String @id @default(uuid(7))
398
+ productVariantId String
399
+ url String
400
+ urlId String
401
+ order Int @default(1)
402
+
403
+ createdAt DateTime @default(now())
404
+ updatedAt DateTime @updatedAt
405
+
406
+ productVariant ProductVariant @relation(fields: [productVariantId], references: [id], onDelete: Cascade)
407
+
408
+ @@index([productVariantId])
409
+ }
410
+
411
+ enum AttributeType {
412
+ STRING // Строка
413
+ NUMBER // Число
414
+ BOOLEAN // Логическое значение
415
+ SELECT
416
+ MULTISELECT
417
+ }
418
+
419
+ model Attribute {
420
+ id String @id @default(uuid(7))
421
+ categoryId String?
422
+ name String
423
+ type AttributeType
424
+ unit String?
425
+ groupId String?
426
+ required Boolean @default(false)
427
+ filterable Boolean @default(false)
428
+ order Int @default(1)
429
+
430
+ createdAt DateTime @default(now())
431
+ updatedAt DateTime @updatedAt
432
+
433
+ category Category? @relation(fields: [categoryId], references: [id], onDelete: Cascade)
434
+ ptoductAttributes ProductAttribute[]
435
+ values AttributeValue[]
436
+ group AttributeGroup? @relation(fields: [groupId], references: [id], onDelete: SetNull)
437
+ }
438
+
439
+ model AttributeValue {
440
+ id String @id @default(uuid(7))
441
+ attributeId String
442
+ valueString String?
443
+ valueNumber Float?
444
+ valueBoolean Boolean?
445
+ label String?
446
+
447
+ createdAt DateTime @default(now())
448
+ updatedAt DateTime @updatedAt
449
+
450
+ attribute Attribute @relation(fields: [attributeId], references: [id], onDelete: Cascade)
451
+ productAttributes ProductAttribute[]
452
+
453
+ @@index([attributeId])
454
+ }
455
+
456
+ model AttributeGroup {
457
+ id String @id @default(uuid(7))
458
+ name String @unique
459
+ order Int @default(1)
460
+
461
+ createdAt DateTime @default(now())
462
+ updatedAt DateTime @updatedAt
463
+
464
+ attributes Attribute[]
465
+ }
466
+
467
+ model ProductAttribute {
468
+ id String @id @default(uuid(7))
469
+ attributeId String
470
+ attributeValueId String?
471
+ productVariantId String
472
+ valueString String?
473
+ valueNumber Float?
474
+ valueBoolean Boolean?
475
+ label String?
476
+
477
+ createdAt DateTime @default(now())
478
+ updatedAt DateTime @updatedAt
479
+
480
+ attribute Attribute @relation(fields: [attributeId], references: [id], onDelete: Cascade)
481
+ attributeValue AttributeValue? @relation(fields: [attributeValueId], references: [id], onDelete: Cascade)
482
+ productVariant ProductVariant @relation(fields: [productVariantId], references: [id], onDelete: Cascade)
483
+ }
484
+
485
+ model Cart {
486
+ id String @id @default(uuid(7))
487
+ userId String @unique
488
+
489
+ createdAt DateTime @default(now())
490
+ updatedAt DateTime @updatedAt
491
+
492
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
493
+ items CartItem[]
494
+ }
495
+
496
+ model CartItem {
497
+ id String @id @default(uuid(7))
498
+ cartId String
499
+ productVariantId String
500
+ quantity Int @default(1)
501
+
502
+ createdAt DateTime @default(now())
503
+ updatedAt DateTime @updatedAt
504
+
505
+ cart Cart @relation(fields: [cartId], references: [id], onDelete: Cascade)
506
+ productVariant ProductVariant @relation(fields: [productVariantId], references: [id], onDelete: Cascade)
507
+
508
+ @@unique([cartId, productVariantId])
509
+ }
510
+
511
+ enum PaymentMethodType {
512
+ CASH // Наличные
513
+ CARD // Банковская карта
514
+ WALLET // Кошелек пользователья
515
+ }
516
+
517
+ model PaymentMethod {
518
+ id String @id @default(uuid(7))
519
+ name String
520
+ type PaymentMethodType
521
+ isActive Boolean @default(true)
522
+
523
+ createdAt DateTime @default(now())
524
+ updatedAt DateTime @updatedAt
525
+
526
+ orders Order[]
527
+ }
528
+
529
+ enum OrderPaymentStatus {
530
+ UNPAID // Не оплачен
531
+ PAID // Оплачен
532
+ FAILED // Ошибка оплаты
533
+ REFUNDED // Деньги возвращены
534
+ }
535
+
536
+ enum OrderDeliveryStatus {
537
+ NEW // Только оформлен
538
+ PARTIALLY_DELIVERED // Часть товаров доставлена
539
+ DELIVERED // Все товары доставлены
540
+ RECEIVED // Товар у клиента
541
+ RETURNED // Товары возвращены
542
+ }
543
+
544
+ enum OrderUIStatus {
545
+ SHOW // Отображается пользователю
546
+ ARCHIVED // Заказ скрыт, но не удалён (архив)
547
+ DELETED // Удалён из интерфейса (мягкое удаление)
548
+ }
549
+
550
+ enum OrderType {
551
+ PICKUP // Самовывоз
552
+ DELIVERY // Доставка
553
+ }
554
+
555
+ model Order {
556
+ id String @id @default(uuid(7))
557
+ userId String
558
+ paymentStatus OrderPaymentStatus @default(UNPAID)
559
+ deliveryStatus OrderDeliveryStatus @default(NEW)
560
+ uiStatus OrderUIStatus @default(SHOW)
561
+ type OrderType
562
+ paymentMethodId String
563
+ totalPrice Int
564
+ comment String?
565
+ addressId String?
566
+
567
+ createdAt DateTime @default(now())
568
+ updatedAt DateTime @updatedAt
569
+
570
+ user User @relation(fields: [userId], references: [id])
571
+ paymentMethod PaymentMethod @relation(fields: [paymentMethodId], references: [id])
572
+ address Address? @relation(fields: [addressId], references: [id], onDelete: SetNull)
573
+ items OrderItem[]
574
+ transaction Transaction?
575
+ paymentAttempts PaymentAttempt[]
576
+
577
+ @@index([userId])
578
+ }
579
+
580
+ enum OrderItemDeliveryStatus {
581
+ NEW // Только добавлен в заказ
582
+ PROCESSING // Обрабатывается
583
+ SHIPPED // Отправлен
584
+ AT_PICKUP_POINT // На пункте выдачи
585
+ DELIVERED // Доставлен
586
+ RECEIVED // Клиент подтвердил получение
587
+ RETURN_PROCESS // В процессе возврата
588
+ RETURN_CANCEL // Возврат отменен
589
+ RETURNED // Возвращен
590
+ }
591
+
592
+ model OrderItem {
593
+ id String @id @default(uuid(7))
594
+ orderId String
595
+ productVariantId String?
596
+ quantity Int @default(1)
597
+ price Int
598
+ deliveryStatus OrderItemDeliveryStatus @default(NEW)
599
+ warranty Int?
600
+ receivedAt DateTime?
601
+
602
+ createdAt DateTime @default(now())
603
+ updatedAt DateTime @updatedAt
604
+
605
+ order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
606
+ productVariant ProductVariant? @relation(fields: [productVariantId], references: [id], onDelete: SetNull)
607
+
608
+ @@index([orderId])
609
+ }
610
+
611
+ enum NotificationType {
612
+ DEFAULT
613
+ PRODUCT_MODERATION
614
+ }
615
+
616
+ model Notification {
617
+ id String @id @default(uuid(7))
618
+ userId String
619
+ type NotificationType @default(DEFAULT)
620
+ title String
621
+ message String
622
+ isRead Boolean @default(false)
623
+ metadata Json?
624
+
625
+ createdAt DateTime @default(now())
626
+ updatedAt DateTime @updatedAt
627
+
628
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
629
+
630
+ @@index([userId])
631
+ }
632
+
633
+ enum PaymentAttemptStatus {
634
+ PENDING // В ожидании оплаты
635
+ FAILED // Ошибка оплаты
636
+ SUCCESS // Успешно оплачено
637
+ CANCELED // Пользователь отменил
638
+ REFUNDED // Возврат
639
+ }
640
+
641
+ model PaymentAttempt {
642
+ id String @id @default(uuid(7))
643
+ userId String
644
+ orderId String
645
+ amount Int
646
+ status PaymentAttemptStatus @default(PENDING)
647
+ provider String?
648
+ providerId String?
649
+
650
+ createdAt DateTime @default(now())
651
+ updatedAt DateTime @updatedAt
652
+
653
+ user User @relation(fields: [userId], references: [id])
654
+ order Order @relation(fields: [orderId], references: [id])
655
+ }
656
+
657
+ enum TransactionStatus {
658
+ SUCCESS // Успешно оплачено
659
+ REFUNDED // Возврат
660
+ }
661
+
662
+ model Transaction {
663
+ id String @id @default(uuid(7))
664
+ userId String
665
+ orderId String @unique
666
+ amount Int
667
+ status TransactionStatus @default(SUCCESS)
668
+ provider String?
669
+ providerId String?
670
+
671
+ createdAt DateTime @default(now())
672
+ updatedAt DateTime @updatedAt
673
+
674
+ user User @relation(fields: [userId], references: [id])
675
+ order Order @relation(fields: [orderId], references: [id])
676
+ }
677
+
678
+ enum SupportChatStatus {
679
+ AI // Автоматический ответ
680
+ HUMAN // Ручная обработка
681
+ CLOSED // Чат закрыт
682
+ }
683
+
684
+ enum SupportChatPriority {
685
+ LOW // Низкий приоритет, может обрабатываться позже
686
+ NORMAL // Обычный приоритет, обрабатывается в порядке очереди
687
+ HIGH // Высокий приоритет, требует быстрого реагирования
688
+ CRITICAL // Критический приоритет, требует немедленного реагирования
689
+ }
690
+
691
+ model SupportChat {
692
+ id String @id @default(uuid(7))
693
+ userId String?
694
+ status SupportChatStatus @default(AI)
695
+ priority SupportChatPriority @default(NORMAL)
696
+ assignedToId String?
697
+ closedAt DateTime?
698
+
699
+ createdAt DateTime @default(now())
700
+ updatedAt DateTime @updatedAt
701
+
702
+ messages SupportMessage[]
703
+ user User? @relation(fields: [userId], references: [id])
704
+ assignedTo User? @relation("AssignedOperator", fields: [assignedToId], references: [id])
705
+ AIContext SupportAIContext?
706
+ }
707
+
708
+ enum SupportMessageRole {
709
+ USER // Сообщение от пользователя
710
+ AI // Сообщение от искусственного интеллекта
711
+ OPERATOR // Сообщение от оператора поддержки
712
+ SYSTEM // Системное сообщение
713
+ }
714
+
715
+ model SupportMessage {
716
+ id String @id @default(uuid(7))
717
+ chatId String
718
+ role SupportMessageRole
719
+ content String
720
+
721
+ createdAt DateTime @default(now())
722
+ updatedAt DateTime @updatedAt
723
+
724
+ chat SupportChat @relation(fields: [chatId], references: [id], onDelete: Cascade)
725
+ attachments SupportAttachment[]
726
+ }
727
+
728
+ model SupportAIContext {
729
+ id String @id @default(uuid(7))
730
+ chatId String @unique
731
+ lastPrompt String?
732
+ confidence Float?
733
+ model String?
734
+
735
+ createdAt DateTime @default(now())
736
+ updatedAt DateTime @updatedAt
737
+
738
+ chat SupportChat @relation(fields: [chatId], references: [id], onDelete: Cascade)
739
+ }
740
+
741
+ enum SupportAttachmentType {
742
+ IMAGE // Изображение (JPEG, PNG и т.д.)
743
+ FILE // Общий файл (PDF, DOCX и т.д.)
744
+ }
745
+
746
+ model SupportAttachment {
747
+ id String @id @default(uuid(7))
748
+ messageId String
749
+ url String
750
+ urlId String
751
+ type SupportAttachmentType
752
+ name String?
753
+
754
+ createdAt DateTime @default(now())
755
+ updatedAt DateTime @updatedAt
756
+
757
+ message SupportMessage @relation(fields: [messageId], references: [id], onDelete: Cascade)
758
+
759
+ @@index([messageId])
760
+ }
761
+
762
+ model Report {
763
+ id String @id @default(uuid(7))
764
+ year Int
765
+ month Int
766
+ ordersCount Int
767
+ revenue Int
768
+ avgOrderValue Int
769
+ paidOrdersCount Int
770
+ refundedAmount Int
771
+
772
+ createdAt DateTime @default(now())
773
+ updatedAt DateTime @updatedAt
774
+
775
+ @@unique([year, month])
776
+ }