-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab69d2d
commit ed6b37e
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
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,36 @@ | ||
import { Request, Response, Router } from "express"; | ||
import { body } from "express-validator"; | ||
|
||
import { validateRequest } from "../middleware/request-validator"; | ||
import { getOrCreateIdentity } from "../service/contact"; | ||
import { handleError } from "../utils/custom-error"; | ||
import { Format } from "../utils/formatters"; | ||
import { logger } from ".."; | ||
|
||
const router = Router(); | ||
|
||
router.post( | ||
"/", | ||
body("email").if(body("phoneNumber").isEmpty()).exists().isString().trim(), | ||
body("phoneNumber").if(body("email").isEmpty()).exists().isString().trim(), | ||
validateRequest, | ||
async (req: Request, res: Response) => { | ||
try { | ||
const { email, phoneNumber } = req.body; | ||
const contacts = await getOrCreateIdentity(email, phoneNumber); | ||
|
||
res.status(200).json(Format.identity(contacts)); | ||
} catch (err: any) { | ||
console.log(err); | ||
logger.error(err); | ||
const { statusCode, code, message } = handleError(err); | ||
|
||
res.status(statusCode).json({ | ||
code, | ||
message, | ||
}); | ||
} | ||
} | ||
); | ||
|
||
export { router as ContactRouter }; |
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,12 @@ | ||
import { Router, Request, Response } from "express"; | ||
import { ContactRouter } from "./contacts"; | ||
|
||
const router = Router(); | ||
|
||
router.get("/hello", async (req: Request, res: Response) => { | ||
res.status(200).send("hello, ha bhai zinda hoon!"); | ||
}); | ||
|
||
router.use("/identity", ContactRouter); | ||
|
||
export default router; |