Skip to content

Commit

Permalink
Ensure WA exists for lock and unlock calls
Browse files Browse the repository at this point in the history
  • Loading branch information
sanducb committed Oct 2, 2024
1 parent fcfc76b commit b0de9ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/wallet/backend/src/card/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,14 @@ export class CardController implements ICardController {

public lock = async (req: Request, res: Response, next: NextFunction) => {
try {
const userId = req.session.user.id
const { params, query, body } = await validate(lockCardSchema, req)
const { cardId } = params
const { reasonCode } = query
const requestBody: ICardLockRequest = body

const result = await this.cardService.lock(
userId,
cardId,
reasonCode,
requestBody
Expand All @@ -151,11 +153,12 @@ export class CardController implements ICardController {

public unlock = async (req: Request, res: Response, next: NextFunction) => {
try {
const userId = req.session.user.id
const { params, body } = await validate(unlockCardSchema, req)
const { cardId } = params
const requestBody: ICardUnlockRequest = body

const result = await this.cardService.unlock(cardId, requestBody)
const result = await this.cardService.unlock(userId, cardId, requestBody)

res.status(200).json(toSuccessResponse(result))
} catch (error) {
Expand Down
6 changes: 6 additions & 0 deletions packages/wallet/backend/src/card/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,23 @@ export class CardService {
}

async lock(
userId: string,
cardId: string,
reasonCode: LockReasonCode,
requestBody: ICardLockRequest
): Promise<ICardResponse> {
await this.ensureWalletAddressExists(userId, cardId)

return this.gateHubClient.lockCard(cardId, reasonCode, requestBody)
}

async unlock(
userId: string,
cardId: string,
requestBody: ICardUnlockRequest
): Promise<ICardResponse> {
await this.ensureWalletAddressExists(userId, cardId)

return this.gateHubClient.unlockCard(cardId, requestBody)
}

Expand Down

0 comments on commit b0de9ce

Please sign in to comment.