Skip to content

Commit

Permalink
feat(GeoTransaction): add delete function
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSolati committed Jan 24, 2019
1 parent 0b68729 commit e48a742
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/GeoFirestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class GeoFirestore {
* corresponding failure error will be returned.
*/
public runTransaction(
updateFunction: (transaction: GeoTransaction | GeoFirestoreTypes.cloud.Transaction | GeoFirestoreTypes.web.Transaction) => Promise<any>
updateFunction: (transaction: GeoFirestoreTypes.cloud.Transaction | GeoFirestoreTypes.web.Transaction) => Promise<any>
): Promise<any> {
return (this._firestore as GeoFirestoreTypes.web.Firestore).runTransaction(updateFunction);
}
Expand Down
16 changes: 16 additions & 0 deletions src/GeoTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GeoFirestoreTypes } from './GeoFirestoreTypes';
import { GeoDocumentReference } from './GeoDocumentReference';

/**
* A reference to a transaction. The `GeoTransaction` object passed to a transaction's updateFunction provides the methods to read and
Expand All @@ -10,4 +11,19 @@ export class GeoTransaction {
throw new Error('Transaction must be an instance of a Firestore Transaction');
}
}

/**
* Deletes the document referred to by the provided `GeoDocumentReference` or `DocumentReference`.
*
* @param documentRef A reference to the document to be deleted.
* @return This `GeoTransaction` instance. Used for chaining method calls.
*/
public delete(
documentRef: GeoDocumentReference | GeoFirestoreTypes.cloud.DocumentReference | GeoFirestoreTypes.web.DocumentReference
): GeoTransaction {
const ref = ((documentRef instanceof GeoDocumentReference) ?
documentRef['_document'] : documentRef) as GeoFirestoreTypes.web.DocumentReference;
(this._transaction as GeoFirestoreTypes.web.Transaction).delete(ref);
return this;
}
}

0 comments on commit e48a742

Please sign in to comment.