mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-25 21:59:40 +00:00
26 lines
829 B
TypeScript
26 lines
829 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { IsNull, Not, Repository } from 'typeorm';
|
|
import { Device } from '../entities';
|
|
|
|
@Injectable()
|
|
export class DeviceRepository {
|
|
constructor(@InjectRepository(Device) private readonly deviceRepository: Repository<Device>) {}
|
|
|
|
findUserDeviceById(deviceId: string, userId: string) {
|
|
return this.deviceRepository.findOne({ where: { deviceId, userId } });
|
|
}
|
|
|
|
createDevice(data: Partial<Device>) {
|
|
return this.deviceRepository.save(data);
|
|
}
|
|
|
|
updateDevice(deviceId: string, data: Partial<Device>) {
|
|
return this.deviceRepository.save({ deviceId, ...data });
|
|
}
|
|
|
|
getTokens(userId: string) {
|
|
return this.deviceRepository.find({ where: { userId, fcmToken: Not(IsNull()) }, select: ['fcmToken'] });
|
|
}
|
|
}
|