Add production-ready SuperAdmin API features for tenants, SMS, servers, and plugins.
Includes mobile auth, get_user/get_version, SMS wallet parity endpoints, appearance backfill, and related Prisma migrations. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
import { Prisma, ProductType, Tenant } from '@prisma/client';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { AuditService } from '../audit/audit.service';
|
||||
import { AdminNotifyService } from '../notifications/admin-notify.service';
|
||||
import { CreateTenantDto } from './dto/create-tenant.dto';
|
||||
import { UpdateTenantDto } from './dto/update-tenant.dto';
|
||||
|
||||
@@ -14,6 +15,7 @@ export class TenantsService {
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly audit: AuditService,
|
||||
private readonly notify: AdminNotifyService,
|
||||
) {}
|
||||
|
||||
async findAll(product?: ProductType) {
|
||||
@@ -36,6 +38,7 @@ export class TenantsService {
|
||||
appUrl: true,
|
||||
adminUrl: true,
|
||||
appUiConfig: true,
|
||||
appVersion: true,
|
||||
isActive: true,
|
||||
notes: true,
|
||||
createdAt: true,
|
||||
@@ -78,6 +81,7 @@ export class TenantsService {
|
||||
appUiConfig: dto.appUiConfig
|
||||
? (dto.appUiConfig as Prisma.InputJsonValue)
|
||||
: undefined,
|
||||
appVersion: dto.appVersion?.trim() || '1',
|
||||
isActive: dto.isActive ?? true,
|
||||
notes: dto.notes,
|
||||
},
|
||||
@@ -92,6 +96,10 @@ export class TenantsService {
|
||||
after: this.sanitize(tenant) as unknown as Prisma.InputJsonValue,
|
||||
});
|
||||
|
||||
this.notify.notifyAdmins(
|
||||
`سوپرادمین: نسخه جدید «${tenant.nameFa}» (${tenant.domain}) ایجاد شد.`,
|
||||
);
|
||||
|
||||
return this.sanitize(tenant);
|
||||
} catch (error) {
|
||||
this.handleUnique(error);
|
||||
@@ -136,6 +144,9 @@ export class TenantsService {
|
||||
...(dto.appUiConfig !== undefined && {
|
||||
appUiConfig: dto.appUiConfig as Prisma.InputJsonValue,
|
||||
}),
|
||||
...(dto.appVersion !== undefined && {
|
||||
appVersion: dto.appVersion.trim() || '1',
|
||||
}),
|
||||
...(dto.isActive !== undefined && { isActive: dto.isActive }),
|
||||
...(dto.notes !== undefined && { notes: dto.notes }),
|
||||
},
|
||||
@@ -151,6 +162,22 @@ export class TenantsService {
|
||||
after: this.sanitize(tenant) as unknown as Prisma.InputJsonValue,
|
||||
});
|
||||
|
||||
const bits: string[] = [];
|
||||
if (before.isActive !== tenant.isActive) {
|
||||
bits.push(tenant.isActive ? 'فعال شد' : 'غیرفعال شد');
|
||||
}
|
||||
if (before.appVersion !== tenant.appVersion) {
|
||||
bits.push(`ورژن ${before.appVersion} → ${tenant.appVersion}`);
|
||||
}
|
||||
if (before.nameFa !== tenant.nameFa || before.domain !== tenant.domain) {
|
||||
bits.push('هویت/دامنه تغییر کرد');
|
||||
}
|
||||
this.notify.notifyAdmins(
|
||||
bits.length
|
||||
? `سوپرادمین: نسخه «${tenant.nameFa}» — ${bits.join('؛ ')}`
|
||||
: `سوپرادمین: نسخه «${tenant.nameFa}» بهروزرسانی شد.`,
|
||||
);
|
||||
|
||||
return this.sanitize(tenant);
|
||||
} catch (error) {
|
||||
this.handleUnique(error);
|
||||
@@ -175,6 +202,10 @@ export class TenantsService {
|
||||
before: this.sanitize(before) as unknown as Prisma.InputJsonValue,
|
||||
});
|
||||
|
||||
this.notify.notifyAdmins(
|
||||
`سوپرادمین: نسخه «${before.nameFa}» (${before.domain}) حذف شد.`,
|
||||
);
|
||||
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user