feat: add consumer accounts and business activities management
- Implemented AccountsService for managing consumer accounts including create, update, delete, and find operations. - Created DTOs for account creation and updates. - Developed BusinessActivitiesController and BusinessActivitiesService for handling business activities related to consumers. - Added complexes management with ComplexesController and ComplexesService. - Introduced POS management with ComplexPosesController and ComplexPosesService. - Created necessary DTOs for business activities and POS. - Established Licenses management with LicensesController and LicensesService. - Integrated consumer management with PartnerConsumersController and PartnerConsumersService. - Added Prisma module imports and service connections across modules.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `tax_id` on the `complexes` table. All the data in the column will be lost.
|
||||
- A unique constraint covering the columns `[economic_code]` on the table `business_activities` will be added. If there are existing duplicate values, this will fail.
|
||||
- A unique constraint covering the columns `[mobile_number,national_code,partner_id]` on the table `consumers` will be added. If there are existing duplicate values, this will fail.
|
||||
- Added the required column `economic_code` to the `business_activities` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `national_code` to the `consumers` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `partner_id` to the `consumers` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- DropIndex
|
||||
DROP INDEX `consumers_mobile_number_key` ON `consumers`;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `business_activities` ADD COLUMN `economic_code` VARCHAR(191) NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `complexes` DROP COLUMN `tax_id`;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `consumers` ADD COLUMN `national_code` VARCHAR(191) NOT NULL,
|
||||
ADD COLUMN `partner_id` VARCHAR(191) NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `licenses` ADD COLUMN `accounts_limit` INTEGER NOT NULL DEFAULT 3;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX `business_activities_economic_code_key` ON `business_activities`(`economic_code`);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX `consumers_mobile_number_national_code_partner_id_key` ON `consumers`(`mobile_number`, `national_code`, `partner_id`);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `consumers` ADD CONSTRAINT `consumers_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- Added the required column `branch_code` to the `complexes` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE `complexes` ADD COLUMN `branch_code` VARCHAR(191) NOT NULL;
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `charged_license_transaction_id` on the `licenses` table. All the data in the column will be lost.
|
||||
- You are about to drop the `activated_licenses` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `charged_license_transactions` table. If the table is not empty, all the data it contains will be lost.
|
||||
- A unique constraint covering the columns `[mobile_number,partner_id]` on the table `consumers` will be added. If there are existing duplicate values, this will fail.
|
||||
- A unique constraint covering the columns `[national_code,partner_id]` on the table `consumers` will be added. If there are existing duplicate values, this will fail.
|
||||
- Added the required column `charge_transaction_id` to the `licenses` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `activated_licenses` DROP FOREIGN KEY `activated_licenses_consumer_id_fkey`;
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `activated_licenses` DROP FOREIGN KEY `activated_licenses_license_id_fkey`;
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `charged_license_transactions` DROP FOREIGN KEY `charged_license_transactions_partner_id_fkey`;
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE `licenses` DROP FOREIGN KEY `licenses_charged_license_transaction_id_fkey`;
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX `consumers_mobile_number_national_code_partner_id_key` ON `consumers`;
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX `licenses_charged_license_transaction_id_fkey` ON `licenses`;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `licenses` DROP COLUMN `charged_license_transaction_id`,
|
||||
ADD COLUMN `charge_transaction_id` VARCHAR(191) NOT NULL;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE `activated_licenses`;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE `charged_license_transactions`;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `licenses_activated` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`starts_at` DATETIME(3) NOT NULL,
|
||||
`expires_at` DATETIME(3) NOT NULL,
|
||||
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updated_at` TIMESTAMP(0) NOT NULL,
|
||||
`license_id` VARCHAR(191) NOT NULL,
|
||||
`business_activity_id` VARCHAR(191) NOT NULL,
|
||||
|
||||
UNIQUE INDEX `licenses_activated_id_key`(`id`),
|
||||
UNIQUE INDEX `licenses_activated_license_id_key`(`license_id`),
|
||||
UNIQUE INDEX `licenses_activated_business_activity_id_key`(`business_activity_id`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `license_charged_transactions` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`activation_expires_at` DATETIME(3) NOT NULL,
|
||||
`tracking_code` VARCHAR(191) NOT NULL,
|
||||
`purchased_count` INTEGER NOT NULL,
|
||||
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updated_at` TIMESTAMP(0) NOT NULL,
|
||||
`partner_id` VARCHAR(191) NOT NULL,
|
||||
|
||||
UNIQUE INDEX `license_charged_transactions_tracking_code_key`(`tracking_code`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `license_renew` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updated_at` TIMESTAMP(0) NOT NULL,
|
||||
`charge_transaction_id` VARCHAR(191) NOT NULL,
|
||||
`activation_id` VARCHAR(191) NOT NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `license_renew_charge_transaction` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`activation_expires_at` DATETIME(3) NOT NULL,
|
||||
`tracking_code` VARCHAR(191) NOT NULL,
|
||||
`purchased_count` INTEGER NOT NULL,
|
||||
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updated_at` TIMESTAMP(0) NOT NULL,
|
||||
`partner_id` VARCHAR(191) NOT NULL,
|
||||
|
||||
UNIQUE INDEX `license_renew_charge_transaction_tracking_code_key`(`tracking_code`),
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `partner_account_quota_charge_transaction` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`purchased_count` INTEGER NOT NULL,
|
||||
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updated_at` TIMESTAMP(0) NOT NULL,
|
||||
`partner_id` VARCHAR(191) NOT NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `partner_account_quota_allocation` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`created_at` TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
|
||||
`updated_at` TIMESTAMP(0) NOT NULL,
|
||||
`charge_transaction_id` VARCHAR(191) NOT NULL,
|
||||
`license_id` VARCHAR(191) NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX `consumers_mobile_number_partner_id_key` ON `consumers`(`mobile_number`, `partner_id`);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX `consumers_national_code_partner_id_key` ON `consumers`(`national_code`, `partner_id`);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `licenses` ADD CONSTRAINT `licenses_charge_transaction_id_fkey` FOREIGN KEY (`charge_transaction_id`) REFERENCES `license_charged_transactions`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `licenses_activated` ADD CONSTRAINT `licenses_activated_license_id_fkey` FOREIGN KEY (`license_id`) REFERENCES `licenses`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `licenses_activated` ADD CONSTRAINT `licenses_activated_business_activity_id_fkey` FOREIGN KEY (`business_activity_id`) REFERENCES `business_activities`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `license_charged_transactions` ADD CONSTRAINT `license_charged_transactions_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `license_renew` ADD CONSTRAINT `license_renew_charge_transaction_id_fkey` FOREIGN KEY (`charge_transaction_id`) REFERENCES `license_renew_charge_transaction`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `license_renew` ADD CONSTRAINT `license_renew_activation_id_fkey` FOREIGN KEY (`activation_id`) REFERENCES `licenses_activated`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `license_renew_charge_transaction` ADD CONSTRAINT `license_renew_charge_transaction_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `partner_account_quota_charge_transaction` ADD CONSTRAINT `partner_account_quota_charge_transaction_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `partner_account_quota_allocation` ADD CONSTRAINT `partner_account_quota_allocation_charge_transaction_id_fkey` FOREIGN KEY (`charge_transaction_id`) REFERENCES `partner_account_quota_charge_transaction`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `partner_account_quota_allocation` ADD CONSTRAINT `partner_account_quota_allocation_license_id_fkey` FOREIGN KEY (`license_id`) REFERENCES `licenses`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[tracking_code]` on the table `partner_account_quota_charge_transaction` will be added. If there are existing duplicate values, this will fail.
|
||||
- Added the required column `expires_at` to the `license_renew` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `activation_expires_at` to the `partner_account_quota_charge_transaction` table without a default value. This is not possible if the table is not empty.
|
||||
- Added the required column `tracking_code` to the `partner_account_quota_charge_transaction` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE `license_renew` ADD COLUMN `expires_at` DATETIME(3) NOT NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE `partner_account_quota_charge_transaction` ADD COLUMN `activation_expires_at` DATETIME(3) NOT NULL,
|
||||
ADD COLUMN `tracking_code` VARCHAR(191) NOT NULL;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX `partner_account_quota_charge_transaction_tracking_code_key` ON `partner_account_quota_charge_transaction`(`tracking_code`);
|
||||
@@ -1,5 +1,5 @@
|
||||
model AdminAccount {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
@@ -14,7 +14,7 @@ model AdminAccount {
|
||||
}
|
||||
|
||||
model Admin {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
mobile_number String @unique()
|
||||
national_code String? @unique()
|
||||
first_name String
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
model Account {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
username String @unique()
|
||||
password String
|
||||
status AccountStatus
|
||||
@@ -17,7 +17,7 @@ model Account {
|
||||
}
|
||||
|
||||
// model Token {
|
||||
// id String @id @d @uniqueefault(uuid())
|
||||
// id String @id @d @uniqueefault(ulid())
|
||||
// token String @unique
|
||||
// type TokenType
|
||||
// created_at DateTime @default(now())
|
||||
@@ -31,7 +31,7 @@ model Account {
|
||||
// }
|
||||
|
||||
// model VerificationCode {
|
||||
// id String @id @default(uuid())
|
||||
// id String @id @default(ulid())
|
||||
// code String
|
||||
// is_used Boolean @default(false)
|
||||
// created_at DateTime @default(now())
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
model ConsumerAccount {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
role ConsumerRole
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
@@ -8,7 +8,7 @@ model ConsumerAccount {
|
||||
consumer_id String
|
||||
consumer Consumer @relation(fields: [consumer_id], references: [id])
|
||||
|
||||
account_id String @unique
|
||||
account_id String @unique()
|
||||
account Account @relation(fields: [account_id], references: [id])
|
||||
|
||||
permission PermissionConsumer?
|
||||
@@ -18,8 +18,9 @@ model ConsumerAccount {
|
||||
}
|
||||
|
||||
model Consumer {
|
||||
id String @id @default(uuid())
|
||||
mobile_number String @unique()
|
||||
id String @id @default(ulid())
|
||||
mobile_number String
|
||||
national_code String
|
||||
first_name String
|
||||
last_name String
|
||||
status ConsumerStatus @default(ACTIVE)
|
||||
@@ -27,17 +28,23 @@ model Consumer {
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
partner_id String
|
||||
partner Partner @relation(fields: [partner_id], references: [id])
|
||||
|
||||
consumer_accounts ConsumerAccount[]
|
||||
business_activities BusinessActivity[]
|
||||
activated_licenses ActivatedLicense[]
|
||||
consumer_devices ConsumerDevices[]
|
||||
|
||||
@@unique([mobile_number, partner_id])
|
||||
@@unique([national_code, partner_id])
|
||||
@@map("consumers")
|
||||
}
|
||||
|
||||
model BusinessActivity {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
id String @id @default(ulid())
|
||||
economic_code String @unique()
|
||||
name String
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
@@ -49,15 +56,16 @@ model BusinessActivity {
|
||||
|
||||
complexes Complex[]
|
||||
permission_businesses PermissionBusiness[]
|
||||
license_activation LicenseActivation?
|
||||
|
||||
@@map("business_activities")
|
||||
}
|
||||
|
||||
model Complex {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
address String?
|
||||
tax_id String?
|
||||
id String @id @default(ulid())
|
||||
name String
|
||||
branch_code String
|
||||
address String?
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
@@ -77,14 +85,15 @@ model Complex {
|
||||
}
|
||||
|
||||
model Pos {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
serial String @unique
|
||||
model String?
|
||||
status POSStatus @default(ACTIVE)
|
||||
pos_type POSType
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
id String @id @default(ulid())
|
||||
name String
|
||||
serial String @unique()
|
||||
model String?
|
||||
status POSStatus @default(ACTIVE)
|
||||
pos_type POSType
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
complex_id String
|
||||
complex Complex @relation(fields: [complex_id], references: [id])
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
model DeviceBrand {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
name String
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
@@ -11,7 +11,7 @@ model DeviceBrand {
|
||||
}
|
||||
|
||||
model Device {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
name String
|
||||
os_version String?
|
||||
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
model License {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
accounts_limit Int @default(3)
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
charged_license_transaction_id String
|
||||
charged_license_transaction ChargedLicenseTransactions @relation(fields: [charged_license_transaction_id], references: [id])
|
||||
charge_transaction_id String
|
||||
charge_transaction LicenseChargeTransaction @relation(fields: [charge_transaction_id], references: [id])
|
||||
|
||||
activated_license ActivatedLicense?
|
||||
activation LicenseActivation?
|
||||
allocations PartnerAccountQuotaAllocation[]
|
||||
|
||||
@@map("licenses")
|
||||
}
|
||||
|
||||
model ActivatedLicense {
|
||||
id String @id @unique() @default(uuid())
|
||||
model LicenseActivation {
|
||||
id String @id @unique() @default(ulid())
|
||||
starts_at DateTime
|
||||
expires_at DateTime
|
||||
|
||||
@@ -23,16 +25,18 @@ model ActivatedLicense {
|
||||
license_id String @unique
|
||||
license License @relation(fields: [license_id], references: [id])
|
||||
|
||||
consumer_id String
|
||||
consumer Consumer @relation(fields: [consumer_id], references: [id])
|
||||
business_activity_id String @unique
|
||||
business_activity BusinessActivity @relation(fields: [business_activity_id], references: [id])
|
||||
license_renews LicenseRenew[]
|
||||
|
||||
@@map("activated_licenses")
|
||||
@@map("licenses_activated")
|
||||
}
|
||||
|
||||
model ChargedLicenseTransactions {
|
||||
id String @id @default(uuid())
|
||||
model LicenseChargeTransaction {
|
||||
id String @id @default(ulid())
|
||||
activation_expires_at DateTime
|
||||
tracking_code String @unique()
|
||||
purchased_count Int
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
@@ -42,5 +46,70 @@ model ChargedLicenseTransactions {
|
||||
|
||||
licenses License[]
|
||||
|
||||
@@map("charged_license_transactions")
|
||||
@@map("license_charged_transactions")
|
||||
}
|
||||
|
||||
model LicenseRenew {
|
||||
id String @id @default(ulid())
|
||||
expires_at DateTime
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
charge_transaction_id String
|
||||
charge_transaction LicenseRenewChargeTransaction @relation(fields: [charge_transaction_id], references: [id])
|
||||
|
||||
activation_id String
|
||||
activation LicenseActivation @relation(fields: [activation_id], references: [id])
|
||||
|
||||
@@map("license_renew")
|
||||
}
|
||||
|
||||
model LicenseRenewChargeTransaction {
|
||||
id String @id @default(ulid())
|
||||
activation_expires_at DateTime
|
||||
tracking_code String @unique()
|
||||
purchased_count Int
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
partner_id String
|
||||
partner Partner @relation(fields: [partner_id], references: [id])
|
||||
|
||||
license_renews LicenseRenew[]
|
||||
|
||||
@@map("license_renew_charge_transaction")
|
||||
}
|
||||
|
||||
model PartnerAccountQuotaChargeTransaction {
|
||||
id String @id @default(ulid())
|
||||
activation_expires_at DateTime
|
||||
tracking_code String @unique()
|
||||
purchased_count Int
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
partner_id String
|
||||
partner Partner @relation(fields: [partner_id], references: [id])
|
||||
|
||||
allocations PartnerAccountQuotaAllocation[]
|
||||
|
||||
@@map("partner_account_quota_charge_transaction")
|
||||
}
|
||||
|
||||
model PartnerAccountQuotaAllocation {
|
||||
id String @id @default(ulid())
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @updatedAt() @db.Timestamp(0)
|
||||
|
||||
charge_transaction_id String
|
||||
charge_transaction PartnerAccountQuotaChargeTransaction @relation(fields: [charge_transaction_id], references: [id])
|
||||
|
||||
license_id String?
|
||||
license License? @relation(fields: [license_id], references: [id])
|
||||
|
||||
@@map("partner_account_quota_allocation")
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
model PartnerAccount {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
role PartnerRole
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
@@ -15,7 +15,7 @@ model PartnerAccount {
|
||||
}
|
||||
|
||||
model Partner {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
name String
|
||||
code String @unique()
|
||||
status PartnerStatus @default(ACTIVE)
|
||||
@@ -23,8 +23,11 @@ model Partner {
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
updated_at DateTime @default(now()) @updatedAt @db.Timestamp(0)
|
||||
|
||||
partner_accounts PartnerAccount[]
|
||||
chargedLicenseTransactions ChargedLicenseTransactions[]
|
||||
consumers Consumer[]
|
||||
partner_accounts PartnerAccount[]
|
||||
license_charge_transactions LicenseChargeTransaction[]
|
||||
account_quota_charge_transactions PartnerAccountQuotaChargeTransaction[]
|
||||
license_renew_charge_transactions LicenseRenewChargeTransaction[]
|
||||
|
||||
@@map("partners")
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
model PermissionConsumer {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
|
||||
consumer_account_id String @unique
|
||||
consumer_account ConsumerAccount @relation(fields: [consumer_account_id], references: [id], onDelete: Cascade)
|
||||
@@ -12,7 +12,7 @@ model PermissionConsumer {
|
||||
}
|
||||
|
||||
model PermissionPos {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
role POSRole
|
||||
|
||||
pos_id String
|
||||
@@ -26,7 +26,7 @@ model PermissionPos {
|
||||
}
|
||||
|
||||
model PermissionComplex {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
role ComplexRole
|
||||
|
||||
complex_id String
|
||||
@@ -40,7 +40,7 @@ model PermissionComplex {
|
||||
}
|
||||
|
||||
model PermissionBusiness {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
role BusinessRole
|
||||
|
||||
business_id String
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
model ProviderAccount {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
role ProviderRole
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
@@ -15,7 +15,7 @@ model ProviderAccount {
|
||||
}
|
||||
|
||||
model Provider {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
code String @unique()
|
||||
status PartnerStatus @default(ACTIVE)
|
||||
name String
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
model ApplicationReleasedInfo {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
version String
|
||||
build_number String
|
||||
is_minimum_supported Boolean @default(false)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
model Customer {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
is_favorite Boolean? @default(false)
|
||||
|
||||
created_at DateTime @default(now()) @db.Timestamp(0)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
model Good {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
name String @db.VarChar(255)
|
||||
is_default_guild_good Boolean @default(false)
|
||||
sku String @db.VarChar(100)
|
||||
@@ -27,7 +27,7 @@ model Good {
|
||||
}
|
||||
|
||||
model GoodCategory {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
name String @db.VarChar(100)
|
||||
description String? @db.Text
|
||||
image_url String? @db.VarChar(255)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
model Guild {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
name String
|
||||
code String?
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
model SalesInvoice {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
code String @unique @db.VarChar(100)
|
||||
total_amount Decimal @db.Decimal(15, 2)
|
||||
notes String? @db.Text
|
||||
@@ -22,7 +22,7 @@ model SalesInvoice {
|
||||
}
|
||||
|
||||
model SalesInvoiceItem {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
quantity Decimal @db.Decimal(10, 0)
|
||||
unit_type UnitType
|
||||
unit_price Decimal @default(0.00) @db.Decimal(15, 2)
|
||||
@@ -46,7 +46,7 @@ model SalesInvoiceItem {
|
||||
}
|
||||
|
||||
model SalesInvoicePayment {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
invoice_id String
|
||||
amount Decimal @db.Decimal(15, 2)
|
||||
payment_method PaymentMethodType
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
model Service {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
name String @db.VarChar(255)
|
||||
description String? @db.Text
|
||||
sku String @unique() @db.VarChar(100)
|
||||
@@ -21,7 +21,7 @@ model Service {
|
||||
}
|
||||
|
||||
model ServiceCategory {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(ulid())
|
||||
name String @db.VarChar(100)
|
||||
description String? @db.Text
|
||||
image_url String? @db.VarChar(255)
|
||||
|
||||
+90
-57
@@ -1,4 +1,5 @@
|
||||
import { PasswordUtil } from '@/common/utils/password.util'
|
||||
import { generateTrackingCode } from '@/common/utils/tracking-code-generator.util'
|
||||
import { GoodPricingModel, POSType, UnitType } from '@/generated/prisma/enums'
|
||||
import { GoodCreateInput, GoodCreateManyInput } from '@/generated/prisma/models'
|
||||
import { prisma } from '../src/lib/prisma'
|
||||
@@ -240,60 +241,9 @@ async function main() {
|
||||
}
|
||||
}
|
||||
|
||||
// ****************** BA Start ****************** //
|
||||
const ba = await prisma.businessActivity.count()
|
||||
|
||||
if (!ba) {
|
||||
await prisma.businessActivity.create({
|
||||
data: {
|
||||
name: 'طلا فروشی',
|
||||
consumer: {
|
||||
create: {
|
||||
first_name: 'محمد',
|
||||
last_name: 'زرگر',
|
||||
mobile_number: '09120258155',
|
||||
consumer_accounts: {
|
||||
create: {
|
||||
role: 'OWNER',
|
||||
account: {
|
||||
create: {
|
||||
username: 'zargar',
|
||||
password: await PasswordUtil.hash('123456'),
|
||||
status: 'ACTIVE',
|
||||
type: 'CONSUMER',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
guild: {
|
||||
connect: {
|
||||
id: guilds[0].id,
|
||||
},
|
||||
},
|
||||
complexes: {
|
||||
create: {
|
||||
name: 'فروشگاه طلای مرکزی',
|
||||
address: 'تهران، خیابان جمهوری',
|
||||
tax_id: '12312452345765',
|
||||
pos_list: {
|
||||
create: {
|
||||
name: 'لاین ۱',
|
||||
pos_type: POSType.WEB,
|
||||
serial: '12312312',
|
||||
status: 'ACTIVE',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
// ****************** BA Start ****************** //
|
||||
|
||||
// ****************** partner Start ****************** //
|
||||
let partner = await prisma.partner.findFirst()
|
||||
let license = await prisma.license.findFirst()
|
||||
if (!partner) {
|
||||
partner = await prisma.partner.create({
|
||||
data: {
|
||||
@@ -316,7 +266,7 @@ async function main() {
|
||||
},
|
||||
})
|
||||
}
|
||||
if (partner) {
|
||||
if (partner && !license) {
|
||||
await prisma.$transaction(async tx => {
|
||||
const startOfToday = new Date()
|
||||
startOfToday.setHours(0, 0, 0, 0)
|
||||
@@ -332,10 +282,11 @@ async function main() {
|
||||
startOfToday.setFullYear(year)
|
||||
startOfToday.setMonth(expMonth)
|
||||
|
||||
const transaction = await tx.chargedLicenseTransactions.create({
|
||||
const transaction = await tx.licenseChargeTransaction.create({
|
||||
data: {
|
||||
activation_expires_at: startOfToday,
|
||||
tracking_code: `LIC-${'random'}`,
|
||||
purchased_count: 1,
|
||||
tracking_code: generateTrackingCode('LIC', 6),
|
||||
partner: {
|
||||
connect: {
|
||||
id: partner.id,
|
||||
@@ -347,9 +298,9 @@ async function main() {
|
||||
},
|
||||
})
|
||||
if (transaction)
|
||||
await tx.license.create({
|
||||
license = await tx.license.create({
|
||||
data: {
|
||||
charged_license_transaction: {
|
||||
charge_transaction: {
|
||||
connect: {
|
||||
id: transaction.id,
|
||||
},
|
||||
@@ -359,6 +310,88 @@ async function main() {
|
||||
})
|
||||
}
|
||||
|
||||
// ****************** BA Start ****************** //
|
||||
const ba = await prisma.businessActivity.count()
|
||||
|
||||
if (!ba && license) {
|
||||
const startOfToday = new Date()
|
||||
startOfToday.setHours(0, 0, 0, 0)
|
||||
|
||||
let year = startOfToday.getFullYear()
|
||||
let expYear = year + 1
|
||||
// if (expMonth > 11) {
|
||||
// expMonth = expMonth - 11
|
||||
// year = year + 1
|
||||
// }
|
||||
|
||||
startOfToday.setFullYear(expYear)
|
||||
|
||||
await prisma.businessActivity.create({
|
||||
data: {
|
||||
name: 'طلا فروشی',
|
||||
economic_code: '0111111111',
|
||||
license_activation: {
|
||||
create: {
|
||||
expires_at: startOfToday,
|
||||
starts_at: new Date(),
|
||||
license: {
|
||||
connect: {
|
||||
id: license.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
consumer: {
|
||||
create: {
|
||||
first_name: 'محمد',
|
||||
last_name: 'زرگر',
|
||||
mobile_number: '09120258155',
|
||||
national_code: '1234567890',
|
||||
consumer_accounts: {
|
||||
create: {
|
||||
role: 'OWNER',
|
||||
account: {
|
||||
create: {
|
||||
username: 'zargar',
|
||||
password: await PasswordUtil.hash('123456'),
|
||||
status: 'ACTIVE',
|
||||
type: 'CONSUMER',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
partner: {
|
||||
connect: {
|
||||
id: partner.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
guild: {
|
||||
connect: {
|
||||
id: guilds[0].id,
|
||||
},
|
||||
},
|
||||
complexes: {
|
||||
create: {
|
||||
name: 'فروشگاه طلای مرکزی',
|
||||
address: 'تهران، خیابان جمهوری',
|
||||
branch_code: '12332',
|
||||
pos_list: {
|
||||
create: {
|
||||
name: 'لاین ۱',
|
||||
pos_type: POSType.WEB,
|
||||
serial: '12312312',
|
||||
status: 'ACTIVE',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
// ****************** BA Start ****************** //
|
||||
|
||||
// ****************** provider Start ****************** //
|
||||
const provider = await prisma.provider.count()
|
||||
if (!provider) {
|
||||
|
||||
Reference in New Issue
Block a user