transform core api codes into this project, update modules as admin/pos context modules

This commit is contained in:
2026-03-07 11:25:11 +03:30
parent b949500482
commit 8c5f1d4d49
167 changed files with 26975 additions and 1837 deletions
@@ -0,0 +1,272 @@
/*
Warnings:
- The primary key for the `devices` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to drop the column `account_id` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `app_version` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `brand` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `browser_name` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `build_number` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `device` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `fcm_token` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `model` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `platform` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `release_number` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `sdk_version` on the `devices` table. All the data in the column will be lost.
- You are about to drop the column `uuid` on the `devices` table. All the data in the column will be lost.
- A unique constraint covering the columns `[complex_id,national_id]` on the table `customer_individuals` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[complex_id,registration_number]` on the table `customer_legal` will be added. If there are existing duplicate values, this will fail.
- Added the required column `complex_id` to the `customer_individuals` table without a default value. This is not possible if the table is not empty.
- Added the required column `complex_id` to the `customer_legal` table without a default value. This is not possible if the table is not empty.
- Added the required column `brand_id` to the `devices` table without a default value. This is not possible if the table is not empty.
- The required column `id` was added to the `devices` table with a prisma-level default value. This is not possible if the table is not empty. Please add this column as optional, then populate it before making it required.
- Added the required column `name` to the `devices` table without a default value. This is not possible if the table is not empty.
- Added the required column `updated_at` to the `devices` table without a default value. This is not possible if the table is not empty.
*/
-- DropIndex
DROP INDEX `devices_uuid_key` ON `devices`;
-- AlterTable
ALTER TABLE `customer_individuals` ADD COLUMN `complex_id` VARCHAR(191) NOT NULL;
-- AlterTable
ALTER TABLE `customer_legal` ADD COLUMN `complex_id` VARCHAR(191) NOT NULL;
-- AlterTable
ALTER TABLE `devices` DROP PRIMARY KEY,
DROP COLUMN `account_id`,
DROP COLUMN `app_version`,
DROP COLUMN `brand`,
DROP COLUMN `browser_name`,
DROP COLUMN `build_number`,
DROP COLUMN `device`,
DROP COLUMN `fcm_token`,
DROP COLUMN `model`,
DROP COLUMN `platform`,
DROP COLUMN `release_number`,
DROP COLUMN `sdk_version`,
DROP COLUMN `uuid`,
ADD COLUMN `brand_id` VARCHAR(191) NOT NULL,
ADD COLUMN `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
ADD COLUMN `id` VARCHAR(191) NOT NULL,
ADD COLUMN `name` VARCHAR(191) NOT NULL,
ADD COLUMN `updated_at` DATETIME(3) NOT NULL,
MODIFY `os_version` VARCHAR(191) NULL,
ADD PRIMARY KEY (`id`);
-- CreateTable
CREATE TABLE `tokens` (
`id` VARCHAR(191) NOT NULL,
`token` VARCHAR(191) NOT NULL,
`type` ENUM('ACCESS', 'REFRESH') NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`expires_at` DATETIME(3) NOT NULL,
`account_id` VARCHAR(191) NOT NULL,
UNIQUE INDEX `tokens_token_key`(`token`),
UNIQUE INDEX `tokens_type_account_id_key`(`type`, `account_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `verification_codes` (
`id` VARCHAR(191) NOT NULL,
`code` VARCHAR(191) NOT NULL,
`is_used` BOOLEAN NOT NULL DEFAULT false,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`expires_at` DATETIME(3) NOT NULL,
`account_id` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `guilds` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`code` VARCHAR(191) NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `business_activities` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`tax_id` VARCHAR(191) NULL,
`guild_id` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `complexes` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`address` VARCHAR(191) NULL,
`business_activity_id` VARCHAR(191) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `poses` (
`id` VARCHAR(191) NOT NULL,
`serial` VARCHAR(191) NOT NULL,
`model` VARCHAR(191) NULL,
`status` ENUM('ACTIVE', 'DISABLED') NOT NULL DEFAULT 'ACTIVE',
`pos_type` ENUM('PSP', 'MOBILE', 'API') NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL,
`complex_id` VARCHAR(191) NOT NULL,
`device_id` VARCHAR(191) NOT NULL,
`provider_id` VARCHAR(191) NULL,
UNIQUE INDEX `poses_serial_key`(`serial`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `device_brands` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `licenses` (
`id` VARCHAR(191) NOT NULL,
`pos_id` VARCHAR(191) NOT NULL,
`partner_id` VARCHAR(191) NOT NULL,
`starts_at` DATETIME(3) NOT NULL,
`expires_at` DATETIME(3) NOT NULL,
`status` ENUM('ACTIVE', 'EXPIRED', 'SUSPENDED') NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `partners` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`code` VARCHAR(191) NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `users` (
`id` VARCHAR(191) NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`mobile_number` VARCHAR(191) NOT NULL,
`national_code` VARCHAR(191) NULL,
`first_name` VARCHAR(191) NOT NULL,
`last_name` VARCHAR(191) NOT NULL,
UNIQUE INDEX `users_mobile_number_key`(`mobile_number`),
UNIQUE INDEX `users_national_code_key`(`national_code`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `accounts` (
`id` VARCHAR(191) NOT NULL,
`username` VARCHAR(191) NOT NULL,
`type` ENUM('PARTNER', 'BUSINESS', 'ADMIN', 'PROVIDER', 'POS') NOT NULL,
`status` ENUM('ACTIVE', 'SUSPENDED') NOT NULL,
`password` VARCHAR(191) NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`user_id` VARCHAR(191) NOT NULL,
`partner_id` VARCHAR(191) NULL,
`business_id` VARCHAR(191) NULL,
`provider_id` VARCHAR(191) NULL,
`pos_id` VARCHAR(191) NULL,
UNIQUE INDEX `accounts_username_key`(`username`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `providers` (
`id` VARCHAR(191) NOT NULL,
`name` VARCHAR(191) NOT NULL,
`code` VARCHAR(191) NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `user_devices` (
`account_id` VARCHAR(255) NULL,
`app_version` VARCHAR(20) NOT NULL,
`build_number` VARCHAR(20) NOT NULL,
`uuid` VARCHAR(255) NOT NULL,
`platform` VARCHAR(100) NOT NULL,
`brand` VARCHAR(100) NOT NULL,
`model` VARCHAR(100) NOT NULL,
`device` VARCHAR(100) NOT NULL,
`os_version` VARCHAR(20) NOT NULL,
`sdk_version` VARCHAR(20) NOT NULL,
`release_number` VARCHAR(20) NOT NULL,
`browser_name` VARCHAR(100) NULL,
`fcm_token` VARCHAR(100) NULL,
UNIQUE INDEX `user_devices_uuid_key`(`uuid`),
PRIMARY KEY (`uuid`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateIndex
CREATE UNIQUE INDEX `customer_individuals_complex_id_national_id_key` ON `customer_individuals`(`complex_id`, `national_id`);
-- CreateIndex
CREATE UNIQUE INDEX `customer_legal_complex_id_registration_number_key` ON `customer_legal`(`complex_id`, `registration_number`);
-- AddForeignKey
ALTER TABLE `tokens` ADD CONSTRAINT `tokens_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `verification_codes` ADD CONSTRAINT `verification_codes_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `business_activities` ADD CONSTRAINT `business_activities_guild_id_fkey` FOREIGN KEY (`guild_id`) REFERENCES `guilds`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `complexes` ADD CONSTRAINT `complexes_business_activity_id_fkey` FOREIGN KEY (`business_activity_id`) REFERENCES `business_activities`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `poses` ADD CONSTRAINT `poses_complex_id_fkey` FOREIGN KEY (`complex_id`) REFERENCES `complexes`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `poses` ADD CONSTRAINT `poses_device_id_fkey` FOREIGN KEY (`device_id`) REFERENCES `devices`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `poses` ADD CONSTRAINT `poses_provider_id_fkey` FOREIGN KEY (`provider_id`) REFERENCES `providers`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `devices` ADD CONSTRAINT `devices_brand_id_fkey` FOREIGN KEY (`brand_id`) REFERENCES `device_brands`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `licenses` ADD CONSTRAINT `licenses_pos_id_fkey` FOREIGN KEY (`pos_id`) REFERENCES `poses`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `licenses` ADD CONSTRAINT `licenses_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `accounts` ADD CONSTRAINT `accounts_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `accounts` ADD CONSTRAINT `accounts_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `accounts` ADD CONSTRAINT `accounts_business_id_fkey` FOREIGN KEY (`business_id`) REFERENCES `business_activities`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `accounts` ADD CONSTRAINT `accounts_provider_id_fkey` FOREIGN KEY (`provider_id`) REFERENCES `providers`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `accounts` ADD CONSTRAINT `accounts_pos_id_fkey` FOREIGN KEY (`pos_id`) REFERENCES `poses`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
@@ -0,0 +1,31 @@
/*
Warnings:
- You are about to drop the column `account_id` on the `good_categories` table. All the data in the column will be lost.
- You are about to drop the column `account_id` on the `goods` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE `good_categories` DROP COLUMN `account_id`,
ADD COLUMN `guild_id` VARCHAR(191) NULL,
ADD COLUMN `is_default_guild_good` BOOLEAN NOT NULL DEFAULT false,
MODIFY `complex_id` VARCHAR(191) NULL;
-- AlterTable
ALTER TABLE `goods` DROP COLUMN `account_id`,
ADD COLUMN `guild_id` VARCHAR(191) NULL,
ADD COLUMN `is_default_guild_good` BOOLEAN NOT NULL DEFAULT false,
MODIFY `base_sale_price` DECIMAL(15, 0) NULL DEFAULT 0.00,
MODIFY `complex_id` VARCHAR(191) NULL;
-- AddForeignKey
ALTER TABLE `goods` ADD CONSTRAINT `goods_complex_id_fkey` FOREIGN KEY (`complex_id`) REFERENCES `complexes`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `goods` ADD CONSTRAINT `goods_guild_id_fkey` FOREIGN KEY (`guild_id`) REFERENCES `guilds`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `good_categories` ADD CONSTRAINT `good_categories_guild_id_fkey` FOREIGN KEY (`guild_id`) REFERENCES `guilds`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE `good_categories` ADD CONSTRAINT `good_categories_complex_id_fkey` FOREIGN KEY (`complex_id`) REFERENCES `complexes`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
@@ -0,0 +1,21 @@
/*
Warnings:
- You are about to drop the column `tax_id` on the `business_activities` table. All the data in the column will be lost.
- You are about to drop the column `pricingModel` on the `sales_invoice_items` table. All the data in the column will be lost.
- Added the required column `owner_id` to the `business_activities` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE `business_activities` DROP COLUMN `tax_id`,
ADD COLUMN `owner_id` VARCHAR(191) NOT NULL;
-- AlterTable
ALTER TABLE `complexes` ADD COLUMN `tax_id` VARCHAR(191) NULL;
-- AlterTable
ALTER TABLE `sales_invoice_items` DROP COLUMN `pricingModel`,
MODIFY `unit_type` ENUM('COUNT', 'GRAM', 'KILOGRAM', 'MILLILITER', 'LITER', 'METER', 'HOUR') NOT NULL;
-- AddForeignKey
ALTER TABLE `business_activities` ADD CONSTRAINT `business_activities_owner_id_fkey` FOREIGN KEY (`owner_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
+26
View File
@@ -0,0 +1,26 @@
model Token {
id String @id @default(uuid())
token String @unique
type TokenType
created_at DateTime @default(now())
expires_at DateTime
account_id String
account Account @relation(fields: [account_id], references: [id])
@@unique([type, account_id])
@@map("tokens")
}
model VerificationCode {
id String @id @default(uuid())
code String
is_used Boolean @default(false)
created_at DateTime @default(now())
expires_at DateTime
account_id String
account Account @relation(fields: [account_id], references: [id])
@@map("verification_codes")
}
+96
View File
@@ -0,0 +1,96 @@
model Guild {
id String @id @default(uuid())
name String
code String?
business_activities BusinessActivity[]
goods Good[]
good_categories GoodCategory[]
@@map("guilds")
}
model BusinessActivity {
id String @id @default(uuid())
name String
created_at DateTime @default(now())
guild_id String
owner_id String
guild Guild @relation(fields: [guild_id], references: [id])
user User @relation(fields: [owner_id], references: [id])
complexes Complex[]
accounts Account[]
@@map("business_activities")
}
model Complex {
id String @id @default(uuid())
name String
address String?
tax_id String?
business_activity_id String
business_activity BusinessActivity @relation(fields: [business_activity_id], references: [id])
pos_list Pos[]
goods Good[]
good_categories GoodCategory[]
@@map("complexes")
}
model Pos {
id String @id @default(uuid())
serial String @unique
model String?
status POSStatus @default(ACTIVE)
pos_type POSType
created_at DateTime @default(now())
updated_at DateTime @updatedAt()
complex_id String
device_id String
provider_id String?
complex Complex @relation(fields: [complex_id], references: [id])
device Device @relation(fields: [device_id], references: [id])
provider Provider? @relation(fields: [provider_id], references: [id])
licenses License[]
accounts Account[]
@@map("poses")
}
// model BusinessAccount {
// id String @id @default(uuid())
// role BusinessRole
// status AccountStatus @default(ACTIVE)
// created_at DateTime @default(now())
// business_activity_id String
// account_id String @unique
// account Account @relation(fields: [account_id], references: [id])
// owned_activities BusinessActivity[] @relation("business_owner")
// @@unique([business_activity_id, account_id])
// @@map("business_accounts")
// }
// model PosAccount {
// id String @id @default(uuid())
// pos_id String
// account_id String
// role POSRole
// created_at DateTime @default(now())
// pos Pos @relation(fields: [pos_id], references: [id])
// account Account @relation(fields: [account_id], references: [id])
// @@unique([pos_id, account_id])
// @@map("pos_accounts")
// }
+25
View File
@@ -0,0 +1,25 @@
model DeviceBrand {
id String @id @default(uuid())
name String
created_at DateTime @default(now())
updated_at DateTime @updatedAt()
devices Device[]
@@map("device_brands")
}
model Device {
id String @id @default(uuid())
name String
os_version String?
created_at DateTime @default(now())
updated_at DateTime @updatedAt()
brand_id String
brand DeviceBrand @relation(fields: [brand_id], references: [id])
poses Pos[]
@@map("devices")
}
+14
View File
@@ -0,0 +1,14 @@
model License {
id String @id @default(uuid())
starts_at DateTime
expires_at DateTime
status LicenseStatus
pos_id String
partner_id String
pos Pos @relation(fields: [pos_id], references: [id])
partner Partner @relation(fields: [partner_id], references: [id])
@@map("licenses")
}
+25
View File
@@ -0,0 +1,25 @@
model Partner {
id String @id @default(uuid())
name String
code String?
licenses License[]
account Account[]
@@map("partners")
}
// model PartnerAccount {
// id String @id @default(uuid())
// role PartnerRole
// status AccountStatus @default(ACTIVE)
// created_at DateTime @default(now())
// partner_id String
// account_id String @unique
// partner Partner @relation(fields: [partner_id], references: [id])
// account Account @relation(fields: [account_id], references: [id])
// @@unique([partner_id, account_id])
// @@map("partner_accounts")
// }
+72
View File
@@ -0,0 +1,72 @@
model User {
id String @id @default(uuid())
// user_type UserType
created_at DateTime @default(now())
// individual_profile IndividualProfile?
// legal_profile LegalProfile?
mobile_number String @unique()
national_code String? @unique()
first_name String
last_name String
// username String
accounts Account[]
businessActivities BusinessActivity[]
@@map("users")
}
// model LegalProfile {
// user_id String @id
// company_name String
// register_no String @unique()
// representative_name String?
// representative_national_id String?
// // user User @relation(fields: [user_id], references: [id])
// @@map("legal_profiles")
// }
// model IndividualProfile {
// user_id String @id
// national_code String @unique()
// first_name String
// last_name String
// birth_date DateTime?
// mobile_number String
// // user User @relation(fields: [user_id], references: [id])
// @@map("individual_profiles")
// }
model Account {
id String @id @default(uuid())
username String @unique()
// first_name String
// last_name String
type AccountType
status AccountStatus
password String
created_at DateTime @default(now())
user_id String
user User @relation(fields: [user_id], references: [id])
partner_id String?
partner Partner? @relation(fields: [partner_id], references: [id])
business_id String?
business BusinessActivity? @relation(fields: [business_id], references: [id])
provider_id String?
provider Provider? @relation(fields: [provider_id], references: [id])
pos_id String?
pos Pos? @relation(fields: [pos_id], references: [id])
verification_codes VerificationCode[]
tokens Token[]
@@map("accounts")
}
+25
View File
@@ -0,0 +1,25 @@
model Provider {
id String @id @default(uuid())
name String
code String?
pos_list Pos[]
accounts Account[]
@@map("providers")
}
// model ProviderAccount {
// id String @id @default(uuid())
// role ProviderRole
// status AccountStatus @default(ACTIVE)
// created_at DateTime @default(now())
// provider_id String
// account_id String @unique
// provider Provider @relation(fields: [provider_id], references: [id])
// account Account @relation(fields: [account_id], references: [id])
// @@unique([provider_id, account_id])
// @@map("provider_accounts")
// }
-40
View File
@@ -1,40 +0,0 @@
enum PaymentMethodType {
TERMINAL
CASH
SET_OFF
CARD
BANK
CHECK
OTHER
}
enum PurchaseReceiptStatus {
UNPAID
PARTIALLY_PAID
PAID
}
enum SalesInvoiceType {
GOOD
SERVICE
}
enum UnitType {
COUNT
GRAM
KILOGRAM
LITER
METER
HOUR
}
enum CustomerType {
INDIVIDUAL
LEGAL
UNKNOWN
}
enum SalesInvoiceItemPricingModel {
STANDARD
GOLD
}
-37
View File
@@ -1,37 +0,0 @@
model Good {
id String @id @default(uuid())
name String @db.VarChar(255)
description String? @db.Text
sku String @db.VarChar(100)
local_sku String? @unique() @db.VarChar(100)
barcode String? @unique() @db.VarChar(100)
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt @db.Timestamp(0)
deleted_at DateTime? @db.Timestamp(0)
category_id String?
base_sale_price Decimal @default(0.00) @db.Decimal(15, 0)
account_id String
complex_id String
category GoodCategory? @relation(fields: [category_id], references: [id])
sales_invoice_items SalesInvoiceItem[]
@@index([category_id])
@@map("goods")
}
model GoodCategory {
id String @id @default(uuid())
name String @db.VarChar(100)
description String? @db.Text
image_url String? @db.VarChar(255)
account_id String
complex_id String
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt @db.Timestamp(0)
deleted_at DateTime? @db.Timestamp(0)
goods Good[]
@@map("good_categories")
}
@@ -1,4 +1,4 @@
model Device {
model UserDevices {
account_id String? @db.VarChar(255)
app_version String @db.VarChar(20)
build_number String @db.VarChar(20)
@@ -14,5 +14,5 @@ model Device {
browser_name String? @db.VarChar(100)
fcm_token String? @db.VarChar(100)
@@map("devices")
@@map("user_devices")
}
+119
View File
@@ -0,0 +1,119 @@
enum PaymentMethodType {
TERMINAL
CASH
SET_OFF
CARD
BANK
CHECK
OTHER
}
enum PurchaseReceiptStatus {
UNPAID
PARTIALLY_PAID
PAID
}
enum SalesInvoiceType {
GOOD
SERVICE
}
enum UnitType {
COUNT
GRAM
KILOGRAM
MILLILITER
LITER
METER
HOUR
}
enum GoodPricingModel {
STANDARD
GOLD
}
enum CustomerType {
INDIVIDUAL
LEGAL
UNKNOWN
}
enum UserStatus {
ACTIVE
INACTIVE
}
enum AccountRole {
OWNER
OPERATOR
ACCOUNTANT
}
enum AccountStatus {
ACTIVE
SUSPENDED
}
enum POSStatus {
ACTIVE
DISABLED
}
enum POSRole {
MANAGER
OPERATOR
VIEWER
}
enum LicenseType {
BASIC
PRO
ENTERPRISE
}
enum LicenseStatus {
ACTIVE
EXPIRED
SUSPENDED
}
enum POSType {
PSP
MOBILE
API
}
enum UserType {
LEGAL
INDIVIDUAL
}
enum AccountType {
PARTNER
BUSINESS
ADMIN
PROVIDER
POS
}
enum PartnerRole {
ADMIN
OPERATOR
}
enum BusinessRole {
ADMIN
OPERATOR
}
enum ProviderRole {
ADMIN
OPERATOR
}
enum TokenType {
ACCESS
REFRESH
}
+45
View File
@@ -0,0 +1,45 @@
model Good {
id String @id @default(uuid())
name String @db.VarChar(255)
description String? @db.Text
sku String @db.VarChar(100)
local_sku String? @unique() @db.VarChar(100)
barcode String? @unique() @db.VarChar(100)
base_sale_price Decimal? @default(0.00) @db.Decimal(15, 0)
is_default_guild_good Boolean @default(false)
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt @db.Timestamp(0)
deleted_at DateTime? @db.Timestamp(0)
complex_id String?
category_id String?
guild_id String?
category GoodCategory? @relation(fields: [category_id], references: [id])
complex Complex? @relation(fields: [complex_id], references: [id])
guild Guild? @relation(fields: [guild_id], references: [id])
sales_invoice_items SalesInvoiceItem[]
@@index([category_id])
@@map("goods")
}
model GoodCategory {
id String @id @default(uuid())
name String @db.VarChar(100)
description String? @db.Text
image_url String? @db.VarChar(255)
complex_id String?
is_default_guild_good Boolean @default(false)
guild_id String?
created_at DateTime @default(now()) @db.Timestamp(0)
updated_at DateTime @updatedAt @db.Timestamp(0)
deleted_at DateTime? @db.Timestamp(0)
goods Good[]
guild Guild? @relation(fields: [guild_id], references: [id])
complex Complex? @relation(fields: [complex_id], references: [id])
@@map("good_categories")
}
@@ -20,15 +20,14 @@ model SalesInvoice {
}
model SalesInvoiceItem {
id String @id @default(uuid())
quantity Decimal @db.Decimal(10, 0)
id String @id @default(uuid())
quantity Decimal @db.Decimal(10, 0)
unit_type UnitType
unit_price Decimal @default(0.00) @db.Decimal(15, 2)
total_amount Decimal @default(0.00) @db.Decimal(15, 2)
created_at DateTime @default(now()) @db.Timestamp(0)
discount Decimal @default(0.00) @db.Decimal(15, 2)
notes String? @db.Text
pricingModel SalesInvoiceItemPricingModel @default(STANDARD)
unit_price Decimal @default(0.00) @db.Decimal(15, 2)
total_amount Decimal @default(0.00) @db.Decimal(15, 2)
created_at DateTime @default(now()) @db.Timestamp(0)
discount Decimal @default(0.00) @db.Decimal(15, 2)
notes String? @db.Text
invoice_id String
good_id String?
+20 -334
View File
@@ -1,340 +1,26 @@
import { PasswordUtil } from '@/common/utils/password.util'
import { prisma } from '../src/lib/prisma'
async function main() {
// if ((await prisma.role.count()) === 0) {
// await prisma.role.upsert({
// where: { id: 0, name: 'Admin' },
// update: {},
// create: {
// name: 'Admin',
// },
// })
// }
// if ((await prisma.user.count()) === 0) {
// const adminRole = await prisma.role.findUnique({ where: { name: 'Admin' } })
// if (!adminRole) {
// return
// }
// await prisma.user.upsert({
// where: { id: 1, firstName: 'عباس', lastName: 'حسنی' },
// update: {},
// create: {
// firstName: 'عباس',
// lastName: 'حسنی',
// roleId: adminRole.id,
// mobileNumber: '09120258156',
// password: '12345678',
// },
// })
// }
// if ((await prisma.inventory.count()) === 0) {
// await prisma.inventory.createMany({
// data: [
// { name: 'انبار مرکزی', location: 'تهران', isPointOfSale: false, isActive: true },
// {
// name: 'فروشگاه حضوری',
// location: 'مرکز شهر',
// isPointOfSale: true,
// isActive: true,
// },
// {
// name: 'فروشگاه اینترنتی',
// location: 'مرکز شهر',
// isPointOfSale: true,
// isActive: true,
// },
// ],
// })
// }
// if ((await prisma.productCategory.count()) === 0) {
// await prisma.productCategory.createMany({
// data: Array.from({ length: 10 }, (_, i) => ({ name: `دسته‌ی ${i + 1}` })),
// })
// }
// if ((await prisma.productBrand.count()) === 0) {
// await prisma.productBrand.createMany({
// data: Array.from({ length: 10 }, (_, i) => ({ name: `برند ${i + 1}` })),
// })
// }
// if ((await prisma.supplier.count()) === 0) {
// await prisma.supplier.createMany({
// data: Array.from({ length: 9 }, (_, i) => ({
// firstName: 'تامین‌',
// lastName: `کننده ${i + 1}`,
// mobileNumber: `0912000000${i + 1}`,
// email: `supplier${i + 1}@example.com`,
// })),
// })
// }
// if ((await prisma.customer.count()) === 0) {
// await prisma.customer.createMany({
// data: Array.from({ length: 5 }, (_, i) => ({
// firstName: 'مشتری',
// lastName: `${i + 1}`,
// mobileNumber: `0913000000${i + 1}`,
// email: `customer${i + 1}@example.com`,
// })),
// })
// }
// if ((await prisma.product.count()) === 0) {
// const categories = await prisma.productCategory.findMany()
// const brands = await prisma.productBrand.findMany()
// await prisma.product.createMany({
// data: Array.from({ length: 20 }, (_, i) => ({
// name: `کالای ${i + 1}`,
// sku: `SKU-${1000 + i + 1}`,
// salePrice: parseInt((Math.random() * (100 - 10) + 10).toString()) * 10000,
// categoryId: categories[i % categories.length].id,
// brandId: brands[i % brands.length].id,
// })),
// })
// }
// if ((await prisma.bank.count()) === 0) {
// await prisma.bank.createMany({
// data: [
// {
// name: 'آینده',
// shortName: 'ain',
// },
// {
// name: 'ایران زمین',
// shortName: 'irz',
// },
// {
// name: 'اقتصاد نوین',
// shortName: 'eqn',
// },
// {
// name: 'انصار',
// shortName: 'ans',
// },
// {
// name: 'پاسارگاد',
// shortName: 'pas',
// },
// {
// name: 'پارسیان',
// shortName: 'prs',
// },
// {
// name: 'پست‌ بانک ایران',
// shortName: 'pbi',
// },
// {
// name: 'تجارت',
// shortName: 'tej',
// },
// {
// name: 'توسعه تعاون',
// shortName: 'tav',
// },
// {
// name: 'توسعه صادرات',
// shortName: 'tes',
// },
// {
// name: 'حکمت ایرانیان',
// shortName: 'hek',
// },
// {
// name: 'رفاه کارگران',
// shortName: 'ref',
// },
// {
// name: 'قرض‌الحسنه رسالت',
// shortName: 'res',
// },
// {
// name: 'قرض‌الحسنه مهر ایران',
// shortName: 'meh',
// },
// {
// name: 'قوامین',
// shortName: 'qva',
// },
// {
// name: 'کشاورزی',
// shortName: 'kes',
// },
// {
// name: 'کوثر',
// shortName: 'kos',
// },
// {
// name: 'دی',
// shortName: 'diy',
// },
// {
// name: 'صنعت و معدن',
// shortName: 'san',
// },
// {
// name: 'سینا',
// shortName: 'sin',
// },
// {
// name: 'سرمایه',
// shortName: 'sar',
// },
// {
// name: 'سپه',
// shortName: 'sep',
// },
// {
// name: 'شهر',
// shortName: 'shr',
// },
// {
// name: 'صادرات ایران',
// shortName: 'sir',
// },
// {
// name: 'سامان',
// shortName: 'sam',
// },
// {
// name: 'مرکزی',
// shortName: 'mar',
// },
// {
// name: 'مسکن',
// shortName: 'mas',
// },
// {
// name: 'ملت',
// shortName: 'mel',
// },
// {
// name: 'ملی ایران',
// shortName: 'mli',
// },
// {
// name: 'مهر اقتصاد',
// shortName: 'meg',
// },
// {
// name: 'کارآفرین',
// shortName: 'kar',
// },
// {
// name: 'تات',
// shortName: 'tat',
// },
// ],
// })
// }
// if ((await prisma.bankBranch.count()) === 0) {
// await prisma.bankBranch.createMany({
// data: [
// {
// bankId: 1,
// name: 'شعبه مرکزی',
// code: '001',
// },
// {
// bankId: 2,
// name: 'شعبه مرکزی',
// code: '002',
// },
// {
// bankId: 1,
// name: 'شعبه ونک',
// code: '003',
// },
// ],
// })
// }
// if ((await prisma.bankAccount.count()) === 0) {
// await prisma.bankAccount.createMany({
// data: [
// {
// branchId: 1,
// accountNumber: '1234567890',
// name: 'حساب اصلی آینده',
// iban: 'IR000123456789012345678901',
// },
// {
// branchId: 2,
// accountNumber: '0987654321',
// name: 'حساب اصلی ایران زمین',
// iban: 'IR000987654321098765432109',
// },
// {
// branchId: 3,
// accountNumber: '1122334455',
// name: 'حساب ونک آینده',
// iban: 'IR000112233445566778899001',
// },
// ],
// })
// }
// if ((await prisma.inventoryBankAccount.count()) === 0) {
// const inventories = await prisma.inventory.findMany()
// const bankAccounts = await prisma.bankAccount.findMany()
// if (inventories.length || bankAccounts.length) {
// // Assign bank accounts to inventories
// const inventoryBankAccounts = []
// for (let i = 0; i < inventories.length; i++) {
// const inventory = inventories[i]
// const bankAccount = bankAccounts[i % bankAccounts.length] // Cycle through bank accounts
// // @ts-ignore
// inventoryBankAccounts.push({
// inventoryId: inventory.id,
// bankAccountId: bankAccount.id,
// })
// }
// await prisma.inventoryBankAccount.createMany({
// data: inventoryBankAccounts,
// })
// }
// }
// if ((await prisma.posAccount.count()) === 0) {
// const inventories = await prisma.inventory.findMany({
// where: { isPointOfSale: true },
// })
// const inventoryBankAccounts = await prisma.inventoryBankAccount.findMany()
// const posAccounts = []
// for (let i = 0; i < inventories.length; i++) {
// const inventory = inventories[i]
// // Find a bank account assigned to this inventory
// const inventoryBankAccount = inventoryBankAccounts.find(
// iba => iba.inventoryId === inventory.id,
// )
// if (inventoryBankAccount) {
// // @ts-ignore
// posAccounts.push({
// name: `پوز ${inventory.name}`,
// code: `POS${(i + 1).toString().padStart(3, '0')}`,
// description: `پوز فروشگاه ${inventory.name}`,
// inventoryId: inventory.id,
// bankAccountId: inventoryBankAccount.bankAccountId,
// })
// }
// }
// await prisma.posAccount.createMany({
// data: posAccounts,
// })
// }
// Seed purchase, transfer, and sales transactions
// const inventories = await prisma.inventory.findMany()
// const products = await prisma.product.findMany({ take: 5 }) // select 5 products for demo
// const supplier = await prisma.supplier.findFirst()
// const customers = await prisma.customer.findMany({ take: 2 })
// if (supplier && customers.length > 0) {
// PurchaseReceiptsService.prototype.create({
// code: '123123',
// inventoryId: inventories[0].id,
// supplierId: supplier.id,
// paidAmount: 0,
// totalAmount: products.reduce((acc, a) => (acc += Number(a.salePrice) * 10), 0),
// items: products.map(product => ({
// productId: product.id,
// count: 10,
// unitPrice: Number(product.salePrice),
// total: 10 * Number(product.salePrice),
// })),
// })
// }
const password = await PasswordUtil.hash('123456')
const adminUser = await prisma.account.upsert({
where: { username: 'superAdmin' },
update: {},
create: {
username: 'superAdmin',
password,
type: 'ADMIN',
status: 'ACTIVE',
user: {
create: {
first_name: 'عباس',
last_name: 'حسنی',
national_code: '0016022289',
mobile_number: '09120258156',
},
},
},
})
}
main()