From 9aa12184a1c6ef6fea54b706bcf84edfdc655adc Mon Sep 17 00:00:00 2001 From: ahasani194 Date: Thu, 21 May 2026 17:27:37 +0330 Subject: [PATCH] refactor: streamline Redis caching logic across services - Implemented a unified `getAndSet` method in RedisService to handle caching for single, list, and paginated responses. - Removed redundant cache checks and writes in various services, simplifying the code and improving readability. - Updated GoodsService, StockKeepingUnitsService, PartnerActivatedLicensesService, and others to utilize the new caching mechanism. - Adjusted Prisma connection limit for better resource management. --- Agents.md | 159 +- psp_backup_2026-04-27-05-50-22.sql | 1404 ----------------- .../admin/guilds/goods/goods.service.ts | 32 +- .../stock-keeping-units.service.ts | 26 +- .../activatedLicenses.service.ts | 113 +- .../chargedLicenseTransactions.service.ts | 67 +- .../admin/partners/partners.service.ts | 37 +- .../business-activities.service.ts | 31 +- src/modules/consumer/consumer.service.ts | 30 +- .../business-activities.service.ts | 65 +- .../complexes/complexes.service.ts | 90 +- .../partners/consumers/consumers.service.ts | 74 +- src/modules/pos/goods/goods.service.ts | 69 +- src/modules/pos/pos.service.ts | 214 +-- src/prisma/prisma.service.ts | 2 +- src/redis/redis.service.ts | 172 +- 16 files changed, 689 insertions(+), 1896 deletions(-) delete mode 100644 psp_backup_2026-04-27-05-50-22.sql diff --git a/Agents.md b/Agents.md index 90cde54..3010108 100644 --- a/Agents.md +++ b/Agents.md @@ -1,17 +1,162 @@ -# AGENT.md +# GapCode Agent Instructions + +# AGENTS.md Operational guide for AI/coding agents working in `consumer_api`. +--- + +# ⚡ RTK LOW-TOKEN EXECUTION POLICY (MANDATORY) + +This repository uses **RTK (Rust Token Killer)**. + +All shell interactions MUST prefer RTK wrappers to reduce token usage. + +If an RTK equivalent exists, **never use the raw command**. + +This repository can be large; uncontrolled shell output will quickly exhaust model context. + +--- + +# ✅ COMMAND REWRITE RULES (STRICT) + +Always rewrite commands using RTK: + +git status → rtk git status +git diff → rtk git diff +git log → rtk git log +ls → rtk ls +tree → rtk ls +cat → rtk read +grep → rtk grep +rg → rtk grep +find → rtk find + +Never run: + +- raw git commands for inspection +- raw cat +- raw grep +- raw ls +- raw tree + +--- + +# 📂 CODE NAVIGATION WORKFLOW (MANDATORY) + +When working in this repository follow this order: + +1️⃣ Discover structure + +rtk ls + +2️⃣ Search before opening files + +rtk grep + +3️⃣ Read only the necessary files + +rtk read + +4️⃣ For large files (>300 lines) + +rtk read -l aggressive + +5️⃣ For quick understanding + +rtk smart + +Never open many files blindly. + +Never read entire modules without searching first. + +--- + +# 🧠 DIFF INSPECTION RULES + +For reviewing repository changes: + +Use: + +rtk git diff + +For large diffs: + +rtk git diff -l aggressive + +Never run raw `git diff`. + +--- + +# 📁 FORBIDDEN PATHS + +Never inspect or read these directories unless explicitly required: + +node_modules/ +dist/ +build/ +coverage/ +.prisma/ +prisma/migrations/ + +These folders produce extremely large outputs and waste tokens. + +--- + +# 📄 FILE READING POLICY + +Preferred: + +rtk read file.ts + +Large file: + +rtk read file.ts -l aggressive + +Quick overview: + +rtk smart file.ts + +Never use `cat` for source code inspection. + +--- + +# 🔎 SEARCH POLICY + +Always search before opening files. + +Use: + +rtk grep + +Avoid raw recursive searches. + +--- + +# 🎯 TOKEN SAFETY RULES + +- Never scan the entire repository. +- Never dump full logs. +- Never output entire large files. +- Prefer targeted inspection. + +Token preservation is mandatory for this project. + +--- + ## Scope + - Applies to the whole repository. - Stack: NestJS + Prisma + TypeScript. ## Primary Goals + - Deliver minimal, safe, and focused changes. - Preserve existing API behavior unless explicitly requested. - Keep Prisma schema/data operations forward-safe. ## Project Conventions + - Keep module layering consistent: `controller -> service -> prisma/shared service`. - Reuse shared services for cross-module business logic (for example, sales invoice create flow). - Keep DTO validation at API boundaries; avoid unchecked `any` in new code. @@ -19,6 +164,7 @@ Operational guide for AI/coding agents working in `consumer_api`. - Prefer explicit Prisma `select`/`include` to control payload shape. ## Sales Invoice / TSP Rules + - `originalSend`, `correctionSend`, and `revoke` flows should be consistent and auditable. - For correction/revoke creation, prepare data from the related invoice when required. - Persist attempt records with clear status transitions (`QUEUED` -> final status). @@ -26,6 +172,7 @@ Operational guide for AI/coding agents working in `consumer_api`. - Avoid changing fiscal/tax status semantics without explicit approval. ## Prisma and Migration Safety + - Treat committed migrations as immutable history. - Prefer forward migrations; avoid destructive resets unless explicitly requested. - For data-affecting changes: @@ -34,12 +181,14 @@ Operational guide for AI/coding agents working in `consumer_api`. - keep logic idempotent where possible. ## Editing Principles + - Do not modify unrelated files. - Do not revert user changes unless asked. - Keep functions cohesive; extract shared logic when duplication appears. - Remove debug leftovers (`console.log`, dead code) before finishing unless explicitly needed. ## Validation Checklist (before handoff) + 1. Read target module/service/DTO end-to-end before edits. 2. Apply minimal patch with consistent naming. 3. Run typecheck: `pnpm -s tsc --noEmit`. @@ -47,12 +196,14 @@ Operational guide for AI/coding agents working in `consumer_api`. 5. Summarize changed files and behavior impact clearly. ## Useful Commands + - Typecheck: `pnpm -s tsc --noEmit` - Migration status: `pnpm prisma migrate status` - Create migration: `pnpm prisma migrate dev --name ` - Deploy migrations: `pnpm prisma migrate deploy` ## Communication Style + - Be concise and implementation-focused. - Call out assumptions/risk before risky steps. - Provide practical next actions after task completion. @@ -60,6 +211,7 @@ Operational guide for AI/coding agents working in `consumer_api`. ## Do / Don't (Repo-Specific) ### Do + - Do derive correction/revoke invoice creation data from `relatedInvoice` when the flow requires historical consistency. - Do keep TSP attempt lifecycle explicit (`QUEUED`, then update with provider result and timestamps). - Do use shared invoice-creation service instead of duplicating create logic across modules. @@ -67,6 +219,7 @@ Operational guide for AI/coding agents working in `consumer_api`. - Do keep Prisma queries tight with `select`/`include` only for fields you actually use. ### Don't + - Don't pass undefined/out-of-scope variables in TSP flows (common regressions: `invoice_id`, `attemptId`, `pos_id` mismatches). - Don't leave placeholder query blocks (for example empty `select: {}`) in production code. - Don't mix method semantics (`send` vs `originalSend`) across services without verifying signatures. @@ -74,12 +227,14 @@ Operational guide for AI/coding agents working in `consumer_api`. - Don't change invoice type semantics (`ORIGINAL`, `CORRECTION`, `REVOKE`) implicitly. ### Common Pitfalls To Recheck + - Incorrect relation field names (`tax_id` on wrong model, missing relation selects). - Building payloads from the wrong invoice (must match the expected new/ref invoice in each flow). - Creating attempts without persisting request payload and final response payload. - Mismatch between DTO shapes and shared service input contracts. ## Thread Notes (May 2026) + - Shared sale-invoice creation was introduced and must be injected/exported correctly in consuming modules (example failure: `UnknownDependenciesException` for `SharedSaleInvoiceCreateService`). - In `SalesInvoiceTspService.revoke`, prepare all creation/update data from `relatedInvoice` (no external `dataToUpdate` argument expected). - Prisma client is generated to `src/generated/prisma` via: @@ -94,6 +249,7 @@ Operational guide for AI/coding agents working in `consumer_api`. - For heavy license provisioning (100+), request path should not synchronously insert all licenses; queue/background + batching is required. ## Migration Drift Playbook (Prisma/MySQL) + - If Prisma reports `modified after applied`, never edit an already-applied migration in-place for shared environments; create a new forward migration instead. - If migration history and DB drift mismatch: 1. Verify local migration folders are complete and ordered. @@ -104,6 +260,7 @@ Operational guide for AI/coding agents working in `consumer_api`. - `prisma migrate status` may show up-to-date while `migrate dev` still detects drift (shadow DB/application history issue); treat `migrate dev` output as source of truth for fixing local history. ## Redis Cache Conventions (May 2026) + - Use `RedisKeyMaker` in `src/common/utils/redis-key-maker.util.ts` for all cache keys and wildcard patterns; do not inline key strings in services. - Keep invalidation domain-based (for example `src/modules/admin/guilds/cache/*`, `src/modules/admin/partners/cache/*`, `src/modules/pos/cache/*`) and avoid duplicating delete logic across modules. - For list APIs that are expensive or frequently read, prefer read-through cache with TTL and invalidation on every related write path. diff --git a/psp_backup_2026-04-27-05-50-22.sql b/psp_backup_2026-04-27-05-50-22.sql deleted file mode 100644 index 894129a..0000000 --- a/psp_backup_2026-04-27-05-50-22.sql +++ /dev/null @@ -1,1404 +0,0 @@ --- MySQL dump 10.13 Distrib 9.5.0, for macos15.4 (arm64) --- --- Host: 194.59.214.243 Database: psp --- ------------------------------------------------------ --- Server version 8.0.45 - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!50503 SET NAMES utf8mb4 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Current Database: `psp` --- - -CREATE DATABASE /*!32312 IF NOT EXISTS*/ `psp` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */; - -USE `psp`; - --- --- Table structure for table `_prisma_migrations` --- - -DROP TABLE IF EXISTS `_prisma_migrations`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `_prisma_migrations` ( - `id` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL, - `checksum` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, - `finished_at` datetime(3) DEFAULT NULL, - `migration_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, - `logs` text COLLATE utf8mb4_unicode_ci, - `rolled_back_at` datetime(3) DEFAULT NULL, - `started_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), - `applied_steps_count` int unsigned NOT NULL DEFAULT '0', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `_prisma_migrations` --- - -LOCK TABLES `_prisma_migrations` WRITE; -/*!40000 ALTER TABLE `_prisma_migrations` DISABLE KEYS */; -INSERT INTO `_prisma_migrations` VALUES ('1108a09e-549b-4005-9689-98cba940a709','ee9ebde408feab2873611eddfd07bbda9368b20b96273c874d9b4517d3faa56c','2026-04-23 12:44:58.496','20260416125205_init',NULL,NULL,'2026-04-23 12:44:55.151',1),('3541b09f-3669-4f35-a3e3-911057c67e03','5a112a51f306dea0700821a4a83dc9501877055f74328b058618d2fe233e13bb','2026-04-23 16:43:42.282','20260423164340_init',NULL,NULL,'2026-04-23 16:43:40.920',1),('477cf4ee-172f-4404-acb1-f20091de1318','3ac42b4fc3adb21ad76e4e4840e063d1a87133ea781458bde858f7191a7de84e','2026-04-23 12:47:28.831','20260423124719_init',NULL,NULL,'2026-04-23 12:47:19.866',1),('4ed5ba10-2560-44a7-9532-1ce565a5d46b','7e1b0fe4e68b0cd96acbfad7cc5e24e9f950b3f7127c14c8fc0537e445bc170a','2026-04-23 12:44:50.203','20260415113308_init',NULL,NULL,'2026-04-23 12:44:49.433',1),('568c2102-f31a-4caa-a812-f148cc3cec01','91a62b1feba2d5523af07ab99220b1d16b1f829b7c0f1d32dfbbc33a24a227ef','2026-04-24 15:41:07.863','20260424154103_init',NULL,NULL,'2026-04-24 15:41:03.334',1),('6a798168-272b-4bce-805d-63dbedf01671','0825c1eb311bbe206a0860013857b233eb1d6815f273f43ec31e6ca6a1ca6798','2026-04-26 15:33:15.375','20260426143218_init',NULL,NULL,'2026-04-26 15:33:11.443',1),('6ff68053-ba7e-4b28-8686-66fa22351fec','4e1dd6ff9dbc1e444bc81c75ec1f33af765fdf9883b6d35909b1376f625b2307','2026-04-23 23:26:24.979','20260423232622_init',NULL,NULL,'2026-04-23 23:26:22.722',1),('7182a21f-b443-46ed-9cb4-fdae9d3b3962','8556f73f0381b5fc6cce88a1863b43472bfdc679679931eecaeede0337cf5712','2026-04-23 21:49:58.970','20260423214958_init',NULL,NULL,'2026-04-23 21:49:58.469',1),('74bde740-5c8c-400f-9f88-6041f8ff5390','40f854bad9fa0aab0c217fa20a9460060dc97abd2afe2bad3e5bf96aea629eed','2026-04-24 16:17:29.634','20260424161725_init',NULL,NULL,'2026-04-24 16:17:26.165',1),('7ae5b147-8213-46c4-a7ff-b9ebc10ad60a','a72f62b8d630960939698b0274eb0299c7176709aaa2c38307a33d56a3e934d0','2026-04-23 12:45:06.014','20260422201806_init',NULL,NULL,'2026-04-23 12:45:05.411',1),('82058c73-a09c-4359-9f86-311cd8189578','b402755a3286415fc2bc4222eb2985e7a9c57589087d9eb3ec7a53ceff93d9b2','2026-04-23 12:45:02.405','20260421131918_init',NULL,NULL,'2026-04-23 12:45:01.280',1),('87642cbe-ce89-4c6d-a2bb-5fbf49e8ad5a','2cc65b76a60988ff06b1f416324b0255dbfca4b0ff1aae548bdb177c7ed07ea1','2026-04-26 16:26:19.315','20260426153449_init',NULL,NULL,'2026-04-26 16:26:15.831',1),('8cea4939-145e-41ae-bb11-58aa28a3e6ee','167122e74dcee71d32ebbef0aac309d1af64102b7ec55243d003357716ead54e','2026-04-25 07:50:50.757','20260425075045_init',NULL,NULL,'2026-04-25 07:50:45.993',1),('9877046c-94c9-45ba-8267-febaedf3e044','1635987bbb82eac80c0466d25345f272272dff555e44eaa3a116fae9a92c1fb1','2026-04-23 12:44:43.161','20260410112847_init',NULL,NULL,'2026-04-23 12:44:07.094',1),('a033038d-a40b-48ff-b51b-aea3bd6891fa','96b6d0c1c58fcc02fb880e952d9cc2f212939aacda09cc1b385c290647441d9b','2026-04-23 12:44:55.118','20260416100419_init',NULL,NULL,'2026-04-23 12:44:50.250',1),('a0bb816e-7f01-4a7a-a3bc-9dc9ecbe7762','0dd8abc36bf573eaf474a0a7e00197d233a5191c386f801df2da798259cc14c0','2026-04-26 07:17:57.244','20260426071752_init',NULL,NULL,'2026-04-26 07:17:52.782',1),('bc3e2fd6-32b1-4815-a9e3-e53937136c7d','5571ff74b6b77590d9caa561b69d585cad1dcc659948e95d2aaafb59c4aa48f3','2026-04-23 12:45:01.225','20260420124725_add_tracking_code_to_charged_license_transactions',NULL,NULL,'2026-04-23 12:44:58.544',1),('c49c2327-7e41-4051-9c06-9ec8335e2130','43ff604ffd0cb65080a8339360db76cb0e7862725280429278e2e4660be6b9d9','2026-04-23 12:44:49.392','20260410211433_init',NULL,NULL,'2026-04-23 12:44:43.327',1),('c6c41010-5e11-4648-a19c-6ad04cd669fd','c715277bc53a127bbd2028f4916187229caeb9093103a89bf1bb3953ce5bb049','2026-04-23 12:45:05.364','20260422200730_init',NULL,NULL,'2026-04-23 12:45:02.436',1); -/*!40000 ALTER TABLE `_prisma_migrations` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `accounts` --- - -DROP TABLE IF EXISTS `accounts`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `accounts` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `username` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `password` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `status` enum('ACTIVE','SUSPENDED') COLLATE utf8mb4_unicode_ci NOT NULL, - `type` enum('ADMIN','PROVIDER','PARTNER','CONSUMER') COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `accounts_username_key` (`username`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `accounts` --- - -LOCK TABLES `accounts` WRITE; -/*!40000 ALTER TABLE `accounts` DISABLE KEYS */; -INSERT INTO `accounts` VALUES ('01KPX63KJFQTM95S4ACQQV8NJT','superAdmin','$2b$10$/oEp78p.lw90yaItLgDm6uj0rH5GHeQAc5QhDXQt.zYZD92za9dsy','ACTIVE','ADMIN'),('01KPX63MEFBXD6E514VJJP5YJC','tis','$2b$10$XVSWjBrSalJH7QUDhuWfxOo6nhLIv.SBjzgVvvs5mvrbP.sgByCEG','ACTIVE','PARTNER'),('01KPX63V8D3BQNSVDTC1C5XQCE','zargar','$2b$10$AF2QHMNCl8HIlNRnI5s5D.fzv2v1aE0VEp2zxRfYGLf6qaEe9/ubC','ACTIVE','CONSUMER'),('01KPX63VK0ACPB3JDQV5JBCY0F','tosan','$2b$10$KC3gmQZRAxyxXcdsZ.KPDe2a3NxLGLCb9T.57viYq9XoU/IJGMb5W','ACTIVE','PROVIDER'),('01KPZEE9CNBHPD2BYQVEQ5F8KD','rahbar','$2b$10$FCuxbO/zMadwLkPjMlbd9uQJohJ.FVbeEg/fccAfxqnjsZ.a8/qr.','ACTIVE','PARTNER'),('01KQ0C2K841814NEQCMN0CVSW3','and_web','$2b$10$ak7w1SQra4Uppf6rXE/W7ehW72UhpBG5hdZGliz83Vja8g.mX5iG2','ACTIVE','CONSUMER'),('01KQ0CB5P1WQW2HD748E2SK9VC','and_sep','$2b$10$ZGoxyzAGQC4kYEjSznQ7ROdewVGBH2qa6nZAGGLsEsIezl1WkoRyq','ACTIVE','CONSUMER'),('01KQ1XPKB60G452A01V7Y5T1F0','mon_mob','$2b$10$8PxCrZWDzU/X3kdDqbzy8uz8DtBE6lYnp7ODw9aPhWViSUwkclDIi','ACTIVE','CONSUMER'),('01KQ2HF2REZPRH929E8NPCV5ZW','jafari','$2b$10$Zb73AnSz1P8FF9CzNGaXq.NyK7RkR5rRAC/YIGSzMKYc2FzxVPINK','ACTIVE','CONSUMER'),('01KQ2JB8Q1SYCRAH7K69WB62MF','ali_sep','$2b$10$skqiJZ50NcIdwEU1V6Jo.uwgHydNCAfulbOpPkZLSFT71BO0o81N2','ACTIVE','CONSUMER'),('01KQ2W7SA1KHQCATSSBVDWWQ6Z','akbar','$2b$10$.rpgUeNzHZ3wiGeqimVw8OpBeP/eIjKFwPIPn18qDOSFyKIP2UlbW','ACTIVE','CONSUMER'),('01KQ2WFMXFZBT22HWJ1VQKP4PN','akbarpos','$2b$10$RcESQgafg4fLgVIqOGy/VuBGtxQOnJ35nIkLC0s4C7B8l109u./Nm','ACTIVE','CONSUMER'); -/*!40000 ALTER TABLE `accounts` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `admin_accounts` --- - -DROP TABLE IF EXISTS `admin_accounts`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `admin_accounts` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `admin_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `account_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `admin_accounts_account_id_key` (`account_id`), - KEY `admin_accounts_admin_id_fkey` (`admin_id`), - CONSTRAINT `admin_accounts_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT `admin_accounts_admin_id_fkey` FOREIGN KEY (`admin_id`) REFERENCES `admins` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `admin_accounts` --- - -LOCK TABLES `admin_accounts` WRITE; -/*!40000 ALTER TABLE `admin_accounts` DISABLE KEYS */; -INSERT INTO `admin_accounts` VALUES ('01KPX63KJZB2VNCW4J72P41SAJ','2026-04-23 12:47:45','2026-04-23 12:47:45','01KPX63KHRB9CCKBZ2VVB46B46','01KPX63KJFQTM95S4ACQQV8NJT'); -/*!40000 ALTER TABLE `admin_accounts` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `admins` --- - -DROP TABLE IF EXISTS `admins`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `admins` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `mobile_number` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `national_code` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `first_name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `last_name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `admins_mobile_number_key` (`mobile_number`), - UNIQUE KEY `admins_national_code_key` (`national_code`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `admins` --- - -LOCK TABLES `admins` WRITE; -/*!40000 ALTER TABLE `admins` DISABLE KEYS */; -INSERT INTO `admins` VALUES ('01KPX63KHRB9CCKBZ2VVB46B46','09120258156','0016022289','عباس','حسنی','2026-04-23 12:47:45','2026-04-23 12:47:45'); -/*!40000 ALTER TABLE `admins` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `application_released_info` --- - -DROP TABLE IF EXISTS `application_released_info`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `application_released_info` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `version` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `build_number` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `is_minimum_supported` tinyint(1) NOT NULL DEFAULT '0', - `notes` json DEFAULT NULL, - `release_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `platform` enum('ANDROID','IOS') COLLATE utf8mb4_unicode_ci NOT NULL, - `release_type` enum('STABLE','BETA','ALPHA') COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `application_released_info` --- - -LOCK TABLES `application_released_info` WRITE; -/*!40000 ALTER TABLE `application_released_info` DISABLE KEYS */; -/*!40000 ALTER TABLE `application_released_info` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `business_activities` --- - -DROP TABLE IF EXISTS `business_activities`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `business_activities` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `guild_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `consumer_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `economic_code` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `business_activities_economic_code_consumer_id_key` (`economic_code`,`consumer_id`), - KEY `business_activities_guild_id_fkey` (`guild_id`), - KEY `business_activities_consumer_id_fkey` (`consumer_id`), - CONSTRAINT `business_activities_consumer_id_fkey` FOREIGN KEY (`consumer_id`) REFERENCES `consumers` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT `business_activities_guild_id_fkey` FOREIGN KEY (`guild_id`) REFERENCES `guilds` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `business_activities` --- - -LOCK TABLES `business_activities` WRITE; -/*!40000 ALTER TABLE `business_activities` DISABLE KEYS */; -INSERT INTO `business_activities` VALUES ('01KQ05Q8X0EQH4R79038WXXC19','زرگران','2026-04-24 16:38:44','2026-04-24 16:38:44','01KPX63KNQXAR1J032RVMAJ100','01KPX63V7WEFC9V5JTD0EDTG76','۲۱۳۱۲۳'),('01KQ2J44B6SF32XDKY6SZ16TB4','طلا علی','2026-04-25 14:53:57','2026-04-25 14:53:57','01KPX63KNQXAR1J032RVMAJ100','01KQ2HF2R0XCM9VKZZY2J92Z3V','۱۲۳۲۱۳'),('01KQ2K5X6AHKR119VJQB7NC4NH','تره بار','2026-04-25 15:12:24','2026-04-25 15:12:24','01KPX63KNQ3PSK1RSBJNV00PMN','01KQ2HF2R0XCM9VKZZY2J92Z3V','۱۲۳۲۱۳۱'),('01KQ2WB8XGS33DQVSW3CPH9P13','یاران دریان حجت','2026-04-25 17:52:37','2026-04-25 17:52:37','01KPX63KNQ3PSK1RSBJNV00PMN','01KQ2W7S95WEC578WCG52G4VJD','۱۰۹۸۷۴۸۲'); -/*!40000 ALTER TABLE `business_activities` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `complexes` --- - -DROP TABLE IF EXISTS `complexes`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `complexes` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `address` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `business_activity_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `branch_code` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - KEY `complexes_business_activity_id_fkey` (`business_activity_id`), - CONSTRAINT `complexes_business_activity_id_fkey` FOREIGN KEY (`business_activity_id`) REFERENCES `business_activities` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `complexes` --- - -LOCK TABLES `complexes` WRITE; -/*!40000 ALTER TABLE `complexes` DISABLE KEYS */; -INSERT INTO `complexes` VALUES ('01KQ0866BCDC6WPSNMTB0X6MKE','شعبه‌ی اندرزگو','تهران اندرزگو','2026-04-24 17:21:50','2026-04-24 17:21:50','01KQ05Q8X0EQH4R79038WXXC19','۱۲۳۱۲۳'),('01KQ1WFH94EYY2C46YC29QR895','شعبه‌ی منیریه','تهران منیریه','2026-04-25 08:35:43','2026-04-25 08:36:41','01KQ05Q8X0EQH4R79038WXXC19','۲۴۱'),('01KQ2J6YEHGZG8GHE0DFGCFY80','طلای مرزداران','سبی','2026-04-25 14:55:30','2026-04-25 14:55:30','01KQ2J44B6SF32XDKY6SZ16TB4','۱۲'),('01KQ2WCV8D0Q1SB1A471THF096','جنت آباد جنوبی','جنت آباد','2026-04-25 17:53:29','2026-04-25 17:53:29','01KQ2WB8XGS33DQVSW3CPH9P13','۰۹۸۳'); -/*!40000 ALTER TABLE `complexes` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `consumer_accounts` --- - -DROP TABLE IF EXISTS `consumer_accounts`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `consumer_accounts` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `role` enum('OWNER','MANAGER','OPERATOR') COLLATE utf8mb4_unicode_ci NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `consumer_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `account_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `consumer_accounts_account_id_key` (`account_id`), - KEY `consumer_accounts_consumer_id_fkey` (`consumer_id`), - CONSTRAINT `consumer_accounts_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT `consumer_accounts_consumer_id_fkey` FOREIGN KEY (`consumer_id`) REFERENCES `consumers` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `consumer_accounts` --- - -LOCK TABLES `consumer_accounts` WRITE; -/*!40000 ALTER TABLE `consumer_accounts` DISABLE KEYS */; -INSERT INTO `consumer_accounts` VALUES ('01KPX63V8TSSPM3B7DM3013RD4','OWNER','2026-04-23 12:47:53','2026-04-23 12:47:53','01KPX63V7WEFC9V5JTD0EDTG76','01KPX63V8D3BQNSVDTC1C5XQCE'),('01KQ0C2K96Z64MRNFXSY1C1WKD','OPERATOR','2026-04-24 18:29:47','2026-04-24 18:29:47','01KPX63V7WEFC9V5JTD0EDTG76','01KQ0C2K841814NEQCMN0CVSW3'),('01KQ0CB5PW4BKEXR947C9ZAXVP','OPERATOR','2026-04-24 18:34:28','2026-04-24 18:34:28','01KPX63V7WEFC9V5JTD0EDTG76','01KQ0CB5P1WQW2HD748E2SK9VC'),('01KQ1XPKGJ869MHG1DHJE2PV47','OPERATOR','2026-04-25 08:57:03','2026-04-25 08:57:03','01KPX63V7WEFC9V5JTD0EDTG76','01KQ1XPKB60G452A01V7Y5T1F0'),('01KQ2HF2X05VGVHP2TZWGYAS70','OWNER','2026-04-25 14:42:28','2026-04-25 14:42:28','01KQ2HF2R0XCM9VKZZY2J92Z3V','01KQ2HF2REZPRH929E8NPCV5ZW'),('01KQ2JB8RM5AY2KM5FSZE2SF45','OPERATOR','2026-04-25 14:57:51','2026-04-25 14:57:51','01KQ2HF2R0XCM9VKZZY2J92Z3V','01KQ2JB8Q1SYCRAH7K69WB62MF'),('01KQ2W7SAJF514GQ02AZV51JB4','OWNER','2026-04-25 17:50:43','2026-04-25 17:50:43','01KQ2W7S95WEC578WCG52G4VJD','01KQ2W7SA1KHQCATSSBVDWWQ6Z'),('01KQ2WFMYZ3THXKBNMFB1EX0B9','OPERATOR','2026-04-25 17:55:01','2026-04-25 17:55:01','01KQ2W7S95WEC578WCG52G4VJD','01KQ2WFMXFZBT22HWJ1VQKP4PN'); -/*!40000 ALTER TABLE `consumer_accounts` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `consumer_devices` --- - -DROP TABLE IF EXISTS `consumer_devices`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `consumer_devices` ( - `uuid` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, - `app_version` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL, - `build_number` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL, - `platform` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, - `brand` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, - `model` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, - `device` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, - `os_version` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL, - `sdk_version` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL, - `release_number` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL, - `browser_name` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `fcm_token` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `consumer_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `publisher` enum('DIRECT','CAFE_BAZAR','MAYKET') COLLATE utf8mb4_unicode_ci NOT NULL, - `user_agent` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - PRIMARY KEY (`uuid`), - UNIQUE KEY `consumer_devices_uuid_key` (`uuid`), - KEY `consumer_devices_consumer_id_fkey` (`consumer_id`), - CONSTRAINT `consumer_devices_consumer_id_fkey` FOREIGN KEY (`consumer_id`) REFERENCES `consumers` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `consumer_devices` --- - -LOCK TABLES `consumer_devices` WRITE; -/*!40000 ALTER TABLE `consumer_devices` DISABLE KEYS */; -/*!40000 ALTER TABLE `consumer_devices` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `consumers` --- - -DROP TABLE IF EXISTS `consumers`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `consumers` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `status` enum('ACTIVE','SUSPENDED') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'ACTIVE', - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `type` enum('INDIVIDUAL','LEGAL') COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `consumers` --- - -LOCK TABLES `consumers` WRITE; -/*!40000 ALTER TABLE `consumers` DISABLE KEYS */; -INSERT INTO `consumers` VALUES ('01KPX63V7WEFC9V5JTD0EDTG76','ACTIVE','2026-04-23 12:47:53','2026-04-23 12:47:53','INDIVIDUAL'),('01KQ2HF2R0XCM9VKZZY2J92Z3V','ACTIVE','2026-04-25 14:42:28','2026-04-25 14:42:28','INDIVIDUAL'),('01KQ2W7S95WEC578WCG52G4VJD','ACTIVE','2026-04-25 17:50:43','2026-04-25 17:50:43','INDIVIDUAL'); -/*!40000 ALTER TABLE `consumers` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `consumers_individual` --- - -DROP TABLE IF EXISTS `consumers_individual`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `consumers_individual` ( - `first_name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `last_name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `mobile_number` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `national_code` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `partner_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `consumer_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`consumer_id`), - UNIQUE KEY `consumers_individual_mobile_number_consumer_id_key` (`mobile_number`,`consumer_id`), - UNIQUE KEY `consumers_individual_partner_id_national_code_key` (`partner_id`,`national_code`), - CONSTRAINT `consumers_individual_consumer_id_fkey` FOREIGN KEY (`consumer_id`) REFERENCES `consumers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `consumers_individual_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `consumers_individual` --- - -LOCK TABLES `consumers_individual` WRITE; -/*!40000 ALTER TABLE `consumers_individual` DISABLE KEYS */; -/*!40000 ALTER TABLE `consumers_individual` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `consumers_legal` --- - -DROP TABLE IF EXISTS `consumers_legal`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `consumers_legal` ( - `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `registration_code` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `partner_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `consumer_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`consumer_id`), - UNIQUE KEY `consumers_legal_partner_id_registration_code_key` (`partner_id`,`registration_code`), - CONSTRAINT `consumers_legal_consumer_id_fkey` FOREIGN KEY (`consumer_id`) REFERENCES `consumers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `consumers_legal_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `consumers_legal` --- - -LOCK TABLES `consumers_legal` WRITE; -/*!40000 ALTER TABLE `consumers_legal` DISABLE KEYS */; -/*!40000 ALTER TABLE `consumers_legal` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `customer_individuals` --- - -DROP TABLE IF EXISTS `customer_individuals`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `customer_individuals` ( - `first_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, - `last_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, - `national_id` char(10) COLLATE utf8mb4_unicode_ci NOT NULL, - `postal_code` char(10) COLLATE utf8mb4_unicode_ci NOT NULL, - `economic_code` char(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `customer_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `business_activity_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `mobile_number` char(15) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`customer_id`), - UNIQUE KEY `customer_individuals_business_activity_id_national_id_key` (`business_activity_id`,`national_id`), - KEY `customer_individuals_business_activity_id_idx` (`business_activity_id`), - CONSTRAINT `customer_individuals_business_activity_id_fkey` FOREIGN KEY (`business_activity_id`) REFERENCES `business_activities` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT `customer_individuals_customer_id_fkey` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `customer_individuals` --- - -LOCK TABLES `customer_individuals` WRITE; -/*!40000 ALTER TABLE `customer_individuals` DISABLE KEYS */; -/*!40000 ALTER TABLE `customer_individuals` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `customer_legal` --- - -DROP TABLE IF EXISTS `customer_legal`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `customer_legal` ( - `company_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, - `economic_code` char(10) COLLATE utf8mb4_unicode_ci NOT NULL, - `registration_number` char(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `postal_code` char(10) COLLATE utf8mb4_unicode_ci NOT NULL, - `customer_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `business_activity_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`customer_id`), - UNIQUE KEY `customer_legal_business_activity_id_economic_code_key` (`business_activity_id`,`economic_code`), - KEY `customer_legal_business_activity_id_idx` (`business_activity_id`), - CONSTRAINT `customer_legal_business_activity_id_fkey` FOREIGN KEY (`business_activity_id`) REFERENCES `business_activities` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT `customer_legal_customer_id_fkey` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `customer_legal` --- - -LOCK TABLES `customer_legal` WRITE; -/*!40000 ALTER TABLE `customer_legal` DISABLE KEYS */; -/*!40000 ALTER TABLE `customer_legal` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `customers` --- - -DROP TABLE IF EXISTS `customers`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `customers` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `is_favorite` tinyint(1) DEFAULT '0', - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `deleted_at` timestamp NULL DEFAULT NULL, - `type` enum('INDIVIDUAL','LEGAL','UNKNOWN') COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `customers` --- - -LOCK TABLES `customers` WRITE; -/*!40000 ALTER TABLE `customers` DISABLE KEYS */; -INSERT INTO `customers` VALUES ('01KQ20CKZ8AKZR6R1QKEA5JCYE',0,'2026-04-25 09:44:01','2026-04-25 09:44:01',NULL,'INDIVIDUAL'),('01KQ2M7SFE75328NC05QF6B49E',0,'2026-04-25 15:30:55','2026-04-25 15:30:55',NULL,'LEGAL'); -/*!40000 ALTER TABLE `customers` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `device_brands` --- - -DROP TABLE IF EXISTS `device_brands`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `device_brands` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `device_brands` --- - -LOCK TABLES `device_brands` WRITE; -/*!40000 ALTER TABLE `device_brands` DISABLE KEYS */; -/*!40000 ALTER TABLE `device_brands` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `devices` --- - -DROP TABLE IF EXISTS `devices`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `devices` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `os_version` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `brand_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - KEY `devices_brand_id_fkey` (`brand_id`), - CONSTRAINT `devices_brand_id_fkey` FOREIGN KEY (`brand_id`) REFERENCES `device_brands` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `devices` --- - -LOCK TABLES `devices` WRITE; -/*!40000 ALTER TABLE `devices` DISABLE KEYS */; -/*!40000 ALTER TABLE `devices` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `good_categories` --- - -DROP TABLE IF EXISTS `good_categories`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `good_categories` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, - `description` text COLLATE utf8mb4_unicode_ci, - `image_url` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `complex_id` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `is_default_guild_good` tinyint(1) NOT NULL DEFAULT '0', - `guild_id` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `deleted_at` timestamp NULL DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `good_categories_guild_id_fkey` (`guild_id`), - KEY `good_categories_complex_id_fkey` (`complex_id`), - CONSTRAINT `good_categories_complex_id_fkey` FOREIGN KEY (`complex_id`) REFERENCES `complexes` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT `good_categories_guild_id_fkey` FOREIGN KEY (`guild_id`) REFERENCES `guilds` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `good_categories` --- - -LOCK TABLES `good_categories` WRITE; -/*!40000 ALTER TABLE `good_categories` DISABLE KEYS */; -INSERT INTO `good_categories` VALUES ('01KPX63KRM17Y5X5NGY0FVMD05','سایر',NULL,NULL,NULL,1,'01KPX63KNQXAR1J032RVMAJ100','2026-04-23 12:47:45','2026-04-23 12:47:45',NULL),('01KPX63KRM4S453DZNRSHYA2V2','طلا',NULL,NULL,NULL,1,'01KPX63KNQXAR1J032RVMAJ100','2026-04-23 12:47:45','2026-04-23 12:47:45',NULL),('01KPX63KRMCRP04S1DGR97WVTQ','شمش',NULL,NULL,NULL,1,'01KPX63KNQXAR1J032RVMAJ100','2026-04-23 12:47:45','2026-04-23 12:47:45',NULL),('01KPX63KRMF31DNYWV2X10C1S7','شمش',NULL,NULL,NULL,1,'01KPX63KNQXAR1J032RVMAJ100','2026-04-23 12:47:45','2026-04-23 12:47:45',NULL),('01KPX63KRMGFVM2JSN7FHE8GGH','سکه',NULL,NULL,NULL,1,'01KPX63KNQXAR1J032RVMAJ100','2026-04-23 12:47:45','2026-04-23 12:47:45',NULL),('01KPX63KRMT4ZR69FSSTADAAV1','زیورآلات',NULL,NULL,NULL,1,'01KPX63KNQXAR1J032RVMAJ100','2026-04-23 12:47:45','2026-04-23 12:47:45',NULL); -/*!40000 ALTER TABLE `good_categories` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `goods` --- - -DROP TABLE IF EXISTS `goods`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `goods` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, - `is_default_guild_good` tinyint(1) NOT NULL DEFAULT '0', - `sku` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, - `unit_type` enum('COUNT','GRAM','KILOGRAM','MILLILITER','LITER','METER','HOUR') COLLATE utf8mb4_unicode_ci NOT NULL, - `pricing_model` enum('STANDARD','GOLD') COLLATE utf8mb4_unicode_ci NOT NULL, - `description` text COLLATE utf8mb4_unicode_ci, - `local_sku` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `barcode` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `base_sale_price` decimal(15,0) DEFAULT '0', - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `deleted_at` timestamp NULL DEFAULT NULL, - `category_id` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `image_url` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `business_activity_id` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `goods_local_sku_key` (`local_sku`), - UNIQUE KEY `goods_barcode_key` (`barcode`), - KEY `goods_category_id_idx` (`category_id`), - KEY `goods_business_activity_id_fkey` (`business_activity_id`), - CONSTRAINT `goods_business_activity_id_fkey` FOREIGN KEY (`business_activity_id`) REFERENCES `business_activities` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT `goods_category_id_fkey` FOREIGN KEY (`category_id`) REFERENCES `good_categories` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `goods` --- - -LOCK TABLES `goods` WRITE; -/*!40000 ALTER TABLE `goods` DISABLE KEYS */; -INSERT INTO `goods` VALUES ('01KPX63KVV5G03PRGWAY92M6C5','آویز گردنبند طلا',1,'333','GRAM','GOLD',NULL,NULL,NULL,0,'2026-04-23 12:47:46','2026-04-23 20:16:50',NULL,'01KPX63KRMT4ZR69FSSTADAAV1','https://s3.ir-thr-at1.arvanstorage.ir/psp-project/good/9880ff55-f351-4bb2-8f92-38d45c26eb11-necklaceـpendant.webp',NULL),('01KPX63KVW1KMWFSGC7S6KD4PQ','انگشتر',1,'','GRAM','GOLD',NULL,NULL,NULL,0,'2026-04-23 12:47:46','2026-04-23 12:47:46',NULL,'01KPX63KRMT4ZR69FSSTADAAV1',NULL,NULL),('01KPX63KVW3P0X3870R278E7QS','النگو',1,'','GRAM','GOLD',NULL,NULL,NULL,0,'2026-04-23 12:47:46','2026-04-23 12:47:46',NULL,'01KPX63KRMT4ZR69FSSTADAAV1',NULL,NULL),('01KPX63KVW6A25X10BMZZHPVRZ','دست‌بند',1,'','GRAM','GOLD',NULL,NULL,NULL,0,'2026-04-23 12:47:46','2026-04-23 12:47:46',NULL,'01KPX63KRMT4ZR69FSSTADAAV1',NULL,NULL),('01KPX63KVWAMXBBJP1Y743N6W7','سرویس',1,'','GRAM','GOLD',NULL,NULL,NULL,0,'2026-04-23 12:47:46','2026-04-23 12:47:46',NULL,'01KPX63KRMT4ZR69FSSTADAAV1',NULL,NULL),('01KPX63KVWR5ZM2P536RC4E1G6','گوشواره',1,'','GRAM','GOLD',NULL,NULL,NULL,0,'2026-04-23 12:47:46','2026-04-23 12:47:46',NULL,'01KPX63KRMT4ZR69FSSTADAAV1',NULL,NULL),('01KPX63KVWWRQ3SJ78MAAZ5ETE','زنجیر',1,'','GRAM','GOLD',NULL,NULL,NULL,0,'2026-04-23 12:47:46','2026-04-23 12:47:46',NULL,'01KPX63KRMT4ZR69FSSTADAAV1',NULL,NULL),('01KPX63KYK0WHPTGGSH5TGXVBZ','طلای مستعمل',1,'','GRAM','GOLD',NULL,NULL,NULL,0,'2026-04-23 12:47:46','2026-04-23 12:47:46',NULL,'01KPX63KRM4S453DZNRSHYA2V2',NULL,NULL),('01KPX63KYK3EMYS7MCZVT1YJ0E','طلای شکسته',1,'','GRAM','GOLD',NULL,NULL,NULL,0,'2026-04-23 12:47:46','2026-04-23 12:47:46',NULL,'01KPX63KRM4S453DZNRSHYA2V2',NULL,NULL),('01KPX63KYKV1VK0F4W08QN4CGW','طلای آب شده',1,'','GRAM','GOLD',NULL,NULL,NULL,0,'2026-04-23 12:47:46','2026-04-23 12:47:46',NULL,'01KPX63KRM4S453DZNRSHYA2V2',NULL,NULL),('01KPX63M4C85AEE19ME3V8RHZ9','مسکوکات خارجی',1,'','COUNT','STANDARD',NULL,NULL,NULL,0,'2026-04-23 12:47:46','2026-04-23 12:47:46',NULL,'01KPX63KRMGFVM2JSN7FHE8GGH',NULL,NULL),('01KPX63M4D3E765VH9FD3SWSQT','تمام بهار آزادی (طرح جدید)',1,'','COUNT','STANDARD',NULL,NULL,NULL,0,'2026-04-23 12:47:46','2026-04-23 12:47:46',NULL,'01KPX63KRMGFVM2JSN7FHE8GGH',NULL,NULL),('01KPX63M4DSDK234E3XGQGJHS7','تمام بهار آزادی (طرح قدیم)',1,'','COUNT','STANDARD',NULL,NULL,NULL,0,'2026-04-23 12:47:46','2026-04-23 12:47:46',NULL,'01KPX63KRMGFVM2JSN7FHE8GGH',NULL,NULL),('01KPX63M4DXETEAHPR3401T469','مسکوکات داخلی (پارسیان)',1,'','COUNT','STANDARD',NULL,NULL,NULL,0,'2026-04-23 12:47:46','2026-04-23 12:47:46',NULL,'01KPX63KRMGFVM2JSN7FHE8GGH',NULL,NULL),('01KPX63M7EKNMMTF25QJNJM4QS','شمش استاندارد',1,'','GRAM','GOLD',NULL,NULL,NULL,0,'2026-04-23 12:47:46','2026-04-23 12:47:46',NULL,'01KPX63KRMCRP04S1DGR97WVTQ',NULL,NULL),('01KQ4AQHEKH9HWPAJHG7E1V9WN','دستبند',0,'۱۲۳۲','COUNT','GOLD',NULL,NULL,NULL,0,'2026-04-26 07:23:14','2026-04-26 07:23:26',NULL,'01KPX63KRM4S453DZNRSHYA2V2',NULL,'01KQ05Q8X0EQH4R79038WXXC19'); -/*!40000 ALTER TABLE `goods` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `guilds` --- - -DROP TABLE IF EXISTS `guilds`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `guilds` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `code` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `guilds` --- - -LOCK TABLES `guilds` WRITE; -/*!40000 ALTER TABLE `guilds` DISABLE KEYS */; -INSERT INTO `guilds` VALUES ('01KPX63KNQ3PSK1RSBJNV00PMN','میوه و تره‌بار','Fruit','2026-04-23 12:47:45','2026-04-23 12:47:45'),('01KPX63KNQXAR1J032RVMAJ100','طلا','Gold','2026-04-23 12:47:45','2026-04-23 12:47:45'); -/*!40000 ALTER TABLE `guilds` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `license_account_allocation` --- - -DROP TABLE IF EXISTS `license_account_allocation`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `license_account_allocation` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `license_activation_id` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `account_id` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `credit_id` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `license_account_allocation_account_id_key` (`account_id`), - UNIQUE KEY `license_account_allocation_credit_id_key` (`credit_id`), - KEY `license_account_allocation_license_activation_id_fkey` (`license_activation_id`), - CONSTRAINT `license_account_allocation_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `consumer_accounts` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT `license_account_allocation_credit_id_fkey` FOREIGN KEY (`credit_id`) REFERENCES `partner_account_quota_credit` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT `license_account_allocation_license_activation_id_fkey` FOREIGN KEY (`license_activation_id`) REFERENCES `licenses_activated` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `license_account_allocation` --- - -LOCK TABLES `license_account_allocation` WRITE; -/*!40000 ALTER TABLE `license_account_allocation` DISABLE KEYS */; -INSERT INTO `license_account_allocation` VALUES ('01KQ05Q90DZW821MTVDKS88N5V','2026-04-24 16:38:44','2026-04-24 18:29:47','01KQ05Q8YDXXB2J31DP2DHRS58','01KQ0C2K96Z64MRNFXSY1C1WKD',NULL),('01KQ05Q91RPSYHZZSZKNQ48TQ3','2026-04-24 16:38:45','2026-04-24 18:34:28','01KQ05Q8YDXXB2J31DP2DHRS58','01KQ0CB5PW4BKEXR947C9ZAXVP',NULL),('01KQ1WF429J6N7HEKZYE1VXE09','2026-04-25 08:35:29','2026-04-25 08:57:03','01KQ05Q8YDXXB2J31DP2DHRS58','01KQ1XPKGJ869MHG1DHJE2PV47','01KQ04EAYD2B8A4HN9XQ85Y1QD'),('01KQ2J44QGV0HEHWFQA77MRF4V','2026-04-25 14:53:58','2026-04-25 14:57:51','01KQ2J44DCE1XQWTS2Q6Z2A44W','01KQ2JB8RM5AY2KM5FSZE2SF45',NULL),('01KQ2J44T54PN7V035SHS3CYJT','2026-04-25 14:53:58','2026-04-25 14:53:58','01KQ2J44DCE1XQWTS2Q6Z2A44W',NULL,NULL),('01KQ2K5XHTGP8G41VHWYQPDQFY','2026-04-25 15:12:25','2026-04-25 15:12:25','01KQ2K5XAYMF0Z1PRPBWESQPTS',NULL,NULL),('01KQ2K5XM9A2CK5YXNBTD4DB2B','2026-04-25 15:12:25','2026-04-25 15:12:25','01KQ2K5XAYMF0Z1PRPBWESQPTS',NULL,NULL),('01KQ2KBJ2YZ513AE3MRJ60C90M','2026-04-25 15:15:30','2026-04-25 15:15:30','01KQ2J44DCE1XQWTS2Q6Z2A44W',NULL,'01KQ04EAZMAAYZ4HRW9DQ0MWV7'),('01KQ2WB994DRTZMAW6F5M9EV9X','2026-04-25 17:52:38','2026-04-25 17:55:01','01KQ2WB8ZDH4DY0E8M00G888G0','01KQ2WFMYZ3THXKBNMFB1EX0B9',NULL),('01KQ2WB9AWS2D0Z1WJVGH9TSAR','2026-04-25 17:52:38','2026-04-25 17:52:38','01KQ2WB8ZDH4DY0E8M00G888G0',NULL,NULL); -/*!40000 ALTER TABLE `license_account_allocation` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `license_charged_transactions` --- - -DROP TABLE IF EXISTS `license_charged_transactions`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `license_charged_transactions` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `activation_expires_at` datetime(3) NOT NULL, - `tracking_code` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `purchased_count` int NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `partner_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `license_charged_transactions_tracking_code_key` (`tracking_code`), - KEY `license_charged_transactions_partner_id_fkey` (`partner_id`), - CONSTRAINT `license_charged_transactions_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `license_charged_transactions` --- - -LOCK TABLES `license_charged_transactions` WRITE; -/*!40000 ALTER TABLE `license_charged_transactions` DISABLE KEYS */; -INSERT INTO `license_charged_transactions` VALUES ('01KQ033MCGMBBNAF9F2YEJ902H','2027-01-04 20:30:00.000','LIC-B01EVKMK',10,'2026-04-24 15:53:04','2026-04-24 15:53:04','01KPX63ME1JTT2YZNF087EA9TW'),('01KQ2GXFRWZFWQF2TTTJ4RKJHJ','2026-10-04 20:30:00.000','LIC-L00F3N48',2,'2026-04-25 14:32:51','2026-04-25 14:32:51','01KPX63ME1JTT2YZNF087EA9TW'); -/*!40000 ALTER TABLE `license_charged_transactions` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `license_renew` --- - -DROP TABLE IF EXISTS `license_renew`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `license_renew` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `charge_transaction_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `activation_id` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `expires_at` datetime(3) NOT NULL, - PRIMARY KEY (`id`), - KEY `license_renew_charge_transaction_id_fkey` (`charge_transaction_id`), - KEY `license_renew_activation_id_fkey` (`activation_id`), - CONSTRAINT `license_renew_activation_id_fkey` FOREIGN KEY (`activation_id`) REFERENCES `licenses_activated` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT `license_renew_charge_transaction_id_fkey` FOREIGN KEY (`charge_transaction_id`) REFERENCES `license_renew_charge_transaction` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `license_renew` --- - -LOCK TABLES `license_renew` WRITE; -/*!40000 ALTER TABLE `license_renew` DISABLE KEYS */; -/*!40000 ALTER TABLE `license_renew` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `license_renew_charge_transaction` --- - -DROP TABLE IF EXISTS `license_renew_charge_transaction`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `license_renew_charge_transaction` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `activation_expires_at` datetime(3) NOT NULL, - `tracking_code` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `purchased_count` int NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `partner_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `license_renew_charge_transaction_tracking_code_key` (`tracking_code`), - KEY `license_renew_charge_transaction_partner_id_fkey` (`partner_id`), - CONSTRAINT `license_renew_charge_transaction_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `license_renew_charge_transaction` --- - -LOCK TABLES `license_renew_charge_transaction` WRITE; -/*!40000 ALTER TABLE `license_renew_charge_transaction` DISABLE KEYS */; -/*!40000 ALTER TABLE `license_renew_charge_transaction` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `licenses` --- - -DROP TABLE IF EXISTS `licenses`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `licenses` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `accounts_limit` int NOT NULL DEFAULT '2', - `charge_transaction_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - KEY `licenses_charge_transaction_id_fkey` (`charge_transaction_id`), - CONSTRAINT `licenses_charge_transaction_id_fkey` FOREIGN KEY (`charge_transaction_id`) REFERENCES `license_charged_transactions` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `licenses` --- - -LOCK TABLES `licenses` WRITE; -/*!40000 ALTER TABLE `licenses` DISABLE KEYS */; -INSERT INTO `licenses` VALUES ('01KQ033MMNWE0KMCHY8FGBFSMA','2026-04-24 15:53:04','2026-04-24 15:53:04',2,'01KQ033MCGMBBNAF9F2YEJ902H'),('01KQ033MT3Y5GED3A2B0SX3AQP','2026-04-24 15:53:04','2026-04-24 15:53:04',2,'01KQ033MCGMBBNAF9F2YEJ902H'),('01KQ033MZMY26F4E9RS8SKH3G1','2026-04-24 15:53:04','2026-04-24 15:53:04',2,'01KQ033MCGMBBNAF9F2YEJ902H'),('01KQ033N66P32091R1FXC6VVZ6','2026-04-24 15:53:04','2026-04-24 15:53:04',2,'01KQ033MCGMBBNAF9F2YEJ902H'),('01KQ033N7HHDS7JD5ADZ27E6H1','2026-04-24 15:53:04','2026-04-24 15:53:04',2,'01KQ033MCGMBBNAF9F2YEJ902H'),('01KQ033NB49PCHDSCGQGWB333T','2026-04-24 15:53:05','2026-04-24 15:53:05',2,'01KQ033MCGMBBNAF9F2YEJ902H'),('01KQ033ND6VEA9P1P01NXXNH4R','2026-04-24 15:53:05','2026-04-24 15:53:05',2,'01KQ033MCGMBBNAF9F2YEJ902H'),('01KQ033NG49ARA17M385684MCQ','2026-04-24 15:53:05','2026-04-24 15:53:05',2,'01KQ033MCGMBBNAF9F2YEJ902H'),('01KQ033NHFM871YWAC123DGTT9','2026-04-24 15:53:05','2026-04-24 15:53:05',2,'01KQ033MCGMBBNAF9F2YEJ902H'),('01KQ033NP9ZQX9DN84WCN03TF8','2026-04-24 15:53:05','2026-04-24 15:53:05',2,'01KQ033MCGMBBNAF9F2YEJ902H'),('01KQ2GXFVPH7H5FYEEAKC5AC7V','2026-04-25 14:32:51','2026-04-25 14:32:51',2,'01KQ2GXFRWZFWQF2TTTJ4RKJHJ'),('01KQ2GXFX7Y7DC9R0K6BH3F2NN','2026-04-25 14:32:51','2026-04-25 14:32:51',2,'01KQ2GXFRWZFWQF2TTTJ4RKJHJ'); -/*!40000 ALTER TABLE `licenses` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `licenses_activated` --- - -DROP TABLE IF EXISTS `licenses_activated`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `licenses_activated` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `starts_at` datetime(3) NOT NULL, - `expires_at` datetime(3) NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `license_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `business_activity_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `licenses_activated_id_key` (`id`), - UNIQUE KEY `licenses_activated_license_id_key` (`license_id`), - UNIQUE KEY `licenses_activated_business_activity_id_key` (`business_activity_id`), - CONSTRAINT `licenses_activated_business_activity_id_fkey` FOREIGN KEY (`business_activity_id`) REFERENCES `business_activities` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT `licenses_activated_license_id_fkey` FOREIGN KEY (`license_id`) REFERENCES `licenses` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `licenses_activated` --- - -LOCK TABLES `licenses_activated` WRITE; -/*!40000 ALTER TABLE `licenses_activated` DISABLE KEYS */; -INSERT INTO `licenses_activated` VALUES ('01KQ05Q8YDXXB2J31DP2DHRS58','2026-04-23 20:30:00.000','2027-04-23 20:30:00.000','2026-04-24 16:38:44','2026-04-24 16:38:44','01KQ033MMNWE0KMCHY8FGBFSMA','01KQ05Q8X0EQH4R79038WXXC19'),('01KQ2J44DCE1XQWTS2Q6Z2A44W','2026-04-24 20:30:00.000','2027-04-24 20:30:00.000','2026-04-25 14:53:57','2026-04-25 14:53:57','01KQ2GXFX7Y7DC9R0K6BH3F2NN','01KQ2J44B6SF32XDKY6SZ16TB4'),('01KQ2K5XAYMF0Z1PRPBWESQPTS','2026-04-24 20:30:00.000','2027-04-24 20:30:00.000','2026-04-25 15:12:24','2026-04-25 15:12:24','01KQ2GXFVPH7H5FYEEAKC5AC7V','01KQ2K5X6AHKR119VJQB7NC4NH'),('01KQ2WB8ZDH4DY0E8M00G888G0','2026-04-29 20:30:00.000','2027-04-29 20:30:00.000','2026-04-25 17:52:37','2026-04-25 17:52:37','01KQ033MT3Y5GED3A2B0SX3AQP','01KQ2WB8XGS33DQVSW3CPH9P13'); -/*!40000 ALTER TABLE `licenses_activated` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `partner_account_quota_charge_transaction` --- - -DROP TABLE IF EXISTS `partner_account_quota_charge_transaction`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `partner_account_quota_charge_transaction` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `purchased_count` int NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `partner_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `activation_expires_at` datetime(3) NOT NULL, - `tracking_code` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `partner_account_quota_charge_transaction_tracking_code_key` (`tracking_code`), - KEY `partner_account_quota_charge_transaction_partner_id_fkey` (`partner_id`), - CONSTRAINT `partner_account_quota_charge_transaction_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `partner_account_quota_charge_transaction` --- - -LOCK TABLES `partner_account_quota_charge_transaction` WRITE; -/*!40000 ALTER TABLE `partner_account_quota_charge_transaction` DISABLE KEYS */; -INSERT INTO `partner_account_quota_charge_transaction` VALUES ('01KQ04EAX09SX6BX1NMVXXKZ05',2,'2026-04-24 16:16:23','2026-04-24 16:16:23','01KPX63ME1JTT2YZNF087EA9TW','2026-12-20 20:30:00.000','AQC-A1XYDSK0'),('01KQ2GXVZ5HEC6YKJY1C5J1E03',5,'2026-04-25 14:33:04','2026-04-25 14:33:04','01KPX63ME1JTT2YZNF087EA9TW','2027-01-10 20:30:00.000','AQC-21L5RWEP'); -/*!40000 ALTER TABLE `partner_account_quota_charge_transaction` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `partner_account_quota_credit` --- - -DROP TABLE IF EXISTS `partner_account_quota_credit`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `partner_account_quota_credit` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `charge_transaction_id` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `partner_account_quota_credit_charge_transaction_id_fkey` (`charge_transaction_id`), - CONSTRAINT `partner_account_quota_credit_charge_transaction_id_fkey` FOREIGN KEY (`charge_transaction_id`) REFERENCES `partner_account_quota_charge_transaction` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `partner_account_quota_credit` --- - -LOCK TABLES `partner_account_quota_credit` WRITE; -/*!40000 ALTER TABLE `partner_account_quota_credit` DISABLE KEYS */; -INSERT INTO `partner_account_quota_credit` VALUES ('01KQ04EAYD2B8A4HN9XQ85Y1QD','2026-04-24 16:16:23','2026-04-24 16:16:23','01KQ04EAX09SX6BX1NMVXXKZ05'),('01KQ04EAZMAAYZ4HRW9DQ0MWV7','2026-04-24 16:16:23','2026-04-24 16:16:23','01KQ04EAX09SX6BX1NMVXXKZ05'),('01KQ2GXWAQDB2DXE033GB6NHRH','2026-04-25 14:33:04','2026-04-25 14:33:04','01KQ2GXVZ5HEC6YKJY1C5J1E03'),('01KQ2GXWG5S97TXDBZ2136CWWR','2026-04-25 14:33:04','2026-04-25 14:33:04','01KQ2GXVZ5HEC6YKJY1C5J1E03'),('01KQ2GXWHF4CVXDZVP6NDWA960','2026-04-25 14:33:04','2026-04-25 14:33:04','01KQ2GXVZ5HEC6YKJY1C5J1E03'),('01KQ2GXWJQXEBDDS2EJB4HGTT6','2026-04-25 14:33:04','2026-04-25 14:33:04','01KQ2GXVZ5HEC6YKJY1C5J1E03'),('01KQ2GXWN66R11E1BADMM3KQBD','2026-04-25 14:33:04','2026-04-25 14:33:04','01KQ2GXVZ5HEC6YKJY1C5J1E03'); -/*!40000 ALTER TABLE `partner_account_quota_credit` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `partner_accounts` --- - -DROP TABLE IF EXISTS `partner_accounts`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `partner_accounts` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `role` enum('OWNER','MANAGER','OPERATOR') COLLATE utf8mb4_unicode_ci NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `partner_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `account_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `partner_accounts_account_id_key` (`account_id`), - KEY `partner_accounts_partner_id_fkey` (`partner_id`), - CONSTRAINT `partner_accounts_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT `partner_accounts_partner_id_fkey` FOREIGN KEY (`partner_id`) REFERENCES `partners` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `partner_accounts` --- - -LOCK TABLES `partner_accounts` WRITE; -/*!40000 ALTER TABLE `partner_accounts` DISABLE KEYS */; -INSERT INTO `partner_accounts` VALUES ('01KPX63MF1491CQ2B1MSQFZAX9','OWNER','2026-04-23 12:47:46','2026-04-23 12:47:46','01KPX63ME1JTT2YZNF087EA9TW','01KPX63MEFBXD6E514VJJP5YJC'),('01KPZEE9D28BBHSF0KG491BJ9S','OWNER','2026-04-24 09:51:53','2026-04-24 09:51:53','01KPZEE9A759VE2D2J0MKN2CS2','01KPZEE9CNBHPD2BYQVEQ5F8KD'); -/*!40000 ALTER TABLE `partner_accounts` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `partners` --- - -DROP TABLE IF EXISTS `partners`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `partners` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `code` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `status` enum('ACTIVE','SUSPENDED') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'ACTIVE', - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `logo_url` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `partners_code_key` (`code`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `partners` --- - -LOCK TABLES `partners` WRITE; -/*!40000 ALTER TABLE `partners` DISABLE KEYS */; -INSERT INTO `partners` VALUES ('01KPX63ME1JTT2YZNF087EA9TW','تیس','TIS','ACTIVE','2026-04-23 12:47:46','2026-04-23 12:47:46',NULL),('01KPZEE9A759VE2D2J0MKN2CS2','راهبر','rah','ACTIVE','2026-04-24 09:51:53','2026-04-24 09:51:53',NULL); -/*!40000 ALTER TABLE `partners` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `permission_business_activities` --- - -DROP TABLE IF EXISTS `permission_business_activities`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `permission_business_activities` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `role` enum('MANAGER','OPERATOR') COLLATE utf8mb4_unicode_ci NOT NULL, - `business_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `permission_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `permission_business_activities_permission_id_business_id_key` (`permission_id`,`business_id`), - KEY `permission_business_activities_business_id_fkey` (`business_id`), - CONSTRAINT `permission_business_activities_business_id_fkey` FOREIGN KEY (`business_id`) REFERENCES `business_activities` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `permission_business_activities_permission_id_fkey` FOREIGN KEY (`permission_id`) REFERENCES `permission_consumers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `permission_business_activities` --- - -LOCK TABLES `permission_business_activities` WRITE; -/*!40000 ALTER TABLE `permission_business_activities` DISABLE KEYS */; -/*!40000 ALTER TABLE `permission_business_activities` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `permission_complexes` --- - -DROP TABLE IF EXISTS `permission_complexes`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `permission_complexes` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `role` enum('MANAGER','OPERATOR') COLLATE utf8mb4_unicode_ci NOT NULL, - `complex_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `permission_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `permission_complexes_permission_id_complex_id_key` (`permission_id`,`complex_id`), - KEY `permission_complexes_complex_id_fkey` (`complex_id`), - CONSTRAINT `permission_complexes_complex_id_fkey` FOREIGN KEY (`complex_id`) REFERENCES `complexes` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `permission_complexes_permission_id_fkey` FOREIGN KEY (`permission_id`) REFERENCES `permission_consumers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `permission_complexes` --- - -LOCK TABLES `permission_complexes` WRITE; -/*!40000 ALTER TABLE `permission_complexes` DISABLE KEYS */; -/*!40000 ALTER TABLE `permission_complexes` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `permission_consumers` --- - -DROP TABLE IF EXISTS `permission_consumers`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `permission_consumers` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `consumer_account_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `permission_consumers_consumer_account_id_key` (`consumer_account_id`), - CONSTRAINT `permission_consumers_consumer_account_id_fkey` FOREIGN KEY (`consumer_account_id`) REFERENCES `consumer_accounts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `permission_consumers` --- - -LOCK TABLES `permission_consumers` WRITE; -/*!40000 ALTER TABLE `permission_consumers` DISABLE KEYS */; -/*!40000 ALTER TABLE `permission_consumers` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `permission_poses` --- - -DROP TABLE IF EXISTS `permission_poses`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `permission_poses` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `role` enum('MANAGER','OPERATOR') COLLATE utf8mb4_unicode_ci NOT NULL, - `pos_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `permission_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `permission_poses_permission_id_pos_id_key` (`permission_id`,`pos_id`), - KEY `permission_poses_pos_id_fkey` (`pos_id`), - CONSTRAINT `permission_poses_permission_id_fkey` FOREIGN KEY (`permission_id`) REFERENCES `permission_consumers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `permission_poses_pos_id_fkey` FOREIGN KEY (`pos_id`) REFERENCES `poses` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `permission_poses` --- - -LOCK TABLES `permission_poses` WRITE; -/*!40000 ALTER TABLE `permission_poses` DISABLE KEYS */; -/*!40000 ALTER TABLE `permission_poses` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `poses` --- - -DROP TABLE IF EXISTS `poses`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `poses` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `model` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `status` enum('ACTIVE','DISABLED') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'ACTIVE', - `pos_type` enum('PSP','MOBILE','WEB','API') COLLATE utf8mb4_unicode_ci NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `complex_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `device_id` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `provider_id` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `serial_number` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `account_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `poses_account_id_key` (`account_id`), - UNIQUE KEY `poses_serial_number_key` (`serial_number`), - KEY `poses_complex_id_fkey` (`complex_id`), - KEY `poses_device_id_fkey` (`device_id`), - KEY `poses_provider_id_fkey` (`provider_id`), - CONSTRAINT `poses_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `consumer_accounts` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT `poses_complex_id_fkey` FOREIGN KEY (`complex_id`) REFERENCES `complexes` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT `poses_device_id_fkey` FOREIGN KEY (`device_id`) REFERENCES `devices` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT `poses_provider_id_fkey` FOREIGN KEY (`provider_id`) REFERENCES `providers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `poses` --- - -LOCK TABLES `poses` WRITE; -/*!40000 ALTER TABLE `poses` DISABLE KEYS */; -INSERT INTO `poses` VALUES ('01KQ0C2KAYAH96XW53ATNT6YZ6','پوز سپهر',NULL,'ACTIVE','WEB','2026-04-24 18:29:47','2026-04-24 18:29:47','01KQ0866BCDC6WPSNMTB0X6MKE',NULL,NULL,NULL,'01KQ0C2K96Z64MRNFXSY1C1WKD'),('01KQ0CB5RBX5JYZNNC0DJ8VKFN','دسکتاپ',NULL,'ACTIVE','WEB','2026-04-24 18:34:28','2026-04-24 18:34:28','01KQ0866BCDC6WPSNMTB0X6MKE',NULL,NULL,NULL,'01KQ0CB5PW4BKEXR947C9ZAXVP'),('01KQ1XPKJ3T1375FAFND7MYNKB','لاین ۱',NULL,'ACTIVE','MOBILE','2026-04-25 08:57:03','2026-04-25 08:57:03','01KQ1WFH94EYY2C46YC29QR895',NULL,NULL,NULL,'01KQ1XPKGJ869MHG1DHJE2PV47'),('01KQ2JB8STAJ8S1QBR6MMG7KX7','پوز سپهر',NULL,'ACTIVE','WEB','2026-04-25 14:57:51','2026-04-25 14:57:51','01KQ2J6YEHGZG8GHE0DFGCFY80',NULL,NULL,NULL,'01KQ2JB8RM5AY2KM5FSZE2SF45'),('01KQ2WFN01GKZK28HTDWMX1H8Z','پوز صادرات',NULL,'ACTIVE','MOBILE','2026-04-25 17:55:01','2026-04-25 17:55:01','01KQ2WCV8D0Q1SB1A471THF096',NULL,NULL,NULL,'01KQ2WFMYZ3THXKBNMFB1EX0B9'); -/*!40000 ALTER TABLE `poses` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `provider_accounts` --- - -DROP TABLE IF EXISTS `provider_accounts`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `provider_accounts` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `role` enum('OWNER','MANAGER','OPERATOR') COLLATE utf8mb4_unicode_ci NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `provider_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `account_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `provider_accounts_account_id_key` (`account_id`), - KEY `provider_accounts_provider_id_fkey` (`provider_id`), - CONSTRAINT `provider_accounts_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT `provider_accounts_provider_id_fkey` FOREIGN KEY (`provider_id`) REFERENCES `providers` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `provider_accounts` --- - -LOCK TABLES `provider_accounts` WRITE; -/*!40000 ALTER TABLE `provider_accounts` DISABLE KEYS */; -INSERT INTO `provider_accounts` VALUES ('01KPX63VKD61AB8ET3J1MAH522','OWNER','2026-04-23 12:47:53','2026-04-23 12:47:53','01KPX63VJJ29HRTHZ4YQZVVQG5','01KPX63VK0ACPB3JDQV5JBCY0F'); -/*!40000 ALTER TABLE `provider_accounts` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `providers` --- - -DROP TABLE IF EXISTS `providers`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `providers` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `code` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `status` enum('ACTIVE','SUSPENDED') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'ACTIVE', - `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `providers_code_key` (`code`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `providers` --- - -LOCK TABLES `providers` WRITE; -/*!40000 ALTER TABLE `providers` DISABLE KEYS */; -INSERT INTO `providers` VALUES ('01KPX63VJJ29HRTHZ4YQZVVQG5','Tosan','ACTIVE','توسن','2026-04-23 12:47:53','2026-04-23 12:47:53'); -/*!40000 ALTER TABLE `providers` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `sales_invoice_items` --- - -DROP TABLE IF EXISTS `sales_invoice_items`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `sales_invoice_items` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `quantity` decimal(10,0) NOT NULL, - `unit_type` enum('COUNT','GRAM','KILOGRAM','MILLILITER','LITER','METER','HOUR') COLLATE utf8mb4_unicode_ci NOT NULL, - `unit_price` decimal(15,2) NOT NULL DEFAULT '0.00', - `total_amount` decimal(15,2) NOT NULL DEFAULT '0.00', - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `discount` decimal(15,2) NOT NULL DEFAULT '0.00', - `notes` text COLLATE utf8mb4_unicode_ci, - `invoice_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `good_id` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `service_id` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `payload` json DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `sales_invoice_items_invoice_id_good_id_idx` (`invoice_id`,`good_id`), - KEY `sales_invoice_items_good_id_fkey` (`good_id`), - KEY `sales_invoice_items_service_id_fkey` (`service_id`), - CONSTRAINT `sales_invoice_items_good_id_fkey` FOREIGN KEY (`good_id`) REFERENCES `goods` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT `sales_invoice_items_invoice_id_fkey` FOREIGN KEY (`invoice_id`) REFERENCES `sales_invoices` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT `sales_invoice_items_service_id_fkey` FOREIGN KEY (`service_id`) REFERENCES `services` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `sales_invoice_items` --- - -LOCK TABLES `sales_invoice_items` WRITE; -/*!40000 ALTER TABLE `sales_invoice_items` DISABLE KEYS */; -/*!40000 ALTER TABLE `sales_invoice_items` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `sales_invoice_payments` --- - -DROP TABLE IF EXISTS `sales_invoice_payments`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `sales_invoice_payments` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `invoice_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `amount` decimal(15,2) NOT NULL, - `payment_method` enum('TERMINAL','CASH','SET_OFF','CARD','BANK','CHECK','OTHER') COLLATE utf8mb4_unicode_ci NOT NULL, - `paid_at` datetime(3) NOT NULL, - `created_at` datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), - PRIMARY KEY (`id`), - KEY `sales_invoice_payments_invoice_id_idx` (`invoice_id`), - CONSTRAINT `sales_invoice_payments_invoice_id_fkey` FOREIGN KEY (`invoice_id`) REFERENCES `sales_invoices` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `sales_invoice_payments` --- - -LOCK TABLES `sales_invoice_payments` WRITE; -/*!40000 ALTER TABLE `sales_invoice_payments` DISABLE KEYS */; -/*!40000 ALTER TABLE `sales_invoice_payments` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `sales_invoices` --- - -DROP TABLE IF EXISTS `sales_invoices`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `sales_invoices` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `code` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, - `total_amount` decimal(15,2) NOT NULL, - `notes` text COLLATE utf8mb4_unicode_ci, - `unknown_customer` json DEFAULT NULL, - `invoice_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `customer_id` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `account_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `pos_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `sales_invoices_code_key` (`code`), - KEY `sales_invoices_customer_id_fkey` (`customer_id`), - KEY `sales_invoices_pos_id_fkey` (`pos_id`), - KEY `sales_invoices_account_id_fkey` (`account_id`), - CONSTRAINT `sales_invoices_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `consumer_accounts` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT `sales_invoices_customer_id_fkey` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT `sales_invoices_pos_id_fkey` FOREIGN KEY (`pos_id`) REFERENCES `poses` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `sales_invoices` --- - -LOCK TABLES `sales_invoices` WRITE; -/*!40000 ALTER TABLE `sales_invoices` DISABLE KEYS */; -/*!40000 ALTER TABLE `sales_invoices` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `service_categories` --- - -DROP TABLE IF EXISTS `service_categories`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `service_categories` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, - `description` text COLLATE utf8mb4_unicode_ci, - `image_url` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `account_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `complex_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `deleted_at` timestamp NULL DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `service_categories` --- - -LOCK TABLES `service_categories` WRITE; -/*!40000 ALTER TABLE `service_categories` DISABLE KEYS */; -/*!40000 ALTER TABLE `service_categories` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `services` --- - -DROP TABLE IF EXISTS `services`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `services` ( - `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, - `description` text COLLATE utf8mb4_unicode_ci, - `sku` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL, - `local_sku` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `barcode` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL, - `deleted_at` timestamp NULL DEFAULT NULL, - `category_id` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `base_sale_price` decimal(15,0) NOT NULL DEFAULT '0', - `account_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - `complex_id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `services_sku_key` (`sku`), - UNIQUE KEY `services_local_sku_key` (`local_sku`), - UNIQUE KEY `services_barcode_key` (`barcode`), - KEY `services_category_id_idx` (`category_id`), - CONSTRAINT `services_category_id_fkey` FOREIGN KEY (`category_id`) REFERENCES `service_categories` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `services` --- - -LOCK TABLES `services` WRITE; -/*!40000 ALTER TABLE `services` DISABLE KEYS */; -/*!40000 ALTER TABLE `services` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `trigger_logs` --- - -DROP TABLE IF EXISTS `trigger_logs`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `trigger_logs` ( - `id` int NOT NULL AUTO_INCREMENT, - `message` text COLLATE utf8mb4_unicode_ci NOT NULL, - `createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `name` text COLLATE utf8mb4_unicode_ci NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `trigger_logs` --- - -LOCK TABLES `trigger_logs` WRITE; -/*!40000 ALTER TABLE `trigger_logs` DISABLE KEYS */; -/*!40000 ALTER TABLE `trigger_logs` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping routines for database 'psp' --- --- --- WARNING: can't read the INFORMATION_SCHEMA.libraries table. It's most probably an old server 8.0.45. --- -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2026-04-27 9:20:30 diff --git a/src/modules/admin/guilds/goods/goods.service.ts b/src/modules/admin/guilds/goods/goods.service.ts index 616ee8e..c9f608e 100644 --- a/src/modules/admin/guilds/goods/goods.service.ts +++ b/src/modules/admin/guilds/goods/goods.service.ts @@ -57,26 +57,22 @@ export class GoodsService { async findAll(guildId: string) { const cacheKey = RedisKeyMaker.guildGoodsList(guildId) - const cached = await this.redisService.getJson<{ goods: unknown[]; total: number }>( + return this.redisService.getAndSet( cacheKey, + 'paginate', + async () => { + const [goods, total] = await this.prisma.$transaction([ + this.prisma.good.findMany({ + where: this.defaultWhere(guildId), + select: this.defaultSelect, + }), + this.prisma.good.count(), + ]) + + return { items: goods, total } + }, + this.listCacheTtlSeconds, ) - if (cached) { - return ResponseMapper.paginate(cached.goods, { total: cached.total }) - } - - const [goods, total] = await this.prisma.$transaction([ - this.prisma.good.findMany({ - where: this.defaultWhere(guildId), - select: this.defaultSelect, - }), - this.prisma.good.count(), - ]) - - await this.redisService.setJson(cacheKey, { goods, total }, this.listCacheTtlSeconds) - - return ResponseMapper.paginate(goods, { - total, - }) } async findOne(guild_id: string, id: string) { diff --git a/src/modules/admin/guilds/stock-keeping-units/stock-keeping-units.service.ts b/src/modules/admin/guilds/stock-keeping-units/stock-keeping-units.service.ts index 6b42198..7d07f84 100644 --- a/src/modules/admin/guilds/stock-keeping-units/stock-keeping-units.service.ts +++ b/src/modules/admin/guilds/stock-keeping-units/stock-keeping-units.service.ts @@ -31,20 +31,20 @@ export class StockKeepingUnitsService { async findAll(guild_id: string) { const cacheKey = this.getListCacheKey(guild_id) - const cached = await this.redisService.getJson(cacheKey) - if (cached) { - return ResponseMapper.list(cached) - } + return await this.redisService.getAndSet( + cacheKey, + 'list', + async () => { + const items = await this.prisma.stockKeepingUnits.findMany({ + where: { guild_id }, + orderBy: { created_at: 'desc' }, + }) - const items = await this.prisma.stockKeepingUnits.findMany({ - where: { guild_id }, - orderBy: { created_at: 'desc' }, - }) - - const mappedData = items.map(this.mapData) - await this.redisService.setJson(cacheKey, mappedData, this.listCacheTtlSeconds) - - return ResponseMapper.list(mappedData) + const mappedData = items.map(this.mapData) + return mappedData + }, + this.listCacheTtlSeconds, + ) } async create(guild_id: string, data: CreateStockKeepingUnitDto) { diff --git a/src/modules/admin/partners/activatedLicenses/activatedLicenses.service.ts b/src/modules/admin/partners/activatedLicenses/activatedLicenses.service.ts index e7a1290..b6def62 100644 --- a/src/modules/admin/partners/activatedLicenses/activatedLicenses.service.ts +++ b/src/modules/admin/partners/activatedLicenses/activatedLicenses.service.ts @@ -17,14 +17,6 @@ export class PartnerActivatedLicensesService { ) {} async findAll(partner_id: string, page = 1, perPage = 10) { - const cacheKey = RedisKeyMaker.partnerActivatedLicensesList(partner_id, page, perPage) - const cached = await this.redisService.getJson<{ data: unknown[]; total: number }>( - cacheKey, - ) - if (cached) { - return ResponseMapper.paginate(cached.data, { page, perPage, total: cached.total }) - } - const defaultWhere: LicenseActivationWhereInput = { license: { charge_transaction: { @@ -32,69 +24,70 @@ export class PartnerActivatedLicensesService { }, }, } - const [activatedLicense, total] = await this.prisma.$transaction(async tx => [ - await tx.licenseActivation.findMany({ - where: defaultWhere, - skip: (page - 1) * perPage, - take: perPage, - select: { - id: true, - starts_at: true, - expires_at: true, - created_at: true, - account_allocations: { - select: { - id: true, - account_id: true, + const cacheKey = RedisKeyMaker.partnerActivatedLicensesList(partner_id, page, perPage) + return await this.redisService.getAndSet(cacheKey, 'paginate', async () => { + const [activatedLicense, total] = await this.prisma.$transaction(async tx => [ + await tx.licenseActivation.findMany({ + where: defaultWhere, + skip: (page - 1) * perPage, + take: perPage, + select: { + id: true, + starts_at: true, + expires_at: true, + created_at: true, + account_allocations: { + select: { + id: true, + account_id: true, + }, }, - }, - business_activity: { - select: { - id: true, - name: true, - consumer: { - select: { - id: true, - ...QUERY_CONSTANTS.CONSUMER.infoSelect, + business_activity: { + select: { + id: true, + name: true, + consumer: { + select: { + id: true, + ...QUERY_CONSTANTS.CONSUMER.infoSelect, + }, }, }, }, }, - }, - }), - await tx.licenseActivation.count({ - where: defaultWhere, - }), - ]) + }), + await tx.licenseActivation.count({ + where: defaultWhere, + }), + ]) - const mappedLicenses = activatedLicense.map(license => { - const { account_allocations, business_activity, ...rest } = license - const { consumer, ...businessActivityRest } = business_activity + const mappedLicenses = activatedLicense.map(license => { + const { account_allocations, business_activity, ...rest } = license + const { consumer, ...businessActivityRest } = business_activity - const mappedConsumer = consumer_mappersUtil(consumer) + const mappedConsumer = consumer_mappersUtil(consumer) + return { + ...rest, + license: { + accounts_limit: account_allocations.length, + allocated_account_count: account_allocations.filter( + allocation => allocation.account_id !== null, + ).length, + }, + business_activity: { + ...business_activity, + consumer_name: mappedConsumer.name, + }, + } + }) return { - ...rest, - license: { - accounts_limit: account_allocations.length, - allocated_account_count: account_allocations.filter( - allocation => allocation.account_id !== null, - ).length, - }, - business_activity: { - ...business_activity, - consumer_name: mappedConsumer.name, - }, + items: mappedLicenses, + page, + perPage, + total, } }) - - await this.redisService.setJson(cacheKey, { data: mappedLicenses, total }, 300) - - return ResponseMapper.paginate(mappedLicenses, { - page, - perPage, - total, - }) } // async update(partnerId: string, id: string, data: UpdateLicenseDto) { diff --git a/src/modules/admin/partners/chargedLicenseTransactions/chargedLicenseTransactions.service.ts b/src/modules/admin/partners/chargedLicenseTransactions/chargedLicenseTransactions.service.ts index 8547690..40cf6ba 100644 --- a/src/modules/admin/partners/chargedLicenseTransactions/chargedLicenseTransactions.service.ts +++ b/src/modules/admin/partners/chargedLicenseTransactions/chargedLicenseTransactions.service.ts @@ -65,56 +65,45 @@ export class PartnerLicenseChargeTransactionService { page, perPage, ) - const cached = await this.redisService.getJson<{ data: unknown[]; total: number }>( - cacheKey, - ) - if (cached) { - return ResponseMapper.paginate(cached.data, { page, perPage, total: cached.total }) - } const defaultWhere: LicenseChargeTransactionWhereInput = { partner_id, } + return await this.redisService.getAndSet(cacheKey, 'paginate', async () => { + const [transactions, total] = await this.prisma.$transaction(async tx => [ + await tx.licenseChargeTransaction.findMany({ + where: defaultWhere, + skip: (page - 1) * perPage, + take: perPage, + select: this.defaultSelect, + }), + await tx.licenseChargeTransaction.count({ + where: defaultWhere, + }), + ]) - const [transactions, total] = await this.prisma.$transaction(async tx => [ - await tx.licenseChargeTransaction.findMany({ - where: defaultWhere, - skip: (page - 1) * perPage, - take: perPage, - select: this.defaultSelect, - }), - await tx.licenseChargeTransaction.count({ - where: defaultWhere, - }), - ]) - - const mappedTransactions = transactions.map(this.mappedTransaction) - await this.redisService.setJson(cacheKey, { data: mappedTransactions, total }, 300) - - return ResponseMapper.paginate(mappedTransactions, { - page, - perPage, - total, + const mappedTransactions = transactions.map(this.mappedTransaction) + return { + items: mappedTransactions, + page, + perPage, + total, + } }) } async findOne(partner_id: string, id: string) { const cacheKey = RedisKeyMaker.partnerLicenseChargeTransactionDetail(partner_id, id) - const cached = await this.redisService.getJson(cacheKey) - if (cached) { - return ResponseMapper.single(cached) - } - - const transaction = await this.prisma.licenseChargeTransaction.findUniqueOrThrow({ - where: { - id, - partner_id, - }, - select: this.defaultSelect, + return await this.redisService.getAndSet(cacheKey, 'single', async () => { + const transaction = await this.prisma.licenseChargeTransaction.findUniqueOrThrow({ + where: { + id, + partner_id, + }, + select: this.defaultSelect, + }) + return this.mappedTransaction(transaction) }) - const mappedTransaction = this.mappedTransaction(transaction) - await this.redisService.setJson(cacheKey, mappedTransaction, 300) - return ResponseMapper.single(mappedTransaction) } async create(partner_id: string, data: ChargeLicenseDto) { diff --git a/src/modules/admin/partners/partners.service.ts b/src/modules/admin/partners/partners.service.ts index 81a5d3c..28ef6fe 100644 --- a/src/modules/admin/partners/partners.service.ts +++ b/src/modules/admin/partners/partners.service.ts @@ -143,39 +143,26 @@ export class PartnersService { async findAll() { const cacheKey = RedisKeyMaker.partnersList() - const cached = await this.redisService.getJson(cacheKey) - if (cached) { - console.log('cached', cached) + return await this.redisService.getAndSet(cacheKey, 'list', async () => { + const partners = await this.prisma.partner.findMany({ + select: this.defaultSelect, + }) - return ResponseMapper.list(cached) - } - - const partners = await this.prisma.partner.findMany({ - select: this.defaultSelect, + return partners.map(this.mapPartner) }) - - const mappedPartners = partners.map(this.mapPartner) - await this.redisService.setJson(cacheKey, mappedPartners, 300) - - return ResponseMapper.list(mappedPartners) } async findOne(id: string) { const cacheKey = RedisKeyMaker.partnerDetail(id) - const cached = await this.redisService.getJson(cacheKey) - if (cached) { - return ResponseMapper.single(cached) - } - const partner = await this.prisma.partner.findUniqueOrThrow({ - where: { id }, - select: this.defaultSelect, + return await this.redisService.getAndSet(cacheKey, 'single', async () => { + const partner = await this.prisma.partner.findUniqueOrThrow({ + where: { id }, + select: this.defaultSelect, + }) + + return this.mapPartner(partner) }) - - const mappedPartner = this.mapPartner(partner) - await this.redisService.setJson(cacheKey, mappedPartner, 300) - - return ResponseMapper.single(mappedPartner) } async create(data: CreatePartnerDto, logo?: any) { diff --git a/src/modules/consumer/business-activities/business-activities.service.ts b/src/modules/consumer/business-activities/business-activities.service.ts index e91cc7c..56cbee9 100644 --- a/src/modules/consumer/business-activities/business-activities.service.ts +++ b/src/modules/consumer/business-activities/business-activities.service.ts @@ -61,34 +61,23 @@ export class BusinessActivitiesService { async findAll(consumer_id: string) { const cacheKey = RedisKeyMaker.consumerBusinessActivitiesList(consumer_id) - const cached = await this.redisService.getJson(cacheKey) - if (cached) { - return ResponseMapper.list(cached) - } - - const businessActivities = - await this.businessActivitiesQueryService.findAllByConsumer( + return await this.redisService.getAndSet(cacheKey, 'list', async () => { + return await this.businessActivitiesQueryService.findAllByConsumer( consumer_id, this.defaultSelect, ) - await this.redisService.setJson(cacheKey, businessActivities, this.cacheTtlSeconds) - return ResponseMapper.list(businessActivities) + }) } async findOne(consumer_id: string, id: string) { const cacheKey = RedisKeyMaker.consumerBusinessActivityInfo(consumer_id, id) - const cached = await this.redisService.getJson(cacheKey) - if (cached) { - return ResponseMapper.single(cached) - } - - const businessActivity = await this.businessActivitiesQueryService.findOneByConsumer( - consumer_id, - id, - this.defaultSelect, - ) - await this.redisService.setJson(cacheKey, businessActivity, this.cacheTtlSeconds) - return ResponseMapper.single(businessActivity) + return await this.redisService.getAndSet(cacheKey, 'list', async () => { + return await this.businessActivitiesQueryService.findOneByConsumer( + consumer_id, + id, + this.defaultSelect, + ) + }) } async update(consumer_id: string, id: string, data: any) { diff --git a/src/modules/consumer/consumer.service.ts b/src/modules/consumer/consumer.service.ts index 64e2135..3100c6d 100644 --- a/src/modules/consumer/consumer.service.ts +++ b/src/modules/consumer/consumer.service.ts @@ -21,25 +21,21 @@ export class ConsumerService { async getInfo(consumer_id: string) { const cacheKey = RedisKeyMaker.consumerInfo(consumer_id) - const cached = await this.redisService.getJson(cacheKey) - if (cached) { - return ResponseMapper.single(cached) - } - const consumer = await this.prisma.consumer.findUniqueOrThrow({ - where: { - id: consumer_id, - }, - select: { - id: true, - status: true, - ...QUERY_CONSTANTS.CONSUMER.infoSelect, - }, + return await this.redisService.getAndSet(cacheKey, 'single', async () => { + const consumer = await this.prisma.consumer.findUniqueOrThrow({ + where: { + id: consumer_id, + }, + select: { + id: true, + status: true, + ...QUERY_CONSTANTS.CONSUMER.infoSelect, + }, + }) + + return consumer_mappersUtil(consumer) }) - - const mappedConsumer = consumer_mappersUtil(consumer) - await this.redisService.setJson(cacheKey, mappedConsumer, this.infoCacheTtlSeconds) - return ResponseMapper.single(mappedConsumer) } async updateInfo(consumer_id: string, data: UpdateConsumerInfoDto) { diff --git a/src/modules/partners/consumers/business-activities/business-activities.service.ts b/src/modules/partners/consumers/business-activities/business-activities.service.ts index 1a706eb..028dca2 100644 --- a/src/modules/partners/consumers/business-activities/business-activities.service.ts +++ b/src/modules/partners/consumers/business-activities/business-activities.service.ts @@ -103,30 +103,26 @@ export class BusinessActivitiesService { page, perPage, ) - const cached = await this.redisService.getJson<{ items: unknown[]; total: number }>( - cacheKey, - ) - if (cached) { - return ResponseMapper.paginate(cached.items, { total: cached.total, page, perPage }) - } + return await this.redisService.getAndSet(cacheKey, 'paginate', async () => { + const where = this.defaultWhere(partner_id, consumer_id) + const [businessActivities, total] = await this.prisma.$transaction(async tx => [ + await tx.businessActivity.findMany({ + where, + select: this.defaultSelect, + skip: (page - 1) * perPage, + take: perPage, + }), + await tx.businessActivity.count({ where }), + ]) + const mappedItems = businessActivities.map(this.prepareBusinessActivityResponse) - const where = this.defaultWhere(partner_id, consumer_id) - const [businessActivities, total] = await this.prisma.$transaction(async tx => [ - await tx.businessActivity.findMany({ - where, - select: this.defaultSelect, - skip: (page - 1) * perPage, - take: perPage, - }), - await tx.businessActivity.count({ where }), - ]) - const mappedItems = businessActivities.map(this.prepareBusinessActivityResponse) - await this.redisService.setJson( - cacheKey, - { items: mappedItems, total }, - this.cacheTtlSeconds, - ) - return ResponseMapper.paginate(mappedItems, { total, page, perPage }) + return { + items: mappedItems, + total, + page, + perPage, + } + }) } async findOne(partner_id: string, consumer_id: string, id: string) { @@ -135,21 +131,16 @@ export class BusinessActivitiesService { consumer_id, id, ) - const cached = await this.redisService.getJson(cacheKey) - if (cached) { - return ResponseMapper.single(cached) - } - - const businessActivity = await this.prisma.businessActivity.findUnique({ - where: { - ...this.defaultWhere(partner_id, consumer_id), - id, - }, - select: this.defaultSelect, + return await this.redisService.getAndSet(cacheKey, 'single', async () => { + const businessActivity = await this.prisma.businessActivity.findUnique({ + where: { + ...this.defaultWhere(partner_id, consumer_id), + id, + }, + select: this.defaultSelect, + }) + return this.prepareBusinessActivityResponse(businessActivity) }) - const mappedItem = this.prepareBusinessActivityResponse(businessActivity) - await this.redisService.setJson(cacheKey, mappedItem, this.cacheTtlSeconds) - return ResponseMapper.single(mappedItem) } async create( diff --git a/src/modules/partners/consumers/business-activities/complexes/complexes.service.ts b/src/modules/partners/consumers/business-activities/complexes/complexes.service.ts index 4afeb7c..9de8cd4 100644 --- a/src/modules/partners/consumers/business-activities/complexes/complexes.service.ts +++ b/src/modules/partners/consumers/business-activities/complexes/complexes.service.ts @@ -65,44 +65,40 @@ export class BusinessActivityComplexesService { page, perPage, ) - const cached = await this.redisService.getJson<{ items: unknown[]; total: number }>( - cacheKey, - ) - if (cached) { - return ResponseMapper.paginate(cached.items, { total: cached.total, page, perPage }) - } - - const where = this.defaultWhere(partner_id, consumer_id, business_activity_id) - const [complexes, total] = await this.prisma.$transaction(async tx => [ - await tx.complex.findMany({ - where, - select: { - ...this.defaultSelect, - _count: { - select: { - pos_list: true, + return await this.redisService.getAndSet(cacheKey, 'paginate', async () => { + const where = this.defaultWhere(partner_id, consumer_id, business_activity_id) + const [complexes, total] = await this.prisma.$transaction(async tx => [ + await tx.complex.findMany({ + where, + select: { + ...this.defaultSelect, + _count: { + select: { + pos_list: true, + }, }, }, - }, - skip: (page - 1) * perPage, - take: perPage, - }), - await tx.complex.count({ where }), - ]) + skip: (page - 1) * perPage, + take: perPage, + }), + await tx.complex.count({ where }), + ]) + + const mappedComplexes = complexes.map(complex => { + const { _count, ...rest } = complex + return { + ...rest, + pos_count: _count.pos_list, + } + }) - const mappedComplexes = complexes.map(complex => { - const { _count, ...rest } = complex return { - ...rest, - pos_count: _count.pos_list, + items: mappedComplexes, + total, + page, + perPage, } }) - await this.redisService.setJson( - cacheKey, - { items: mappedComplexes, total }, - this.cacheTtlSeconds, - ) - return ResponseMapper.paginate(mappedComplexes, { total, page, perPage }) } async findOne( @@ -117,25 +113,21 @@ export class BusinessActivityComplexesService { business_activity_id, id, ) - const cached = await this.redisService.getJson(cacheKey) - if (cached) { - return ResponseMapper.single(cached) - } + return await this.redisService.getAndSet(cacheKey, 'single', async () => { + const complex = await this.prisma.complex.findFirst({ + where: { + ...this.defaultWhere(partner_id, consumer_id, business_activity_id), + id, + }, + select: this.defaultSelect, + }) - const complex = await this.prisma.complex.findFirst({ - where: { - ...this.defaultWhere(partner_id, consumer_id, business_activity_id), - id, - }, - select: this.defaultSelect, + if (!complex) { + throw new BadRequestException('شعبه مورد نظر یافت نشد.') + } + + return complex }) - - if (!complex) { - throw new BadRequestException('شعبه مورد نظر یافت نشد.') - } - - await this.redisService.setJson(cacheKey, complex, this.cacheTtlSeconds) - return ResponseMapper.single(complex) } async create( diff --git a/src/modules/partners/consumers/consumers.service.ts b/src/modules/partners/consumers/consumers.service.ts index 690b17b..78014cd 100644 --- a/src/modules/partners/consumers/consumers.service.ts +++ b/src/modules/partners/consumers/consumers.service.ts @@ -64,60 +64,42 @@ export class PartnerConsumersService { async findAll(partner_id: string, page = 1, perPage = 10) { const cacheKey = RedisKeyMaker.partnerConsumersList(partner_id, page, perPage) - const cached = await this.redisService.getJson<{ items: unknown[]; total: number }>( - cacheKey, - ) - if (cached) { - return ResponseMapper.paginate(cached.items, { total: cached.total, page, perPage }) - } + return await this.redisService.getAndSet(cacheKey, 'paginate', async () => { + const [consumers, total] = await this.prisma.$transaction(async tx => [ + await tx.consumer.findMany({ + where: this.defaultWhere(partner_id), + select: this.defaultSelect, + skip: (page - 1) * perPage, + take: 10, + }), + await tx.consumer.count({ + where: this.defaultWhere(partner_id), + }), + ]) + const mappedConsumers = consumers.map(mapConsumerWithLicenseUtil) - const [consumers, total] = await this.prisma.$transaction(async tx => [ - await tx.consumer.findMany({ - where: this.defaultWhere(partner_id), - select: this.defaultSelect, - skip: (page - 1) * perPage, - take: 10, - }), - await tx.consumer.count({ - where: this.defaultWhere(partner_id), - }), - ]) - const mappedItems = consumers.map(mapConsumerWithLicenseUtil) - await this.redisService.setJson( - cacheKey, - { items: mappedItems, total }, - this.infoCacheTtlSeconds, - ) - return ResponseMapper.paginate(mappedItems, { - total, - page, - perPage, + return { + items: mappedConsumers, + total, + page, + perPage, + } }) } async findOne(partner_id: string, consumer_id: string) { const cacheKey = RedisKeyMaker.partnerConsumerInfo(partner_id, consumer_id) - const cached = await this.redisService.getJson(cacheKey) - if (cached) { - return ResponseMapper.single(cached) - } + return await this.redisService.getAndSet(cacheKey, 'single', async () => { + const consumer = await this.prisma.consumer.findUniqueOrThrow({ + where: { + ...(this.defaultWhere(partner_id) as any), + id: consumer_id, + }, + select: this.defaultSelect, + }) - const consumer = await this.prisma.consumer.findUniqueOrThrow({ - where: { - ...(this.defaultWhere(partner_id) as any), - id: consumer_id, - }, - select: this.defaultSelect, + return mapConsumerWithLicenseUtil(consumer) }) - - const mappedConsumer = mapConsumerWithLicenseUtil(consumer) - await this.redisService.setJson( - RedisKeyMaker.consumerInfo(consumer_id), - mappedConsumer, - this.infoCacheTtlSeconds, - ) - await this.redisService.setJson(cacheKey, mappedConsumer, this.infoCacheTtlSeconds) - return ResponseMapper.single(mappedConsumer) } async create(partner_id: string, data: CreateConsumerDto) { diff --git a/src/modules/pos/goods/goods.service.ts b/src/modules/pos/goods/goods.service.ts index 9182ddd..f677ccf 100644 --- a/src/modules/pos/goods/goods.service.ts +++ b/src/modules/pos/goods/goods.service.ts @@ -52,47 +52,44 @@ export class GoodsService { guild_id: string, consumer_account_id: string, ) { - const cacheKey = RedisKeyMaker.posGoodsList(guild_id, business_activity_id) - try { - const cached = await this.redisService.getJson(cacheKey) - if (cached) { - return ResponseMapper.list(cached) - } - throw new Error('Cache miss') - } catch (error) { - const goods = await this.prisma.good.findMany({ - where: { - OR: [ - { - is_default_guild_good: true, - category: { - guild_id, + const cacheKey = RedisKeyMaker.posGoodsList(business_activity_id, guild_id) + return this.redisService.getAndSet( + cacheKey, + 'list', + async () => { + const goods = await this.prisma.good.findMany({ + where: { + OR: [ + { + is_default_guild_good: true, + category: { + guild_id, + }, + }, + { + business_activity_id, + }, + ], + }, + select: { + ...this.defaultSelect, + consumer_account_good_favorites: { + where: { + consumer_account_id, }, }, - { - business_activity_id, - }, - ], - }, - select: { - ...this.defaultSelect, - consumer_account_good_favorites: { - where: { - consumer_account_id, - }, }, - }, - }) + }) - const mappedGoods = goods.map(good => ({ - ...good, - is_favorite: good.consumer_account_good_favorites.length > 0, - })) + const mappedGoods = goods.map(good => ({ + ...good, + is_favorite: good.consumer_account_good_favorites.length > 0, + })) - await this.redisService.setJson(cacheKey, mappedGoods, this.listCacheTtlSeconds) - - return ResponseMapper.list(mappedGoods) - } + return mappedGoods + }, + this.listCacheTtlSeconds, + ) } async findOne(good_id: string, business_activity_id: string, guild_id: string) { diff --git a/src/modules/pos/pos.service.ts b/src/modules/pos/pos.service.ts index d8ec164..d5311dd 100644 --- a/src/modules/pos/pos.service.ts +++ b/src/modules/pos/pos.service.ts @@ -19,93 +19,95 @@ export class PosService { async getInfo(pos_id: string) { const cacheKey = RedisKeyMaker.posInfo(pos_id) - const cached = await this.redisService.getJson(cacheKey) - if (cached) { - return ResponseMapper.single(cached) - } - - const pos = await this.prisma.pos.findUniqueOrThrow({ - where: { - id: pos_id, - }, - select: { - name: true, - complex: { + return await this.redisService.getAndSet( + cacheKey, + 'single', + async () => { + const pos = await this.prisma.pos.findUniqueOrThrow({ + where: { + id: pos_id, + }, select: { - id: true, name: true, - branch_code: true, - business_activity: { + complex: { select: { id: true, name: true, - economic_code: true, - license_activation: { + branch_code: true, + business_activity: { select: { - expires_at: true, - license: { + id: true, + name: true, + economic_code: true, + license_activation: { select: { - id: true, - charge_transaction: { + expires_at: true, + license: { select: { - partner: { + id: true, + charge_transaction: { select: { - id: true, - name: true, - code: true, - logo_url: true, + partner: { + select: { + id: true, + name: true, + code: true, + logo_url: true, + }, + }, }, }, }, }, }, }, - }, - }, - guild: { - select: { - id: true, - name: true, - code: true, + guild: { + select: { + id: true, + name: true, + code: true, + }, + }, }, }, }, }, }, - }, - }, - }) - const { name, complex } = pos - const { name: complexName, id: complexId, business_activity } = complex - const { - name: businessName, - id: businessId, - guild, - economic_code, - license_activation, - } = business_activity + }) + const { name, complex } = pos + const { name: complexName, id: complexId, business_activity } = complex + const { + name: businessName, + id: businessId, + guild, + economic_code, + license_activation, + } = business_activity - const payload = { - name, - complex: { - id: complexId, - name: complexName, - branch_code: complex.branch_code, + const payload = { + name, + complex: { + id: complexId, + name: complexName, + branch_code: complex.branch_code, + }, + businessActivity: { + id: businessId, + name: businessName, + economic_code, + }, + guild, + license_info: { + expires_at: license_activation?.expires_at, + license_id: license_activation?.license.id, + }, + partner: license_activation?.license.charge_transaction.partner, + } + + return payload }, - businessActivity: { - id: businessId, - name: businessName, - economic_code, - }, - guild, - license_info: { - expires_at: license_activation?.expires_at, - license_id: license_activation?.license.id, - }, - partner: license_activation?.license.charge_transaction.partner, - } - await this.redisService.setJson(cacheKey, payload, this.infoCacheTtlSeconds) - return ResponseMapper.single(payload) + this.infoCacheTtlSeconds, + ) } async getAccessible(account_id: string) { @@ -153,57 +155,59 @@ export class PosService { async getMe(account_id: string, pos_id: string) { const cacheKey = RedisKeyMaker.posMe(account_id, pos_id) - const cached = await this.redisService.getJson(cacheKey) - if (cached) { - return ResponseMapper.single(cached) - } - - const pos = await this.prisma.consumerAccount.findUniqueOrThrow({ - where: { - id: account_id, - consumer: { - status: ConsumerStatus.ACTIVE, - business_activities: { - some: { - complexes: { + return await this.redisService.getAndSet( + cacheKey, + 'single', + async () => { + const pos = await this.prisma.consumerAccount.findUniqueOrThrow({ + where: { + id: account_id, + consumer: { + status: ConsumerStatus.ACTIVE, + business_activities: { some: { - pos_list: { + complexes: { some: { - id: pos_id, + pos_list: { + some: { + id: pos_id, + }, + }, }, }, }, }, }, }, - }, - }, - select: { - id: true, - role: true, - consumer: { select: { id: true, - type: true, - status: true, - ...QUERY_CONSTANTS.CONSUMER.infoSelect, + role: true, + consumer: { + select: { + id: true, + type: true, + status: true, + ...QUERY_CONSTANTS.CONSUMER.infoSelect, + }, + }, + account: { + select: { + username: true, + }, + }, }, - }, - account: { - select: { - username: true, - }, - }, + }) + + const { consumer, ...rest } = pos + + const payload = { + ...rest, + consumer: consumer_mappersUtil(consumer), + } + + return payload }, - }) - - const { consumer, ...rest } = pos - - const payload = { - ...rest, - consumer: consumer_mappersUtil(consumer), - } - await this.redisService.setJson(cacheKey, payload, this.meCacheTtlSeconds) - return ResponseMapper.single(payload) + this.meCacheTtlSeconds, + ) } } diff --git a/src/prisma/prisma.service.ts b/src/prisma/prisma.service.ts index f0f7378..d7a7902 100644 --- a/src/prisma/prisma.service.ts +++ b/src/prisma/prisma.service.ts @@ -14,7 +14,7 @@ export class PrismaService extends PrismaClient implements OnModuleInit, OnModul password: env('DATABASE_PASSWORD'), database: env('DATABASE_NAME'), port: env('DATABASE_PORT') ? Number(env('DATABASE_PORT')) : 3306, - connectionLimit: 50, + connectionLimit: 10, }) const prismaOptions = getPrismaOptions() diff --git a/src/redis/redis.service.ts b/src/redis/redis.service.ts index 65b3ec8..1f69ec4 100644 --- a/src/redis/redis.service.ts +++ b/src/redis/redis.service.ts @@ -1,27 +1,35 @@ +import { + MapperWrapper, + Paginated, + ResponseMapper, +} from '@/common/response/response-mapper' import { Injectable, Logger, OnModuleDestroy } from '@nestjs/common' import Redis from 'ioredis' +interface PaginatedCache { + items: T[] + total: number + page?: number + perPage?: number +} + @Injectable() export class RedisService implements OnModuleDestroy { + private static readonly scanCount = 100 private readonly logger = new Logger(RedisService.name) private readonly client: Redis constructor() { - const host = process.env.REDIS_HOST || 'redis' - const port = Number(process.env.REDIS_PORT || 6379) - const password = process.env.REDIS_PASSWORD || undefined - const db = Number(process.env.REDIS_DB || 0) - this.client = new Redis({ - host, - port, - password, - db, + host: process.env.REDIS_HOST || 'redis', + port: Number(process.env.REDIS_PORT || 6379), + password: process.env.REDIS_PASSWORD || undefined, + db: Number(process.env.REDIS_DB || 0), lazyConnect: true, maxRetriesPerRequest: 3, }) - this.client.on('error', (error) => { + this.client.on('error', error => { this.logger.error(`Redis error: ${error.message}`) }) } @@ -53,11 +61,7 @@ export class RedisService implements OnModuleDestroy { } } - async set( - key: string, - value: string, - ttlSeconds?: number, - ): Promise<'OK' | null> { + async set(key: string, value: string, ttlSeconds?: number): Promise<'OK' | null> { const client = await this.getClient() if (ttlSeconds && ttlSeconds > 0) { return client.set(key, value, 'EX', ttlSeconds) @@ -65,11 +69,7 @@ export class RedisService implements OnModuleDestroy { return client.set(key, value) } - async setJson( - key: string, - value: unknown, - ttlSeconds?: number, - ): Promise<'OK' | null> { + async setJson(key: string, value: unknown, ttlSeconds?: number): Promise<'OK' | null> { return this.set(key, JSON.stringify(value), ttlSeconds) } @@ -101,14 +101,12 @@ export class RedisService implements OnModuleDestroy { 'MATCH', pattern, 'COUNT', - 100, + RedisService.scanCount, ) cursor = nextCursor if (keys.length > 0) { - const pipeline = client.pipeline() - keys.forEach(k => pipeline.del(k)) - const results = await pipeline.exec() + const results = await this.deleteKeys(client, keys) if (results) { deletedCount += results.reduce((sum, [, value]) => { return sum + (typeof value === 'number' ? value : 0) @@ -127,6 +125,132 @@ export class RedisService implements OnModuleDestroy { return deletedCounts.reduce((sum, count) => sum + count, 0) } + async getAndSet( + key: string, + type: 'single', + callback: () => Promise, + ttlSeconds?: number, + ): Promise> + async getAndSet( + key: string, + type: 'list', + callback: () => Promise, + ttlSeconds?: number, + ): Promise> + async getAndSet( + key: string, + type: 'paginate', + callback: () => Promise>, + ttlSeconds?: number, + ): Promise> + async getAndSet( + key: string, + type: 'single' | 'list' | 'paginate', + callback: () => Promise>, + ttlSeconds?: number, + ): Promise | Paginated> { + switch (type) { + case 'single': + return this.getAndSetSingle(key, callback as () => Promise, ttlSeconds) + case 'list': + return this.getAndSetList(key, callback as () => Promise, ttlSeconds) + case 'paginate': + return this.getAndSetPaginate( + key, + callback as () => Promise>, + ttlSeconds, + ) + default: { + const neverType: never = type + throw new Error(`Unsupported cache type: ${neverType}`) + } + } + } + + private async getAndSetSingle( + key: string, + callback: () => Promise, + ttlSeconds?: number, + ): Promise> { + const cached = await this.tryReadJson(key) + if (cached !== null) { + return ResponseMapper.single(cached) + } + + const data = await callback() + await this.tryWriteJson(key, data, ttlSeconds) + return ResponseMapper.single(data) + } + + private async getAndSetList( + key: string, + callback: () => Promise, + ttlSeconds?: number, + ): Promise> { + const cached = await this.tryReadJson(key) + if (cached !== null) { + return ResponseMapper.list(cached) + } + + const data = await callback() + await this.tryWriteJson(key, data, ttlSeconds) + return ResponseMapper.list(data) + } + + private async getAndSetPaginate( + key: string, + callback: () => Promise>, + ttlSeconds?: number, + ): Promise> { + const cached = await this.tryReadJson>(key) + if (cached !== null) { + return ResponseMapper.paginate(cached.items, { + total: cached.total, + page: cached.page, + perPage: cached.perPage, + }) + } + + const data = await callback() + await this.tryWriteJson(key, data, ttlSeconds) + return ResponseMapper.paginate(data.items, { + total: data.total, + page: data.page, + perPage: data.perPage, + }) + } + + private async tryReadJson(key: string): Promise { + try { + return await this.getJson(key) + } catch (error) { + this.logger.warn(`Redis read failed for "${key}": ${(error as Error).message}`) + return null + } + } + + private async tryWriteJson( + key: string, + value: unknown, + ttlSeconds: number = 300, + ): Promise { + try { + await this.setJson(key, value, ttlSeconds) + } catch (error) { + this.logger.warn(`Redis write failed for "${key}": ${(error as Error).message}`) + } + } + + private async deleteKeys( + client: Redis, + keys: string[], + ): Promise> { + const pipeline = client.pipeline() + keys.forEach(key => pipeline.del(key)) + const results = await pipeline.exec() + return results ?? [] + } + async onModuleDestroy() { await this.client.quit() }