Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Document created w/o id inside entity does not contain it after fetching using fireorm #119

Closed
skalashnyk opened this issue Nov 19, 2019 · 2 comments

Comments

@skalashnyk
Copy link
Contributor

skalashnyk commented Nov 19, 2019

He there!

We need some workaround for documents that created without id inside js object - see example.

import * as admin from 'firebase-admin'

@Collection()
class Band {
  id: string;
  name: string;
}

async function createBand(band: Band): string {
  const doc = await admin.firestore().collection('bands').add(band);
  return doc.id;
}

async function getById(id: string): Promise<Band> {
  const doc = await admin.firestore().collection('bands').doc(id);
  return {id: doc.id, ...doc.data()};
}

// Assume, that we used firestore native sdk to create doc:
const band = new Band();
band.name = 'Nirvana';
const bandId = await createBand(band);

// then we decided to use fireorm
const bandFromFirestore = await getRepository(Band).findById(bandId);

expect(bandFromFirestore).to.be.instanceof(Band); // true
expect(bandFromFirestore.id).not.to.be.undefined; // error!

I've created pull request (/w tests) that resolved this - #120

@zhirschtritt
Copy link
Contributor

lgtm

@wovalle
Copy link
Owner

wovalle commented Nov 29, 2019

Closed in #124

@wovalle wovalle closed this as completed Nov 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants