🚀 Initialize Musadaq SaaS: Full Backend + AI + React Dashboard + Docker Setup

This commit is contained in:
Hamza-Ayed
2026-04-16 23:26:32 +03:00
commit d66891ba0f
221 changed files with 13079 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
/**
* ════════════════════════════════════════════════════════════
* مُصادَق (Musadaq) — Users Service
* ════════════════════════════════════════════════════════════
*/
import { Injectable, NotFoundException, ConflictException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import * as bcrypt from 'bcrypt';
import { User } from './entities/user.entity';
@Injectable()
export class UsersService {
constructor(
@InjectRepository(User)
private userRepository: Repository<User>,
) {}
/**
* إضافة مستخدم لمكتب محاسبة
*/
async create(tenantId: string, dto: any): Promise<User> {
const existing = await this.userRepository.findOne({
where: { email: dto.email, tenant_id: tenantId },
});
if (existing) {
throw new ConflictException('User with this email already exists in this office');
}
const passwordHash = await bcrypt.hash(dto.password, 12);
const user = this.userRepository.create({
...dto,
password_hash: passwordHash,
tenant_id: tenantId,
});
return this.userRepository.save(user);
}
/**
* قائمة مستخدمي المكتب
*/
async findAll(tenantId: string): Promise<User[]> {
return this.userRepository.find({
where: { tenant_id: tenantId, is_active: true },
order: { created_at: 'ASC' },
});
}
/**
* تفاصيل مستخدم
*/
async findOne(tenantId: string, id: string): Promise<User> {
const user = await this.userRepository.findOne({
where: { id, tenant_id: tenantId },
});
if (!user) throw new NotFoundException('User not found');
return user;
}
/**
* تعطيل مستخدم
*/
async remove(tenantId: string, id: string): Promise<void> {
const user = await this.findOne(tenantId, id);
await this.userRepository.update(id, { is_active: false });
}
}