@@ -14,14 +14,17 @@ import {
1414 getCardsByCustomerSchema ,
1515 getCardDetailsSchema ,
1616 lockCardSchema ,
17- unlockCardSchema
17+ unlockCardSchema ,
18+ changePinSchema
1819} from './validation'
1920
2021export interface ICardController {
2122 getCardsByCustomer : Controller < ICardDetailsResponse [ ] >
2223 getCardDetails : Controller < ICardResponse >
2324 lock : Controller < ICardResponse >
2425 unlock : Controller < ICardResponse >
26+ getPin : Controller < ICardResponse >
27+ changePin : Controller < void >
2528}
2629
2730export class CardController implements ICardController {
@@ -50,9 +53,9 @@ export class CardController implements ICardController {
5053 ) => {
5154 try {
5255 const userId = req . session . user . id
53- const { params, body } = await validate ( getCardDetailsSchema , req )
56+ const { params, query } = await validate ( getCardDetailsSchema , req )
5457 const { cardId } = params
55- const { publicKeyBase64 } = body
58+ const { publicKeyBase64 } = query
5659
5760 const requestBody : ICardDetailsRequest = { cardId, publicKeyBase64 }
5861 const cardDetails = await this . cardService . getCardDetails (
@@ -97,4 +100,37 @@ export class CardController implements ICardController {
97100 next ( error )
98101 }
99102 }
103+
104+ public getPin = async ( req : Request , res : Response , next : NextFunction ) => {
105+ try {
106+ const userId = req . session . user . id
107+ const { params, query } = await validate ( getCardDetailsSchema , req )
108+ const { cardId } = params
109+ const { publicKeyBase64 } = query
110+
111+ const requestBody : ICardDetailsRequest = { cardId, publicKeyBase64 }
112+ const cardPin = await this . cardService . getPin ( userId , requestBody )
113+ res . status ( 200 ) . json ( toSuccessResponse ( cardPin ) )
114+ } catch ( error ) {
115+ next ( error )
116+ }
117+ }
118+
119+ public changePin = async (
120+ req : Request ,
121+ res : Response ,
122+ next : NextFunction
123+ ) => {
124+ try {
125+ const userId = req . session . user . id
126+ const { params, body } = await validate ( changePinSchema , req )
127+ const { cardId } = params
128+ const { cypher } = body
129+
130+ const result = await this . cardService . changePin ( userId , cardId , cypher )
131+ res . status ( 201 ) . json ( toSuccessResponse ( result ) )
132+ } catch ( error ) {
133+ next ( error )
134+ }
135+ }
100136}
0 commit comments