text: "use strict";
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
      var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
      if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
      else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
      return c > 3 && r && Object.defineProperty(target, key, r), r;
  };
  var __metadata = (this && this.__metadata) || function (k, v) {
      if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  };
  var __param = (this && this.__param) || function (paramIndex, decorator) {
      return function (target, key) { decorator(target, key, paramIndex); }
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.PhotoService = void 0;
  const typeorm_1 = require("@nestjs/typeorm");
  const common_1 = require("@nestjs/common");
  const aws_sdk_1 = require("aws-sdk");
  const uuid_1 = require("uuid");
  const responses_1 = require("../responses");
  const index_1 = require("../entities/index");
  const index_2 = require("../repositories/index");
  const config_service_1 = require("../config/config.service");
  let PhotoService = class PhotoService {
      constructor(photoRepository, userRepository, accessoryRepository, configService) {
          this.photoRepository = photoRepository;
          this.userRepository = userRepository;
          this.accessoryRepository = accessoryRepository;
          this.configService = configService;
      }
      async uploadImage(dataBuffer, filename) {
          const s3 = new aws_sdk_1.S3();
          const uploadResult = await s3
              .upload({
              Bucket: this.configService.get('AWS_PUBLIC_BUCKET_NAME'),
              Body: dataBuffer,
              Key: `avatars/${uuid_1.v4()}-${filename}`,
          })
              .promise();
          const newFile = this.photoRepository.create({
              url: uploadResult.Location,
              default: false,
          });
          await this.photoRepository.save(newFile);
          return newFile;
      }
      async findAll() {
          return `This action returns all photo`;
      }
      async findOne(id) {
          return `This action returns a #${id} photo`;
      }
      async remove(id) {
          const photo = await this.photoRepository.findOne({
              id: id,
          });
          if (!photo)
              return new responses_1.ApiResponse(false, responses_1.ERROR.PHOTO_NOT_FOUND);
          this.userRepository
              .createQueryBuilder()
              .delete()
              .from(index_1.PhotoEntity)
              .where('id = :id', {
              id: id,
          })
              .execute();
          return new responses_1.ApiResponse(true, responses_1.SUCCESS.PHOTO_DELETED);
      }
  };
  PhotoService = __decorate([
      common_1.Injectable(),
      __param(0, typeorm_1.InjectRepository(index_1.PhotoEntity)),
      __param(1, typeorm_1.InjectRepository(index_1.UserEntity)),
      __param(2, typeorm_1.InjectRepository(index_1.AccessoryEntity)),
      __metadata("design:paramtypes", [index_2.PhotoRepository,
          index_2.UserRepository,
          index_2.AccessoryRepository,
          config_service_1.ConfigService])
  ], PhotoService);
  exports.PhotoService = PhotoService;
  //# sourceMappingURL=photo.service.js.map