Initial SuperAdmin API (NestJS + Prisma)

This commit is contained in:
SuperAdmin
2026-07-23 10:25:32 +03:30
commit 7fbc47766c
43 changed files with 12902 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
@Injectable()
export class GetUserService {
constructor(private readonly prisma: PrismaService) {}
async resolveByHost(hostHeader?: string, domainQuery?: string) {
const host = this.normalizeHost(domainQuery || hostHeader || '');
if (!host) {
throw new NotFoundException('domain required');
}
const tenant = await this.prisma.tenant.findFirst({
where: {
isActive: true,
OR: [
{ domain: host },
{ domain: host.replace(/^www\./, '') },
{ domain: `www.${host.replace(/^www\./, '')}` },
],
},
});
if (!tenant) {
throw new NotFoundException('tenant not found for domain');
}
const ui = (tenant.appUiConfig as Record<string, any> | null) || null;
const themeColors = ui?.app?.theme?.colors;
const branding = {
id: tenant.id,
name: tenant.slug,
name_fa: tenant.nameFa,
name_en: tenant.nameEn,
avatar: tenant.avatarUrl,
color: themeColors?.primary || tenant.primaryColor,
secondary_color: themeColors?.secondary || tenant.secondaryColor,
background_color: themeColors?.background || tenant.backgroundColor,
node_server: tenant.nodeServer,
node_ws: tenant.nodeWs,
app_url: tenant.appUrl,
admin_url: tenant.adminUrl,
product: tenant.product,
theme: ui?.app?.theme?.mode === 'light' ? 'dynamicMode' : 'dynamicMode',
mode: 'dynamicMode',
app_ui_config: tenant.product === 'khanegi' ? ui : undefined,
};
return {
...branding,
user: { ...branding },
};
}
private normalizeHost(value: string) {
return value
.trim()
.toLowerCase()
.replace(/^https?:\/\//, '')
.split('/')[0]
.split(':')[0];
}
}