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

Handlers and Endpoints for Mojaloop/App/Firebase - Linking/Unlinking Flow #24

Merged
merged 123 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from 109 commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
c6c2dfd
feat: Handler logic for put participants
akapur99 Aug 25, 2020
df32e0f
Merge remote-tracking branch 'origin/master' into consentRequest
akapur99 Aug 25, 2020
edccad0
feat: add outgoing postConsentRequests method in Client
akapur99 Aug 25, 2020
deacbbb
feat: create consents Handler
akapur99 Aug 25, 2020
0f17193
refactor: fix spelling error in getConsentByID
akapur99 Aug 25, 2020
4fb2e87
feat: Add consentHandlers as default export
akapur99 Aug 25, 2020
5dbc21c
feat: initialize consent handler in firestore
akapur99 Aug 25, 2020
ed87a49
feat: add method to updateConsentById
akapur99 Aug 25, 2020
fe77c44
feat: add updateConsentById method to interface
akapur99 Aug 25, 2020
667363f
feat: Add method to handle creation of consent
akapur99 Aug 25, 2020
a35716e
feat: implement handler for PUT consentRequests/{ID}
akapur99 Aug 25, 2020
858aec4
feat: implement postConsent handler
akapur99 Aug 25, 2020
c7f83a2
fix: status should not be taken from request body
akapur99 Aug 26, 2020
d51fbe8
feat: create ConsentStatus enum and add field to consent object
akapur99 Aug 26, 2020
67c8df5
feat: allow consent status to be undefined(on creation)
akapur99 Aug 26, 2020
c4cfd8d
Merge remote-tracking branch 'origin/master' into consentRequest
akapur99 Aug 28, 2020
b481c5f
feat: Add update consent method to consent repository
akapur99 Aug 28, 2020
0d389e6
feat: implement handler for PUT parties/{Type}/{ID}
akapur99 Aug 28, 2020
ff99ecb
feat: Implement handler for PATCH consents/{ID}
akapur99 Aug 28, 2020
6466f1e
feat: implement PUT consents/{ID}
akapur99 Aug 28, 2020
ea4fa3a
feat: add methods to consent Handler
akapur99 Aug 31, 2020
2cf4491
feat: Add/update ConsentStatus enum
akapur99 Aug 31, 2020
8447762
feat: implement all linking related firestore handlers
akapur99 Aug 31, 2020
bf7d3c8
feat: Use ConsentStatus enum instead of hardcoding value
akapur99 Aug 31, 2020
49812bb
fix: Correct ConsentStatus Enum used
akapur99 Sep 1, 2020
a20f0dc
feat: Add/Update handlers in index
akapur99 Sep 1, 2020
9a49e03
feat: Implement app-side handler for DELETE consents/{ID}
akapur99 Sep 1, 2020
ba3ed53
style: updating licence
akapur99 Sep 1, 2020
6c28ba5
feat: add consent validator for firestore handlers
akapur99 Sep 1, 2020
15e7a60
refactor: remove postConsentRequests method - implemented in separate PR
akapur99 Sep 1, 2020
1639024
fix: Corrected validator method descriptions and updated validator me…
akapur99 Sep 1, 2020
3946c48
chore: linting fix
akapur99 Sep 1, 2020
8920d44
feat: Create participant repository and implement replace method
akapur99 Sep 1, 2020
ad2a59a
feat: implement PUT participants Handler
akapur99 Sep 1, 2020
62c3735
fix: add non-null assertions
akapur99 Sep 1, 2020
d989d75
chore: bump sdk-standard-components to 11.3.1 + audit fix
akapur99 Sep 1, 2020
de20706
fix: add non-null assertions
akapur99 Sep 2, 2020
e7d481a
fix: Incorrect handler type + method names + unneeded import
akapur99 Sep 2, 2020
c4f54b5
fix: add casting to avoid typescript errors
akapur99 Sep 2, 2020
9a872e2
Merge remote-tracking branch 'origin/master' into consentRequest
akapur99 Sep 2, 2020
b7102ea
Merge remote-tracking branch 'origin/master' into consentRequest
akapur99 Sep 2, 2020
a12c673
feat: Following unlinking diagram update, implement unlinking using f…
akapur99 Sep 2, 2020
c72cf12
docs: Added patchConsentsById to yaml files
akapur99 Sep 2, 2020
617b344
fix: necessary casting
akapur99 Sep 2, 2020
3e1d334
fix: add checks to validator for fspId
akapur99 Sep 2, 2020
9d3517f
fix: misc small merge conflict issues
akapur99 Sep 2, 2020
7a0136d
fix: accessing from request instead of context
akapur99 Sep 2, 2020
6054299
test: Unit tests for PUT participants
akapur99 Sep 2, 2020
a084124
test: Unit Test for POST consents handler
akapur99 Sep 2, 2020
9b4fa2a
test: Unit tests for PUT/PATCH consents/{ID}
akapur99 Sep 2, 2020
742b057
fix: Necessary casting
akapur99 Sep 2, 2020
de99659
fix: Correct test description
akapur99 Sep 2, 2020
8e3bb4b
refactor: using variables instead of harcoding ID
akapur99 Sep 2, 2020
3442dc5
fix: Correct extraction of ID from request params
akapur99 Sep 2, 2020
2d267af
test: Unit test for PUT consentRequests/{ID} handler
akapur99 Sep 2, 2020
c6db888
docs: adding comment justifying design decision
akapur99 Sep 2, 2020
4e383a9
feat: add callbackUri to config
akapur99 Sep 2, 2020
5b901da
refactor: Replace callbackUri values with config callbackUri
akapur99 Sep 2, 2020
7cd1b37
chore: bumped sdk-standard-components + central-services shared
akapur99 Sep 7, 2020
2362262
fix: Correct capitalization in context.request.params.ID
akapur99 Sep 7, 2020
e0e837e
fix: Correct types used in participant repository
akapur99 Sep 7, 2020
b07ee42
fix: Use correct types within Participant repository methods
akapur99 Sep 7, 2020
5b145d9
feat: Add OPAQUE to PartyIdType enum
akapur99 Sep 7, 2020
3bdb3d4
style: remove unneeded TODO comment
akapur99 Sep 7, 2020
c56f7a1
refactor: Add needed imports + switch to using enum over strings
akapur99 Sep 7, 2020
d86d39f
test: Add unit tests for consents firestore handlers
akapur99 Sep 7, 2020
e638cab
test: Ignore testing for src/shared/ml-thirdparty-client/models/core/…
akapur99 Sep 7, 2020
cb78424
fix: Checks for fspId in party
akapur99 Sep 7, 2020
cc55900
test: refactor to improve test readability and add structure
akapur99 Sep 7, 2020
af6e3af
test: add unit tests for consent validators
akapur99 Sep 8, 2020
edaa067
test: Add unit tests for error cases + refactor mocking for clarity
akapur99 Sep 8, 2020
7e76707
chore: bump @mojaloop/sdk-standard-components version to 11.5.1
akapur99 Sep 8, 2020
253eebb
refactor: switch to sdk-standard-components logger for mojaloop client
akapur99 Sep 8, 2020
a51a5c4
chore: Remove unneeded TODOs and comments
akapur99 Sep 8, 2020
09e3377
fix: Add error handling + remove unneeded comments
akapur99 Sep 8, 2020
b31fce9
test: Add logger mocking and implement tests for client error
akapur99 Sep 8, 2020
e4ae20b
fix: linter warnings
akapur99 Sep 8, 2020
21d7cb2
feat: Add flags to ignore testing for repository and factory methods
akapur99 Sep 8, 2020
64b590a
refactor: Change ConsentStatus enum values according to linking diagrams
akapur99 Sep 8, 2020
52dfc39
test: Add unit tests for firestore consent handlers
akapur99 Sep 8, 2020
60113d4
Update src/repositories/consent.ts
akapur99 Sep 8, 2020
544d991
refactor: Remove disabling of any type and replace any with unknown i…
akapur99 Sep 9, 2020
0d1d3e4
feat: Updated ambient.d.ts
akapur99 Sep 9, 2020
64ce4b6
refactor: Use enums when referencing http codes + update responseTool…
akapur99 Sep 9, 2020
eae71de
Merge remote-tracking branch 'origin/master' into consentRequest
akapur99 Sep 9, 2020
a54c40e
feat: update ambient.d.ts
akapur99 Sep 9, 2020
c3e5940
feat: utilize new error classes
akapur99 Sep 9, 2020
d33bacc
fix: remove incorrect declaration
akapur99 Sep 9, 2020
944f0a5
fix: change any to unknown type
akapur99 Sep 9, 2020
c7992b1
refactor: undo previous changes
akapur99 Sep 9, 2020
1b7e717
fix: Remove unnecessary `await` usage
akapur99 Sep 9, 2020
bcea9d0
fix: Declaration and import issues in ambient.d.ts
akapur99 Sep 9, 2020
32bd566
feat: Create declarations.d.ts file and add to tsconfig
akapur99 Sep 10, 2020
34caefc
chore: bump sdk-standard-components to v 11.5.2 + audit fix
akapur99 Sep 11, 2020
a2e268c
Merge remote-tracking branch 'origin/master' into consentRequest
akapur99 Sep 11, 2020
363e0c7
refactor: firestore consent handlers - to follow new StateServer inte…
akapur99 Sep 11, 2020
165439e
refactor: tests and files to follow new ambient declaration of StateS…
akapur99 Sep 11, 2020
dd63e63
Revert "feat: Create declarations.d.ts file and add to tsconfig"
akapur99 Sep 11, 2020
5f037ed
refactor: Use optional chaining in validators and merge 2 identical m…
akapur99 Sep 14, 2020
a0b02f2
chore: bump sdk-standard-components to v11.5.3
akapur99 Sep 14, 2020
75bff6f
style: modify TODO comment
akapur99 Sep 14, 2020
42d38a0
refactor: Replace unneeded type casting with non-null assertion
akapur99 Sep 14, 2020
dda5baa
refactor: Change name of callbackUri in config to pispCallbackUri
akapur99 Sep 14, 2020
1753903
chore: Add flags to ignore BDD testing which is covered in separate t…
akapur99 Sep 14, 2020
f8217a9
feat: Throw InvalidConsentStatus Error if default case reached in fir…
akapur99 Sep 15, 2020
b4af4fb
refactor: removed unneeded extra variable
akapur99 Sep 15, 2020
6a58745
refactor: Remove request logging for handlers which have been impleme…
akapur99 Sep 15, 2020
4fd24e6
fix: REplace any type with unknown
akapur99 Sep 15, 2020
d14415b
fix: remove ts-ignore
akapur99 Sep 15, 2020
7072fc0
feat: Add consent ID to invalidConsentStatusError for clarity
akapur99 Sep 15, 2020
e36cdeb
style: Add comments explaining decision to not await async code
akapur99 Sep 15, 2020
69f4718
refactor: Change method names to more accurately reflect function
akapur99 Sep 15, 2020
501af91
refactor: awaiting batch commits in repositories
akapur99 Sep 17, 2020
a5a8874
chore: bump sdk standard components to v 11.8.0
akapur99 Sep 17, 2020
0e2a6f5
fix: Make id a required variable for InvalidConsentStatusError
akapur99 Sep 17, 2020
ca24cbe
refactor: Use try/catch instead of .then/.catch for promise handling …
akapur99 Sep 17, 2020
143777b
Merge remote-tracking branch 'origin/master' into consentRequest
akapur99 Sep 18, 2020
c52584d
style: remove redundant comment
akapur99 Sep 21, 2020
06a21b4
build: Bump sdk-standard-components to v11.9.0
akapur99 Sep 22, 2020
30f7fb7
feat: Implement getParties request in mojaloopClient
akapur99 Sep 22, 2020
a370b25
Merge remote-tracking branch 'origin/master' into consentRequest
akapur99 Sep 22, 2020
a201c95
style: modified TODO comment
akapur99 Sep 24, 2020
38de745
fix: removed unneeded comments
akapur99 Sep 25, 2020
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
1 change: 1 addition & 0 deletions ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* Google
- Abhimanyu Kapur <[email protected]>
- Steven Wijaya <[email protected]>
- Abhimanyu Kapur <[email protected]>
--------------
******/

