-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): get account default wallet by username method updated to …
…support phone number
- Loading branch information
1 parent
52b9d5d
commit 2eebfed
Showing
5 changed files
with
30 additions
and
8 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
core/api/src/app/accounts/get-account-for-username-or-phone.ts
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { UsernameRegex } from "@/domain/accounts" | ||
import { mapError } from "@/graphql/error-map" | ||
import { AccountsRepository, UsersRepository } from "@/services/mongoose" | ||
|
||
export const getAccountByUsernameOrPhone = async ( | ||
value: Username | PhoneNumber, | ||
): Promise<Account> => { | ||
let account: Account | RepositoryError | ||
|
||
if (value.match(UsernameRegex)) { | ||
account = await AccountsRepository().findByUsername(value as Username) | ||
} else { | ||
const user = await UsersRepository().findByPhone(value as PhoneNumber) | ||
if (user instanceof Error) throw mapError(user) | ||
|
||
account = await AccountsRepository().findByUserId(user.id) | ||
} | ||
|
||
if (account instanceof Error) throw mapError(account) | ||
|
||
return account | ||
} |
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