export default async function addPhoto(db, data) {
  const output = { ...data, createdAt: new Date() };
  if (data.jobId) {
    output.job = db.document("jobs", data.jobId);
    delete output.jobId;
  }
  if (data.siteId) {
    output.site = db.document("sites", data.siteId);
    delete output.siteId;
  }
  if (data.serviceId) {
    output.service = db.document("services", data.serviceId);
    delete output.serviceId;
  }
  if (data.inventoryId) {
    output.inventory = db.document("inventories", data.inventoryId);
    delete output.inventoryId;
  }
  return db.add("photos", output);
}
