From 2b4881bbf0d4e5da2e781c09e03251b92cce59c3 Mon Sep 17 00:00:00 2001 From: Michael Kim Date: Fri, 29 Nov 2024 13:56:14 +0900 Subject: [PATCH] Push message for multiple shopId in wallet address --- packages/relay/src/routers/ETCRouter.ts | 14 +++++++++++--- packages/relay/src/routers/PaymentRouter.ts | 2 +- packages/relay/src/routers/ShopRouter.ts | 4 ++-- packages/relay/src/storage/RelayStorage.ts | 8 ++++++-- packages/relay/src/storage/mapper/mobile.xml | 8 +++++--- packages/relay/src/storage/mapper/table.xml | 3 ++- packages/relay/src/types/index.ts | 1 + packages/relay/test/Payment.test.ts | 7 +++++++ packages/relay/test/PaymentV2.test.ts | 1 + 9 files changed, 36 insertions(+), 12 deletions(-) diff --git a/packages/relay/src/routers/ETCRouter.ts b/packages/relay/src/routers/ETCRouter.ts index f8743f80..ef867240 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 896be055..6399b65c 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 7087cef5..a33def1b 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 5936c9a8..5f405f50 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 64efa03b..0f7cba86 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 1c92a441..899b5172 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 68371b6d..6730cd9a 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 92496055..1899d7e4 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 53d70c8c..98cc5bcb 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",