diff --git a/apps/api/release/app.js b/apps/api/release/app.js index cb222c6..d4a4d66 100644 --- a/apps/api/release/app.js +++ b/apps/api/release/app.js @@ -88714,6 +88714,39 @@ var require_brand = __commonJS({ } }); +// dist/common/mobile-owner.js +var require_mobile_owner = __commonJS({ + "dist/common/mobile-owner.js"(exports2) { + "use strict"; + Object.defineProperty(exports2, "__esModule", { value: true }); + exports2.CUSTOMER_HOLDS_MOBILE = exports2.EXPERT_HOLDS_MOBILE = void 0; + exports2.activeExpertHoldsMobile = activeExpertHoldsMobile; + exports2.customerHoldsMobile = customerHoldsMobile; + var client_1 = require("@prisma/client"); + exports2.EXPERT_HOLDS_MOBILE = "\u0627\u06CC\u0646 \u0634\u0645\u0627\u0631\u0647 \u0645\u0648\u0628\u0627\u06CC\u0644 \u0642\u0628\u0644\u0627\u064B \u0628\u0631\u0627\u06CC \u06CC\u06A9 \u06A9\u0627\u0631\u0634\u0646\u0627\u0633 \u0641\u0631\u0648\u0634 \u062B\u0628\u062A \u0634\u062F\u0647 \u0627\u0633\u062A"; + exports2.CUSTOMER_HOLDS_MOBILE = "\u0627\u06CC\u0646 \u0634\u0645\u0627\u0631\u0647 \u0645\u0648\u0628\u0627\u06CC\u0644 \u0642\u0628\u0644\u0627\u064B \u0628\u0631\u0627\u06CC \u06CC\u06A9 \u0645\u0634\u062A\u0631\u06CC \u062B\u0628\u062A \u0634\u062F\u0647 \u0627\u0633\u062A"; + async function activeExpertHoldsMobile(db, mobile, exceptTradingCustomerId) { + const row = await db.adminUser.findFirst({ + where: { + mobile, + role: client_1.AdminRole.SALES_EXPERT, + isActive: true, + ...exceptTradingCustomerId ? { NOT: { salesExpertProfile: { is: { tradingCustomerId: exceptTradingCustomerId } } } } : {} + }, + select: { id: true } + }); + return row !== null; + } + async function customerHoldsMobile(db, mobile, exceptCustomerId) { + const row = await db.customer.findFirst({ + where: { mobile, ...exceptCustomerId ? { id: { not: exceptCustomerId } } : {} }, + select: { id: true } + }); + return row !== null; + } + } +}); + // dist/modules/customer-auth/customer-auth.service.js var require_customer_auth_service = __commonJS({ "dist/modules/customer-auth/customer-auth.service.js"(exports2) { @@ -88785,6 +88818,7 @@ var require_customer_auth_service = __commonJS({ var digits_1 = require_digits(); var sms_service_12 = require_sms_service(); var brand_1 = require_brand(); + var mobile_owner_1 = require_mobile_owner(); var TooManyRequestsException = class extends common_12.HttpException { constructor(message) { super(message, common_12.HttpStatus.TOO_MANY_REQUESTS); @@ -88924,7 +88958,7 @@ var require_customer_auth_service = __commonJS({ const fname = dto.fname.trim(); const lname = dto.lname.trim(); const existing = await this.prisma.customer.findUnique({ where: { mobile }, select: { id: true } }); - if (existing) { + if (existing || await (0, mobile_owner_1.activeExpertHoldsMobile)(this.prisma, mobile)) { throw new common_12.ConflictException("\u0627\u06CC\u0646 \u0634\u0645\u0627\u0631\u0647 \u0645\u0648\u0628\u0627\u06CC\u0644 \u0642\u0628\u0644\u0627\u064B \u062B\u0628\u062A \u0634\u062F\u0647 \u0627\u0633\u062A. \u0627\u0632 \u0628\u062E\u0634 \u0648\u0631\u0648\u062F \u0648\u0627\u0631\u062F \u0634\u0648\u06CC\u062F."); } try { @@ -96979,6 +97013,7 @@ var require_admin_customers_service = __commonJS({ var accounting_hooks_service_1 = require_accounting_hooks_service(); var accounting_config_service_1 = require_accounting_config_service(); var brand_1 = require_brand(); + var mobile_owner_1 = require_mobile_owner(); exports2.CUSTOMER_TYPE_STR = { SALES_AGENT: " \u06A9\u0627\u0631\u0634\u0646\u0627\u0633 \u0641\u0631\u0648\u0634", // legacy value only — see CustomerKind's schema comment @@ -97629,6 +97664,9 @@ var require_admin_customers_service = __commonJS({ if (!fullName || !mobile) { throw new common_12.BadRequestException("\u0646\u0627\u0645 \u0648 \u0645\u0648\u0628\u0627\u06CC\u0644 \u0627\u0644\u0632\u0627\u0645\u06CC \u0627\u0633\u062A"); } + if (await (0, mobile_owner_1.activeExpertHoldsMobile)(this.prisma, mobile)) { + throw new common_12.BadRequestException(mobile_owner_1.EXPERT_HOLDS_MOBILE); + } if (data.percent === void 0 || data.percent === null || data.percent === "") { throw new common_12.BadRequestException("\u0648\u0627\u0631\u062F \u06A9\u0631\u062F\u0646 percent \u0627\u0644\u0632\u0627\u0645\u06CC \u0627\u0633\u062A"); } @@ -97696,8 +97734,13 @@ var require_admin_customers_service = __commonJS({ if (data.percent !== void 0 && data.percent !== null && data.percent !== "") { patch.makingChargeOffsetPercent = new client_1.Prisma.Decimal(String(data.percent)); } - if (data.mobile !== void 0) - patch.mobile = (0, digits_1.faToEn)(String(data.mobile)); + if (data.mobile !== void 0) { + const mobile = (0, digits_1.faToEn)(String(data.mobile)); + patch.mobile = mobile; + if (mobile !== existing.mobile && await (0, mobile_owner_1.activeExpertHoldsMobile)(this.prisma, mobile, id)) { + throw new common_12.BadRequestException(mobile_owner_1.EXPERT_HOLDS_MOBILE); + } + } if (data.national_code !== void 0) patch.nationalCode = nationalCodeOrNull(data.national_code); if (data.city_id !== void 0) { @@ -101292,6 +101335,7 @@ var require_admin_users_service = __commonJS({ var digits_1 = require_digits(); var acl_constants_1 = require_acl_constants(); var super_admin_1 = require_super_admin(); + var mobile_owner_1 = require_mobile_owner(); var STORABLE_RIDS = new Set(acl_constants_1.ALL_RIDS.flatMap((rid) => rid.split(".").map((_2, i, parts) => parts.slice(0, i + 1).join(".")))); var AdminUsersService = class AdminUsersService { static { @@ -101489,6 +101533,9 @@ var require_admin_users_service = __commonJS({ const existing = await this.prisma.adminUser.findUnique({ where: { mobile } }); if (existing) throw new common_12.BadRequestException("\u0627\u06CC\u0646 \u0634\u0645\u0627\u0631\u0647 \u0645\u0648\u0628\u0627\u06CC\u0644 \u0642\u0628\u0644\u0627\u064B \u062B\u0628\u062A \u0634\u062F\u0647 \u0627\u0633\u062A"); + if (await (0, mobile_owner_1.customerHoldsMobile)(this.prisma, mobile)) { + throw new common_12.BadRequestException(mobile_owner_1.CUSTOMER_HOLDS_MOBILE); + } return this.prisma.adminUser.create({ data: { fullName, @@ -101610,6 +101657,9 @@ var require_admin_users_service = __commonJS({ const clash = await this.prisma.adminUser.findUnique({ where: { mobile } }); if (clash) throw new common_12.BadRequestException("\u0627\u06CC\u0646 \u0634\u0645\u0627\u0631\u0647 \u0645\u0648\u0628\u0627\u06CC\u0644 \u0642\u0628\u0644\u0627\u064B \u062B\u0628\u062A \u0634\u062F\u0647 \u0627\u0633\u062A"); + if (await (0, mobile_owner_1.customerHoldsMobile)(this.prisma, mobile, existing.salesExpertProfile?.tradingCustomerId)) { + throw new common_12.BadRequestException(mobile_owner_1.CUSTOMER_HOLDS_MOBILE); + } } patch.mobile = mobile; } diff --git a/apps/api/release/vendor/.prisma/client/edge.js b/apps/api/release/vendor/.prisma/client/edge.js index 46b7511..d04709f 100644 --- a/apps/api/release/vendor/.prisma/client/edge.js +++ b/apps/api/release/vendor/.prisma/client/edge.js @@ -819,7 +819,7 @@ const config = { "value": "prisma-client-js" }, "output": { - "value": "E:\\tehran_taj-wt\\node_modules\\.pnpm\\@prisma+client@5.22.0_prisma@5.22.0\\node_modules\\@prisma\\client", + "value": "E:\\tehran_taj\\node_modules\\.pnpm\\@prisma+client@5.22.0_prisma@5.22.0\\node_modules\\@prisma\\client", "fromEnvVar": null }, "config": { @@ -837,10 +837,11 @@ const config = { } ], "previewFeatures": [], - "sourceFilePath": "E:\\tehran_taj-wt\\apps\\api\\prisma\\schema.prisma" + "sourceFilePath": "E:\\tehran_taj\\apps\\api\\prisma\\schema.prisma" }, "relativeEnvPaths": { - "rootEnvPath": null + "rootEnvPath": null, + "schemaEnvPath": "../../../../../../apps/api/.env" }, "relativePath": "../../../../../../apps/api/prisma", "clientVersion": "5.22.0", diff --git a/apps/api/release/vendor/.prisma/client/index.js b/apps/api/release/vendor/.prisma/client/index.js index b70b0f0..4072850 100644 --- a/apps/api/release/vendor/.prisma/client/index.js +++ b/apps/api/release/vendor/.prisma/client/index.js @@ -820,7 +820,7 @@ const config = { "value": "prisma-client-js" }, "output": { - "value": "E:\\tehran_taj-wt\\node_modules\\.pnpm\\@prisma+client@5.22.0_prisma@5.22.0\\node_modules\\@prisma\\client", + "value": "E:\\tehran_taj\\node_modules\\.pnpm\\@prisma+client@5.22.0_prisma@5.22.0\\node_modules\\@prisma\\client", "fromEnvVar": null }, "config": { @@ -838,10 +838,11 @@ const config = { } ], "previewFeatures": [], - "sourceFilePath": "E:\\tehran_taj-wt\\apps\\api\\prisma\\schema.prisma" + "sourceFilePath": "E:\\tehran_taj\\apps\\api\\prisma\\schema.prisma" }, "relativeEnvPaths": { - "rootEnvPath": null + "rootEnvPath": null, + "schemaEnvPath": "../../../../../../apps/api/.env" }, "relativePath": "../../../../../../apps/api/prisma", "clientVersion": "5.22.0",