Skip to content

Commit

Permalink
Update endpoint /v1/mobile/exists/
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Dec 16, 2024
1 parent 82cb8ce commit d396e14
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions packages/relay/src/routers/ETCRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ export class ETCRouter {
this.mobile_info.bind(this)
);

this.app.get(
"/v1/mobile/exists/:account",
[param("account").exists().trim().isEthereumAddress(), query("type").exists()],
this.app.post(
"/v1/mobile/exists",
[body("account").exists().trim().isEthereumAddress(), body("token").exists()],
this.mobile_exists.bind(this)
);
}
Expand Down Expand Up @@ -236,23 +236,27 @@ export class ETCRouter {
}

/**
* GET /v1/mobile/exists
* POST /v1/mobile/exists
* @private
*/
private async mobile_exists(req: express.Request, res: express.Response) {
logger.http(`GET /v1/mobile/exists ${req.ip}:${JSON.stringify(req.params)}`);
logger.http(`POST /v1/mobile/exists ${req.ip}:${JSON.stringify(req.body)}`);

const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(200).json(ResponseMessage.getErrorMessage("2001", { validation: errors.array() }));
}

try {
const account: string = String(req.params.account).trim();
const type: number = Number(req.query.type);
const shopId = req.query.shopId === undefined ? HashZero : String(req.query.shopId).trim();
const account: string = String(req.body.account).trim();
const type = req.body.type === undefined ? 0 : Number(req.body.type);
const shopId = req.body.shopId === undefined ? HashZero : String(req.body.shopId).trim();
const token: string = String(req.body.token).trim();
const mobileData = await this.storage.getMobile(account, type, shopId);
const exists = mobileData !== undefined && mobileData.account.toLowerCase() === account.toLowerCase();
const exists =
mobileData !== undefined &&
mobileData.account.toLowerCase() === account.toLowerCase() &&
mobileData.token === token;

this.metrics.add("success", 1);
return res.status(200).json(
Expand Down

0 comments on commit d396e14

Please sign in to comment.