Skip to content

Commit

Permalink
fix: move transfer validation from service to handler
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiyuSun committed Aug 28, 2023
1 parent c127534 commit bf128bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 6 additions & 2 deletions server/handlers/transferHandler/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ const transferPostSchema = Joi.alternatives()
{
then: Joi.object({
tokens: Joi.array().items(Joi.string()).required().unique(),
sender_wallet: Joi.alternatives().try(Joi.string()).required(),
sender_wallet: Joi.alternatives().try(Joi.string()).required().invalid(Joi.ref('receiver_wallet')).messages({
'any.invalid': 'Cannot transfer to the same wallet as the originating one!'
}),
receiver_wallet: Joi.alternatives().try(Joi.string()).required(),
claim: Joi.boolean().default(false),
}),
otherwise: Joi.object({
bundle: Joi.object({
bundle_size: Joi.number().min(1).max(10000).integer(),
}).required(),
sender_wallet: Joi.string().required(),
sender_wallet: Joi.string().required().invalid(Joi.ref('receiver_wallet')).messages({
'any.invalid': 'Cannot transfer to the same wallet as the originating one!'
}),
receiver_wallet: Joi.string().required(),
claim: Joi.boolean().default(false),
}),
Expand Down
7 changes: 0 additions & 7 deletions server/services/TransferService.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ class TransferService {
// begin transaction
try {
await this._session.beginTransaction();

if (transferBody.sender_wallet === transferBody.receiver_wallet) {
throw new HttpError(
422,
'Cannot transfer to the same wallet as the originating one!',
);
}

const walletSender = await this._walletService.getByIdOrName(
transferBody.sender_wallet,
Expand Down

0 comments on commit bf128bc

Please sign in to comment.