fix(auth): resolve tenant slug to UUID before user queries
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user