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

feat(core): get account default wallet by username method updated to … #4750

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tiankii
Copy link

@tiankii tiankii commented Feb 20, 2025

Sending Sats via SMS & Onboarding

imagen
Reference: Click here

  • This is an extension of the username query needed to find by phone number, required on the (sending Sats via SMS & Onboarding) task.

@github-actions github-actions bot added the core label Feb 20, 2025
let account: Account | RepositoryError

if (value.match(UsernameRegex)) {
account = await AccountsRepository().findByUsername(value as Username)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is not necessary, in cases like this is just return AccountsRepository().findByUsername(value as Username)


export const getAccountByUsernameOrPhone = async (
value: Username | PhoneNumber,
): Promise<Account> => {
Copy link
Collaborator

@dolcalmi dolcalmi Feb 25, 2025

Choose a reason for hiding this comment

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

please check other app layer methods, this methods should return the type and/or the application error type

if (value.match(UsernameRegex)) {
account = await AccountsRepository().findByUsername(value as Username)
} else {
const user = await UsersRepository().findByPhone(value as PhoneNumber)
Copy link
Collaborator

Choose a reason for hiding this comment

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

please dont use direct cast, use the checkedTo... methods from domain layer

import { mapError } from "@/graphql/error-map"
import { AccountsRepository, UsersRepository } from "@/services/mongoose"

export const getAccountByUsernameOrPhone = async (
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is not what I requested... this is more like getDefaultWalletByUsernameOrPhone

Copy link
Author

Choose a reason for hiding this comment

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

About this do you mean just a renaming change "getAccountByUsernameOrPhone" function to "getDefaultWalletByUsernameOrPhone"?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes.. you need to query the wallets that logic must not be at graphql layer

throw mapError(account)
}

const account = await Accounts.getAccountByUsernameOrPhone(username)
Copy link
Collaborator

Choose a reason for hiding this comment

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

you need to move the wallet selection too to app layer. including throw mapError(new CouldNotFindWalletFromUsernameAndCurrencyError(username)) but please dont throw just return new CouldNotFindWalletFromUsernameAndCurrencyError(username)

Copy link
Author

Choose a reason for hiding this comment

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

It is not clear to me what I should do, since I based on the other validations of the same file.

I also have doubts about the CouldNotFindWalletFromUsernameAndCurrencyError class, since that was already there, and we did not make any changes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

you need to move the wallet selection logic to app layer and in app layer you must not use throw

@@ -22,11 +21,7 @@ const AccountDefaultWalletQuery = GT.Field({
throw username
}

const account = await AccountsRepository().findByUsername(username)
if (account instanceof Error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this cant be removed... same apply to the new method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants