diff --git a/packages/relay/src/routers/ETCRouter.ts b/packages/relay/src/routers/ETCRouter.ts index f8743f8..ef86724 100644 --- a/packages/relay/src/routers/ETCRouter.ts +++ b/packages/relay/src/routers/ETCRouter.ts @@ -12,6 +12,8 @@ import { ResponseMessage } from "../utils/Errors"; import express from "express"; import { body, param, query, validationResult } from "express-validator"; +import { HashZero } from "@ethersproject/constants"; + export class ETCRouter { private web_service: WebService; private readonly config: Config; @@ -118,6 +120,7 @@ export class ETCRouter { try { 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 language: string = String(req.body.language).trim(); const os: string = String(req.body.os).trim(); @@ -130,6 +133,7 @@ export class ETCRouter { const item = { account, type, + shopId, token, language, os, @@ -167,11 +171,12 @@ export class ETCRouter { try { const account: string = String(req.body.account).trim(); const type: number = Number(req.body.type); + const shopId = req.body.shopId === undefined ? HashZero : String(req.body.shopId).trim(); const title: string = String(req.body.title).trim(); const contents: string = String(req.body.contents).trim(); const contentType: string = String(req.body.contentType).trim(); - const mobileData = await this.storage.getMobile(account, type); + const mobileData = await this.storage.getMobile(account, type, shopId); if (mobileData !== undefined) { await this.sender.send(mobileData.token, title, contents, { type: contentType }); } @@ -204,8 +209,9 @@ export class ETCRouter { 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 mobileData = await this.storage.getMobile(account, type); + const mobileData = await this.storage.getMobile(account, type, shopId); if (mobileData === undefined) { return res.status(200).json(ResponseMessage.getErrorMessage("2008")); } @@ -215,6 +221,7 @@ export class ETCRouter { this.makeResponseData(0, { account: mobileData.account, type: mobileData.type, + shopId: mobileData.shopId, token: mobileData.token, language: mobileData.language, os: mobileData.os, @@ -243,7 +250,8 @@ export class ETCRouter { try { const account: string = String(req.params.account).trim(); const type: number = Number(req.query.type); - const mobileData = await this.storage.getMobile(account, type); + const shopId = req.query.shopId === undefined ? HashZero : String(req.query.shopId).trim(); + const mobileData = await this.storage.getMobile(account, type, shopId); const exists = mobileData !== undefined && mobileData.account.toLowerCase() === account.toLowerCase(); this.metrics.add("success", 1); diff --git a/packages/relay/src/routers/PaymentRouter.ts b/packages/relay/src/routers/PaymentRouter.ts index 896be05..6399b65 100644 --- a/packages/relay/src/routers/PaymentRouter.ts +++ b/packages/relay/src/routers/PaymentRouter.ts @@ -1354,7 +1354,7 @@ export class PaymentRouter { ); } - const mobileData = await this.storage.getMobile(shopInfo.account, MobileType.SHOP_APP); + const mobileData = await this.storage.getMobile(shopInfo.account, MobileType.SHOP_APP, shopInfo.shopId); if (!this.config.relay.testMode && mobileData === undefined) { return res.status(200).json(ResponseMessage.getErrorMessage("2005")); diff --git a/packages/relay/src/routers/ShopRouter.ts b/packages/relay/src/routers/ShopRouter.ts index 7087cef..a33def1 100644 --- a/packages/relay/src/routers/ShopRouter.ts +++ b/packages/relay/src/routers/ShopRouter.ts @@ -703,7 +703,7 @@ export class ShopRouter { ); } - const mobileData = await this.storage.getMobile(item.account, MobileType.SHOP_APP); + const mobileData = await this.storage.getMobile(item.account, MobileType.SHOP_APP, item.shopId); if (!this.config.relay.testMode && mobileData === undefined) { return res.status(200).json(ResponseMessage.getErrorMessage("2005")); @@ -992,7 +992,7 @@ export class ShopRouter { } /// 사용자에게 푸쉬 메세지 발송 - const mobileData = await this.storage.getMobile(item.account, MobileType.SHOP_APP); + const mobileData = await this.storage.getMobile(item.account, MobileType.SHOP_APP, item.shopId); if (!this.config.relay.testMode && mobileData === undefined) { return res.status(200).json(ResponseMessage.getErrorMessage("2005")); diff --git a/packages/relay/src/storage/RelayStorage.ts b/packages/relay/src/storage/RelayStorage.ts index 5936c9a..5f405f5 100644 --- a/packages/relay/src/storage/RelayStorage.ts +++ b/packages/relay/src/storage/RelayStorage.ts @@ -22,6 +22,8 @@ import { } from "../types"; import { ContractUtils } from "../utils/ContractUtils"; +import { HashZero } from "@ethersproject/constants"; + import * as hre from "hardhat"; /** @@ -664,6 +666,7 @@ export class RelayStorage extends Storage { this.queryForMapper("mobile", "postMobile", { account: item.account, type: item.type, + shopId: item.shopId, token: item.token, language: item.language, os: item.os, @@ -678,15 +681,16 @@ export class RelayStorage extends Storage { }); } - public getMobile(account: string, type: number): Promise { + public getMobile(account: string, type: number, shopId: string = HashZero): Promise { return new Promise(async (resolve, reject) => { - this.queryForMapper("mobile", "getMobile", { account, type }) + this.queryForMapper("mobile", "getMobile", { account, type, shopId }) .then((result) => { if (result.rows.length > 0) { const m = result.rows[0]; return resolve({ account: m.account, type: m.type, + shopId: m.shopId, token: m.token, language: m.language, os: m.os, diff --git a/packages/relay/src/storage/mapper/mobile.xml b/packages/relay/src/storage/mapper/mobile.xml index 64efa03..0f7cba8 100644 --- a/packages/relay/src/storage/mapper/mobile.xml +++ b/packages/relay/src/storage/mapper/mobile.xml @@ -7,6 +7,7 @@ ( "account" , "type" , + "shopId" , "token" , "language" , "os" @@ -15,18 +16,19 @@ ( #{account} , #{type} , + #{shopId} , #{token} , #{language} , #{os} ) - ON CONFLICT ("account", "type") + ON CONFLICT ("account", "type", "shopId") DO UPDATE - SET "token" = #{token}, + SET "token" = #{token}, "language" = #{language}, "os" = #{os}; diff --git a/packages/relay/src/storage/mapper/table.xml b/packages/relay/src/storage/mapper/table.xml index 1c92a44..899b517 100644 --- a/packages/relay/src/storage/mapper/table.xml +++ b/packages/relay/src/storage/mapper/table.xml @@ -57,10 +57,11 @@ ( "account" VARCHAR(42) NOT NULL, "type" INTEGER DEFAULT 0, + "shopId" VARCHAR(66) DEFAULT '0x0000000000000000000000000000000000000000000000000000000000000000', "token" VARCHAR(50) NOT NULL, "language" VARCHAR(3) NOT NULL, "os" VARCHAR(12) NOT NULL, - PRIMARY KEY ("account", "type") + PRIMARY KEY ("account", "type", "shopId") ); diff --git a/packages/relay/src/types/index.ts b/packages/relay/src/types/index.ts index 68371b6..6730cd9 100644 --- a/packages/relay/src/types/index.ts +++ b/packages/relay/src/types/index.ts @@ -190,6 +190,7 @@ export enum MobileType { export interface MobileData { account: string; type: MobileType; + shopId: string; token: string; language: string; os: string; diff --git a/packages/relay/test/Payment.test.ts b/packages/relay/test/Payment.test.ts index 9249605..1899d7e 100644 --- a/packages/relay/test/Payment.test.ts +++ b/packages/relay/test/Payment.test.ts @@ -1518,6 +1518,12 @@ describe("Test of Server", function () { config.relay.certifiers = deployments.accounts.certifiers.map((m) => m.privateKey); config.relay.callbackEndpoint = "http://127.0.0.1:3400/callback"; config.relay.relayEndpoint = `http://127.0.0.1:${config.server.port}`; + + client = new TestClient({ + headers: { + Authorization: config.relay.accessKey, + }, + }); }); before("Create TestServer", async () => { @@ -1585,6 +1591,7 @@ describe("Test of Server", function () { const param = { account: wallet.address, type: 1, + shopId: shopData[purchaseOfLoyalty.shopIndex].shopId, token: "12345678901234567890123456789012345678901234567890", language: "kr", os: "iOS", diff --git a/packages/relay/test/PaymentV2.test.ts b/packages/relay/test/PaymentV2.test.ts index 53d70c8..98cc5bc 100644 --- a/packages/relay/test/PaymentV2.test.ts +++ b/packages/relay/test/PaymentV2.test.ts @@ -1646,6 +1646,7 @@ describe("Test of Server", function () { const param = { account: wallet.address, type: 1, + shopId: shopData[purchaseOfLoyalty.shopIndex].shopId, token: "12345678901234567890123456789012345678901234567890", language: "kr", os: "iOS",