import { Injectable } from '@nestjs/common';
import { Model } from 'mongoose';
import { InjectModel } from '@nestjs/mongoose';
import { Guest, GuestDocument } from '../schemes/guest.schema';

@Injectable()
export class GuestService {
  constructor(
    @InjectModel(Guest.name) private guestModel: Model<GuestDocument>,
  ) {}

  async findById(id: number) {
    return this.guestModel.findOne({ telegramId: id }).exec();
  }

  async setPhoto(id: number, file: string) {
    const user = await this.findById(id);
    if (!user) {
      return;
    }
    user.photo = file;
    await user.save();
  }
}
