Reclaim tenant aliases from every other version, not only the same product.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-20 18:20:07 +03:30
co-authored by Cursor
parent 6ba6a9cd45
commit e0dd53d639
+7 -9
View File
@@ -110,9 +110,8 @@ export class TenantsService {
notes: dto.notes,
},
});
await this.reclaimAliasesFromSameProduct(tx, {
await this.reclaimAliasesFromOtherTenants(tx, {
tenantId: created.id,
product: created.product,
aliases,
});
return created;
@@ -193,9 +192,8 @@ export class TenantsService {
try {
const tenant = await this.prisma.$transaction(async (tx: any) => {
if (nextAliases !== undefined) {
await this.reclaimAliasesFromSameProduct(tx, {
await this.reclaimAliasesFromOtherTenants(tx, {
tenantId: id,
product: dto.product ?? before.product,
aliases: nextAliases,
});
}
@@ -364,18 +362,18 @@ export class TenantsService {
}
/**
* دامنه/IP در aliases این نسخه، از domains[] نسخه‌های دیگر همان محصول برداشته می‌شود.
* خانگی و همکار جدا هستند؛ دامنهٔ اصلی (ستون domain) جابه‌جا نمی‌شود.
* دامنه/IP در aliases این نسخه، از domains[] همهٔ نسخه‌های دیگر برداشته می‌شود.
* دامنهٔ اصلی (ستون domain) جابه‌جا نمی‌شود.
*/
private async reclaimAliasesFromSameProduct(
private async reclaimAliasesFromOtherTenants(
tx: any,
opts: { tenantId: string; product: ProductType; aliases: string[] },
opts: { tenantId: string; aliases: string[] },
) {
const keys = new Set(opts.aliases.map((item) => this.hostKey(item)).filter(Boolean));
if (!keys.size) return;
const others = await tx.tenant.findMany({
where: { product: opts.product, id: { not: opts.tenantId } },
where: { id: { not: opts.tenantId } },
select: { id: true, nameFa: true, domain: true, domains: true },
});