Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn committed Sep 27, 2022
2 parents a49c8c1 + 81a3ee1 commit 16ef552
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ios/Classes/FirebaseFirestoreModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
*/
- (void)getDocuments:(id)params;

/**
Returns a single doc saved in the provided Firestore collection.
- Parameter callback: The callback to be invoked if either the documents were fetched or an error occurred.
- Parameter collection: The name of the collection.
- Parameter document: The name of the document.
*/
- (void)getSingleDocument:(id)params;

/**
Updates an extisting document from the provided Firestore collection.
Expand Down
19 changes: 19 additions & 0 deletions ios/Classes/FirebaseFirestoreModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ - (void)getDocuments:(id)params
}];
}

- (void)getSingleDocument:(id)params
{
ENSURE_SINGLE_ARG(params, NSDictionary);

KrollCallback *callback = params[@"callback"];
NSString *collection = params[@"collection"];
NSString *document = params[@"document"];
FIRDocumentReference *docRef = [[self.db collectionWithPath:collection] documentWithPath:document];

[docRef getDocumentWithCompletion:^(FIRQuerySnapshot * _Nullable snapshot, NSError * _Nullable error) {
if (error != nil) {
[callback call:@[@{ @"success": @(NO), @"error": error.localizedDescription }] thisObject:self];
return;
}

[callback call:@[@{ @"success": @(YES), @"document": [snapshot data] }] thisObject:self];
}];
}

- (void)updateDocument:(id)params
{
ENSURE_SINGLE_ARG(params, NSDictionary);
Expand Down

0 comments on commit 16ef552

Please sign in to comment.