Expand Down
814 changes: 690 additions & 124 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@
"@hapi/inert": "^6.0.1",
"@hapi/vision": "^6.0.0",
"@mojaloop/central-services-logger": "^10.6.0",
"@mojaloop/sdk-standard-components": "^11.3.1",
"@mojaloop/central-services-shared": "^11.3.2",
"@mojaloop/sdk-standard-components": "^11.6.0",
"@types/uuid": "^8.0.0",
"convict": "^6.0.0",
"dotenv": "^8.2.0",
Expand Down
13 changes: 9 additions & 4 deletions src/interface/mojaloop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,17 @@ paths:
$ref: '../../node_modules/@mojaloop/api-snippets/v1.0/openapi3/responses/index.yaml#/501'
503:
$ref: '../../node_modules/@mojaloop/api-snippets/v1.0/openapi3/responses/index.yaml#/503'
delete:
patch:
tags:
- consents
summary: '[Mojaloop Callback] Result of deleting the specified consent'
description: Result of deleting the specified consent
operationId: deleteConsentsById
summary: '[Mojaloop Callback] Result of patching the specified consent (used in unlinking)'
description: Result of patching the specified consent (used in unlinking)
operationId: patchConsentsById
requestBody:
content:
application/json:
schema:
$ref: 'shared.yaml#/components/schemas/PatchConsentsByIdRequest'
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't it better to take this interface from api-snippets?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yup, I think it would be better that way! :-)
iirc, the current dependency still points to my forked repo (because it was set before the api-snippets was published), probably can fix that as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

