import cleanObjectOfReferences from "../../helpers/cleanObjectOfReferences";
export default async function editUser(db, id, data) {
  const output = data;
  if (data.locationId) {
    output.location = db.document("locations", data.locationId);
    delete output.locationId;
  }
  if (data.companyId) {
    output.company = db.document("comapnies", data.companyId);
    delete output.companyId;
  }
  if (data.address) {
    output.address = await cleanObjectOfReferences(data.address);
  }
  if (data.billingAddress) {
    output.billingAddress = await cleanObjectOfReferences(data.billingAddress);
  }
  return db.update("users", id, output);
}
