import mongoose from 'mongoose';

import UploadedSheetModel, { IUploadedSheetDocWithFile } from '../models/UploadedSheet.model';

export const getSheetWithFile = async (sheetId) => {
  return UploadedSheetModel.aggregate<IUploadedSheetDocWithFile>([
    {
      $match: {
        '_id': new mongoose.Types.ObjectId(sheetId)
      }
    }, {
      $lookup: {
        from: 'uploadedfiles',
        localField: 'fileId',
        foreignField: '_id',
        as: 'file'
      }
    }, {
      $unwind: {
        path: '$file'
      }
    }
  ]);
}
