Issue
The current implementation forces us to implement all the properties in User unless we set ignoreUndefinedProperties in the Firestore SDK.
Cause
The User datatype contains a bunch of optional properties and it will become undefined if we reference it as our current implementation.
|
export const createUserInFirestore = async (user: User) => { |
Suggested solution
We should use spread operator instead:
export const createUserInFirestore = async (user: User) => {
const { id, ...rest } = user;
await firestore().collection(USERS_COLLECTION_NAME).doc(id).set({
...rest,
createdAt: firestore.FieldValue.serverTimestamp(),
updatedAt: firestore.FieldValue.serverTimestamp(),
})
}
It's also less code.
Issue
The current implementation forces us to implement all the properties in
Userunless we setignoreUndefinedPropertiesin the Firestore SDK.Cause
The
Userdatatype contains a bunch of optional properties and it will become undefined if we reference it as our current implementation.react-native-firebase-chat-core/src/utils.ts
Line 19 in 5a9a630
Suggested solution
We should use spread operator instead:
It's also less code.