import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { User, UserRole } from './entities/user.entity'; @Injectable() export class UsersService { constructor( @InjectRepository(User) private readonly userRepository: Repository, ) {} async findByPhone(tenantId: string, phone: string): Promise { return this.userRepository.findOne({ where: { tenant_id: tenantId, phone } }); } async findById(tenantId: string, id: string): Promise { return this.userRepository.findOne({ where: { tenant_id: tenantId, id } }); } async create(tenantId: string, phone: string, role: string = 'rider'): Promise { const user = this.userRepository.create({ tenant_id: tenantId, phone, role: role as UserRole }); return this.userRepository.save(user); } async listByTenant(tenantId: string): Promise { return this.userRepository.find({ where: { tenant_id: tenantId } }); } async updateProfile( tenantId: string, id: string, data: Partial>, ): Promise { await this.userRepository.update({ tenant_id: tenantId, id }, { name: data.name }); return this.findById(tenantId, id); } }