-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added controllers for handling sms sending and code verification. References #61.
- Loading branch information
1 parent
b528447
commit 75c6e59
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
server/services/user-service/src/interfaces/controllers/index.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,29 @@ | ||
import notFound from '../../../../core/interfaces/controllers/not-found'; | ||
import buildPostAuthenticateSendSms from './post-authenticate-send-sms-token'; | ||
import buildPostAuthenticateVerifyToken | ||
from './post-authenticate-verify-sms-token'; | ||
import { | ||
sendAuthenticationSmsCode, | ||
verifyAuthenticationSmsCode, | ||
} from '../../usecases'; | ||
|
||
const postAuthenticateSendSms = buildPostAuthenticateSendSms({ | ||
sendAuthenticationSmsCode, | ||
}); | ||
|
||
const postAuthenticateVerifyToken = buildPostAuthenticateVerifyToken({ | ||
verifyAuthenticationSmsCode, | ||
}); | ||
|
||
const orderController = Object.freeze({ | ||
postAuthenticateSendSms, | ||
postAuthenticateVerifyToken, | ||
notFound, | ||
}); | ||
|
||
export default orderController; | ||
export { | ||
postAuthenticateSendSms, | ||
postAuthenticateVerifyToken, | ||
notFound, | ||
}; |
40 changes: 40 additions & 0 deletions
40
server/services/user-service/src/interfaces/controllers/post-authenticate-send-sms-token.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,40 @@ | ||
import {HttpRequest} from '../../../../core/@types/global'; | ||
|
||
/** | ||
* Express controller for handling of POST "users/authenticate/send-sms-token". | ||
* | ||
* @export | ||
* @param {{sendAuthenticationSmsCode: Function}} { | ||
* sendAuthenticationSmsCode | ||
* } - dependency injection | ||
* @return {Function} - post users send sms token controller builder function | ||
*/ | ||
export default function buildPostAuthenticateSendSms({ | ||
sendAuthenticationSmsCode, | ||
}: {sendAuthenticationSmsCode: Function}): Function { | ||
return async function postAuthenticateSendSms(httpRequest: HttpRequest) { | ||
try { | ||
const phoneNumber = httpRequest.body['phoneNumber']; | ||
const verificationInstance = await sendAuthenticationSmsCode( | ||
phoneNumber, | ||
); | ||
return { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
statusCode: 201, | ||
body: {verificationInstance}, | ||
}; | ||
} catch (e) { | ||
return { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
statusCode: 400, | ||
body: { | ||
error: e.message, | ||
}, | ||
}; | ||
} | ||
}; | ||
} |
40 changes: 40 additions & 0 deletions
40
...er/services/user-service/src/interfaces/controllers/post-authenticate-verify-sms-token.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,40 @@ | ||
import {HttpRequest} from '../../../../core/@types/global'; | ||
|
||
/** | ||
* Express controller for handling of POST "users/authenticate/verify-sms-token" | ||
* | ||
* @export | ||
* @param {{verifyAuthenticationSmsCode: Function}} { | ||
* verifyAuthenticationSmsCode | ||
* } - dependency injection | ||
* @return {Function} - post users send sms token controller builder function | ||
*/ | ||
export default function buildPostAuthenticateVerifyToken({ | ||
verifyAuthenticationSmsCode, | ||
}: {verifyAuthenticationSmsCode: Function}): Function { | ||
return async function postAuthenticateVerifyToken(httpRequest: HttpRequest) { | ||
try { | ||
const verificationInfo = httpRequest.body; | ||
const verificationInstance = await verifyAuthenticationSmsCode( | ||
verificationInfo, | ||
); | ||
return { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
statusCode: 201, | ||
body: {verificationInstance}, | ||
}; | ||
} catch (e) { | ||
return { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
statusCode: 400, | ||
body: { | ||
error: e.message, | ||
}, | ||
}; | ||
} | ||
}; | ||
} |