make sense - I'll make a separate ticket for that - separation of concerns

responses:
200:
$ref: '../../node_modules/@mojaloop/api-snippets/v1.0/openapi3/responses/index.yaml#/200'
Expand Down
9 changes: 9 additions & 0 deletions src/interface/shared.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ components:
name:
type: string
description: Data model for the complex type Participant.
PatchConsentsByIdRequest:
title: PutConsentsByIdRequest
type: object
properties:
status:
type: string
revokedAt:
type: string
description: Data model for the complex type PatchConsentsByIdRequest.
PostAuthorizationsRequest:
title: PostAuthorizationsRequest
type: object
Expand Down
7 changes: 7 additions & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ const config = convict({
default: 'pisp',
env: 'MOJALOOP_PARTICIPANT_ID',
},
// TODO: Replace placeholder
pispCallbackUri: {
doc: 'The callback URI sent by PISP deeplinked with the app',
format: String,
default: 'PLACEHOLDER',
env: 'MOJALOOP_CALLBACK_URI',
},
endpoints: {
default: {
doc: 'Default endpoint to communicate with Mojaloop',
Expand Down
22 changes: 19 additions & 3 deletions src/models/consent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

* Google
- Steven Wijaya <[email protected]>
- Abhimanyu Kapur <[email protected]>
--------------
******/

Expand All @@ -40,22 +41,37 @@ export enum ConsentStatus {
* Waiting for the user to confirm payee information and provide more
* details about the transaction.
*/
PENDING_PAYEE_CONFIRMATION = 'PENDING_PAYEE_CONFIRMATION',
PENDING_PARTY_CONFIRMATION = 'PENDING_PARTY_CONFIRMATION',
eoln marked this conversation as resolved.
Show resolved Hide resolved

/**
* Waiting for the user to authorize the consent.
*/
AUTHORIZATION_REQUIRED = 'AUTHORIZATION_REQUIRED',
AUTHENTICATION_REQUIRED = 'AUTHENTICATION_REQUIRED',
akapur99 marked this conversation as resolved.
Show resolved Hide resolved

/**
* The consent is authorized and active.
* The consent is granted and active.
*/
CONSENT_GRANTED = 'CONSENT_GRANTED',

/**
* The consent is ACTIVE and challenge has been generated
*/
CHALLENGE_GENERATED = 'CHALLENGE_GENERATED',

/**
* The consent is ACTIVE and challenge has been verified
*/
ACTIVE = 'ACTIVE',

/**
* The consent is revoked and no longer valid.
*/
REVOKED = 'REVOKED',

/**
* The consent is requested to be revoked for unlinking.
*/
REVOKE_REQUESTED = 'REVOKE_REQUESTED',
}

export interface Consent {
Expand Down
5 changes: 5 additions & 0 deletions src/models/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ export class MissingConsentFieldsError extends Error {
this.consent = consent
}
}
export class InvalidConsentStatusError extends Error {
public constructor(consentStatus: string) {
akapur99 marked this conversation as resolved.
Show resolved Hide resolved
super(`Invalid Consent Status Provided! Status: ${consentStatus}`)
}
}
75 changes: 71 additions & 4 deletions src/repositories/consent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,47 @@
- Name Surname <[email protected]>

* Google
- Steven Wijaya <stevenwjy@google.com>
- Abhimanyu Kapur <abhi.kapur09@gmail.com>
--------------
******/

/* eslint-disable @typescript-eslint/no-explicit-any */
/* istanbul ignore file */
// TODO: BDD Testing will covered in separate ticket #1702

import firebase from '~/lib/firebase'
import { Consent } from '~/models/consent'
import { logger } from '~/shared/logger'

export interface IConsentRepository {
/**
* Updates a consent document based on a unique identifier.
*
* @param id Id for the consent document that needs to be updated.
* @param data Document fields that are about to be updated.
*/
updateConsentById(id: string, data: Record<string, unknown>): Promise<void>
akapur99 marked this conversation as resolved.
Show resolved Hide resolved

/**
* Retrieves a consent document based on its consent ID.
*
* @param id Consent ID of the document that needs to be retrieved.
*/
getByConsentId(id: string): Promise<Consent>
getConsentById(id: string): Promise<Consent>

/**
* Updates one or more consent documents based on the given conditions.
*
* @param conditions Conditions for the documents that need to be updated.
* @param data Document fields that are about to be updated.
*/
updateConsent(
conditions: Record<string, unknown>,
data: Record<string, unknown>
eoln marked this conversation as resolved.
Show resolved Hide resolved
): Promise<void>
}

export class FirebaseConsentRepository implements IConsentRepository {
async getByConsentId(id: string): Promise<Consent> {
async getConsentById(id: string): Promise<Consent> {
return new Promise((resolve, reject) => {
firebase
.firestore()
Expand All @@ -58,6 +78,53 @@ export class FirebaseConsentRepository implements IConsentRepository {
})
})
}

async updateConsentById(
id: string,
data: Record<string, unknown>
): Promise<void> {
await firebase.firestore().collection('consents').doc(id).update(data)
}

async updateConsent(
conditions: Record<string, unknown>,
data: Record<string, unknown>
): Promise<void> {
let firestoreQuery: FirebaseFirestore.Query = firebase
.firestore()
.collection('consents')

// Chain all of the given conditions to the query
for (const key in conditions) {
firestoreQuery = firestoreQuery.where(key, '==', conditions[key])
}

// Find and update all matching documents in Firebase that match the given conditions.
firestoreQuery
.get()
.then((response) => {
// Create a batch to perform all of the updates using a single request.
// Firebase will also execute the updates atomically according to the
// API specification.
const batch = firebase.firestore().batch()

// Iterate through all matching documents add them to the processing batch.
response.docs.forEach((doc) => {
batch.update(
// Put a reference to the document.
firebase.firestore().collection('consents').doc(doc.id),
// Specify the updated fields and their new values.
data
)
})

// Commit the updates.
return batch.commit()
akapur99 marked this conversation as resolved.
Show resolved Hide resolved
})
.catch((err) => {
logger.error(err)
})
}
}

export const consentRepository: IConsentRepository = new FirebaseConsentRepository()
81 changes: 81 additions & 0 deletions src/repositories/participants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*****
License
--------------
Copyright © 2020 Mojaloop Foundation
The Mojaloop files are made available by the Mojaloop Foundation under the Apache License, Version 2.0 (the 'License') and you may not use these files except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Contributors
--------------
This is the official list of the Mojaloop project contributors for this file.
Names of the original copyright holders (individuals or organizations)
should be listed with a '*' in the first column. People who have
contributed from an organization can be listed under the organization
that actually holds the copyright for their contributions (see the
Mojaloop Foundation organization for an example). Those individuals should have
their names indented and be marked with a '-'. Email address can be added
optionally within square brackets <email>.
* Mojaloop Foundation
- Name Surname <[email protected]>

* Google
- Steven Wijaya <[email protected]>
- Abhimanyu Kapur <[email protected]>
--------------
******/

/* istanbul ignore file */
// TODO: BDD Testing will covered in separate ticket #1702

import firebase from '~/lib/firebase'
import { logger } from '~/shared/logger'
import { Participant } from '~/shared/ml-thirdparty-client/models/core'

export interface IParticipantRepository {
/**
* Replace existing participants list with new list.
*
* @param data Documents that are about to be added.
*/
replace(data: Participant[]): Promise<void>
}

export class FirebaseParticipantRepository implements IParticipantRepository {
async replace(data: Participant[]): Promise<void> {
const collectionRef: FirebaseFirestore.CollectionReference<FirebaseFirestore.DocumentData> = firebase
.firestore()
.collection('participants')

// Find and update all matching documents in Firebase that match the given conditions.
collectionRef
.get()
.then(async (response) => {
// Create a batch to perform all of the updates using a single request.
// Firebase will also execute the updates atomically according to the
// API specification.
const batch = firebase.firestore().batch()

const batchSize = response.size
if (batchSize > 0) {
// If previous participants list exists, delete it

// Iterate through all matching documents add them to the processing batch.
response.docs.forEach((doc) => {
batch.delete(doc.ref)
})
}
// Iterate through received participants list and add them to the processing batch.
data.forEach((participant: Participant) => {
batch.set(collectionRef.doc(), participant)
stevenwjy marked this conversation as resolved.
Show resolved Hide resolved
})

// Commit the updates.
return batch.commit()
akapur99 marked this conversation as resolved.
Show resolved Hide resolved
})
.catch((err) => {
logger.error(err)
})
}
}

export const participantRepository: IParticipantRepository = new FirebaseParticipantRepository()
17 changes: 9 additions & 8 deletions src/repositories/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
--------------
******/

/* eslint-disable @typescript-eslint/no-explicit-any */
/* istanbul ignore file */
// TODO: BDD Testing will covered in separate ticket #1702

import firebase from '~/lib/firebase'
import { logger } from '~/shared/logger'
Expand All @@ -35,7 +36,7 @@ export interface ITransactionRepository {
* @param id Id for the transaction document that needs to be updated.
* @param data Document fields that are about to be updated.
*/
updateById(id: string, data: Record<string, any>): Promise<void>
updateById(id: string, data: Record<string, unknown>): Promise<void>
eoln marked this conversation as resolved.
Show resolved Hide resolved

/**
* Updates one or more transaction documents based on the given conditions.
Expand All @@ -44,19 +45,19 @@ export interface ITransactionRepository {
* @param data Document fields that are about to be updated.
*/
update(
conditions: Record<string, any>,
data: Record<string, any>
conditions: Record<string, unknown>,
data: Record<string, unknown>
): Promise<void>
}

export class FirebaseTransactionRepository implements ITransactionRepository {
async updateById(id: string, data: Record<string, any>): Promise<void> {
async updateById(id: string, data: Record<string, unknown>): Promise<void> {
await firebase.firestore().collection('transactions').doc(id).update(data)
}

async update(
conditions: Record<string, any>,
data: Record<string, any>
conditions: Record<string, unknown>,
data: Record<string, unknown>
): Promise<void> {
let firestoreQuery: FirebaseFirestore.Query = firebase
.firestore()
Expand All @@ -68,7 +69,7 @@ export class FirebaseTransactionRepository implements ITransactionRepository {
}

// Find and update all matching documents in Firebase that match the given conditions.
await firestoreQuery
firestoreQuery
.get()
.then((response) => {
// Create a batch to perform all of the updates using a single request.
Expand Down
Loading