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

Fix parsing data from firestore #245

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/misc/translate-from-firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,29 @@ export const recursivelyMapStorageUrls = async (
(fieldValue as any[]).map(async (value, index) => {
fieldValue[index] = await recursivelyMapStorageUrls(fireWrapper, value);
})
);
).then(() => {
return fieldValue;
});
}
const isDocumentReference = isInputADocReference(fieldValue);
if (isDocumentReference) {
return fieldValue;
}

const isJSDate = fieldValue instanceof Date;
if(isJSDate){
return fieldValue;
}
Comment on lines +133 to +136
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What version of firebase are you using? I didn't think the firestore API would ever return a Date field 🤔

It is only meant to return a Timestamp which should be handled by this part here:

const isTimestamp = !!input.toDate && typeof input.toDate === "function";
if (isTimestamp) {
return input.toDate();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my project, the fields createdAt and updatedAt are of this type. I don't know why but it fix my problem.


const isObject = !isArray && typeof fieldValue === "object";
if (isObject) {
return Promise.all(
Object.keys(fieldValue).map(async (key) => {
const value = fieldValue[key];
fieldValue[key] = await recursivelyMapStorageUrls(fireWrapper, value);
})
);
).then(() => {
return fieldValue;
});;
}
};