-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add taxDoc as optional field in database
- Loading branch information
1 parent
8571369
commit 8bd38a3
Showing
8 changed files
with
41 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
import { Request } from 'express' | ||
import { onboardingBucket } from '../database' | ||
import { fetchUser } from './fetchUser' | ||
import { HttpError } from './httpError' | ||
|
||
export const fetchTaxInfo = async (wallet: Request['wallet']) => { | ||
const taxInfoFile = await onboardingBucket.file(`tax-information/${wallet.address}.pdf`) | ||
const [taxInfoExists] = await taxInfoFile.exists() | ||
const user = await fetchUser(wallet) | ||
const path = user?.taxDocument | ||
? `${user.taxDocument.split('/').at(-2)}/${user.taxDocument.split('/').at(-1)}` | ||
: `tax-information/${wallet.address}.pdf` | ||
const taxInfo = await onboardingBucket.file(path) | ||
|
||
const [taxInfoExists] = await taxInfo.exists() | ||
|
||
if (!taxInfoExists) { | ||
throw new HttpError(400, 'Tax info not found') | ||
throw new HttpError(404, 'Tax info not found') | ||
} | ||
const taxInfoPDF = await taxInfoFile.download() | ||
return taxInfoPDF | ||
|
||
const taxInfoPDF = await taxInfo.download() | ||
return taxInfoPDF[0] | ||
} |