fix(auth): resolve tenant slug to UUID before user queries

This commit is contained in:
Hamza-Ayed
2026-07-16 16:14:30 +03:00
parent 4f11580d4a
commit 4397b07d2f
3 changed files with 32 additions and 1 deletions
@@ -18,6 +18,23 @@ export class TenantsService {
return this.repo.findOne({ where: { slug } });
}
private static readonly UUID_RE =
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
/**
* يحوّل معرّف المستأجر القادم من الهيدر (slug مثل "siro" أو UUID) إلى سجل المستأجر.
* التطبيقات ترسل الـ slug؛ نحوّله للـ UUID المستخدَم في tenant_id (راجع docs/06).
*/
async resolve(idOrSlug: string): Promise<Tenant | null> {
if (!idOrSlug) return null;
const bySlug = await this.findBySlug(idOrSlug);
if (bySlug) return bySlug;
if (TenantsService.UUID_RE.test(idOrSlug)) {
return this.repo.findOne({ where: { id: idOrSlug } });
}
return null;
}
create(data: Partial<Tenant>): Promise<Tenant> {
return this.repo.save(this.repo.create(data));
}