Skip to content

Commit

Permalink
Change endpoint of relay
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Oct 26, 2023
1 parent 6551a05 commit 7deaa1a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
36 changes: 18 additions & 18 deletions packages/relay/src/routers/DefaultRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class DefaultRouter {

// 포인트를 이용하여 구매
this.app.post(
"/payPoint",
"/ledger/payPoint",
[
body("purchaseId").exists(),
body("amount").exists().custom(Validation.isAmount),
Expand All @@ -212,7 +212,7 @@ export class DefaultRouter {

// 토큰을 이용하여 구매할 때
this.app.post(
"/payToken",
"/ledger/payToken",
[
body("purchaseId").exists(),
body("amount").exists().custom(Validation.isAmount),
Expand All @@ -230,7 +230,7 @@ export class DefaultRouter {

// 포인트의 종류를 선택하는 기능
this.app.post(
"/changeToLoyaltyToken",
"/ledger/changeToLoyaltyToken",
[
body("account").exists().isEthereumAddress(),
body("signature")
Expand All @@ -242,7 +242,7 @@ export class DefaultRouter {

// 사용가능한 포인트로 전환
this.app.post(
"/changeToPayablePoint",
"/ledger/changeToPayablePoint",
[
body("phone")
.exists()
Expand Down Expand Up @@ -335,11 +335,11 @@ export class DefaultRouter {

/**
* 사용자 포인트 지불
* POST /payPoint
* POST /ledger/payPoint
* @private
*/
private async payPoint(req: express.Request, res: express.Response) {
logger.http(`POST /payPoint`);
logger.http(`POST /ledger/payPoint`);

const errors = validationResult(req);
if (!errors.isEmpty()) {
Expand Down Expand Up @@ -393,11 +393,11 @@ export class DefaultRouter {

/**
* 사용자 토큰 지불
* POST /payToken
* POST /ledger/payToken
* @private
*/
private async payToken(req: express.Request, res: express.Response) {
logger.http(`POST /payToken`);
logger.http(`POST /ledger/payToken`);

const errors = validationResult(req);
if (!errors.isEmpty()) {
Expand Down Expand Up @@ -437,7 +437,7 @@ export class DefaultRouter {
} catch (error: any) {
let message = ContractUtils.cacheEVMError(error as any);
if (message === "") message = "Failed pay token";
logger.error(`POST /payToken :`, message);
logger.error(`POST /ledger/payToken :`, message);
return res.status(200).json(
this.makeResponseData(500, undefined, {
message,
Expand All @@ -450,11 +450,11 @@ export class DefaultRouter {

/**
* 포인트의 종류를 선택한다.
* POST /changeToLoyaltyToken
* POST /ledger/changeToLoyaltyToken
* @private
*/
private async changeToLoyaltyToken(req: express.Request, res: express.Response) {
logger.http(`POST /changeToLoyaltyToken`);
logger.http(`POST /ledger/changeToLoyaltyToken`);

const errors = validationResult(req);
if (!errors.isEmpty()) {
Expand Down Expand Up @@ -488,8 +488,8 @@ export class DefaultRouter {
return res.status(200).json(this.makeResponseData(200, { txHash: tx.hash }));
} catch (error: any) {
let message = ContractUtils.cacheEVMError(error as any);
if (message === "") message = "Failed change point type";
logger.error(`POST /changeToLoyaltyToken :`, message);
if (message === "") message = "Failed change layalty type";
logger.error(`POST /ledger/changeToLoyaltyToken :`, message);
return res.status(200).json(
this.makeResponseData(500, undefined, {
message,
Expand All @@ -502,11 +502,11 @@ export class DefaultRouter {

/**
* 포인트의 종류를 선택한다.
* POST /changeToPayablePoint
* POST /ledger/changeToPayablePoint
* @private
*/
private async changeToPayablePoint(req: express.Request, res: express.Response) {
logger.http(`POST /changeToPayablePoint`);
logger.http(`POST /ledger/changeToPayablePoint`);

const errors = validationResult(req);
if (!errors.isEmpty()) {
Expand Down Expand Up @@ -537,12 +537,12 @@ export class DefaultRouter {
.connect(signerItem.signer)
.changeToPayablePoint(phone, account, signature);

logger.http(`TxHash(setLoyaltyType): `, tx.hash);
logger.http(`TxHash(changeToPayablePoint): `, tx.hash);
return res.status(200).json(this.makeResponseData(200, { txHash: tx.hash }));
} catch (error: any) {
let message = ContractUtils.cacheEVMError(error as any);
if (message === "") message = "Failed change point type";
logger.error(`POST /setLoyaltyType :`, message);
if (message === "") message = "Failed change to payable point";
logger.error(`POST /ledger/changeToPayablePoint :`, message);
return res.status(200).json(
this.makeResponseData(500, undefined, {
message,
Expand Down
28 changes: 14 additions & 14 deletions packages/relay/test/Endpoints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ describe("Test of Server", function () {
);
});

it("Failure test of the path /payPoint 'Insufficient balance'", async () => {
it("Failure test of the path /ledger/payPoint 'Insufficient balance'", async () => {
const over_purchaseAmount = Amount.make(90_000_000, 18).value;
const nonce = await ledgerContract.nonceOf(users[purchase.userIndex].address);
const signature = await ContractUtils.signPayment(
Expand All @@ -438,7 +438,7 @@ describe("Test of Server", function () {
shop.shopId,
nonce
);
const uri = URI(serverURL).directory("payPoint");
const uri = URI(serverURL).directory("ledger/payPoint");
const url = uri.toString();
const response = await client.post(url, {
purchaseId: purchase.purchaseId,
Expand All @@ -453,7 +453,7 @@ describe("Test of Server", function () {
assert.ok(response.data.error.message === "Insufficient balance");
});

it("Failure test of the path /payPoint 'Invalid signature'", async () => {
it("Failure test of the path /ledger/payPoint 'Invalid signature'", async () => {
const purchaseAmount = Amount.make(purchase.amount, 18).value;
const nonce = await ledgerContract.nonceOf(users[0].address);
const signature = await ContractUtils.signPayment(
Expand All @@ -464,7 +464,7 @@ describe("Test of Server", function () {
shop.shopId,
nonce
);
const uri = URI(serverURL).directory("payPoint");
const uri = URI(serverURL).directory("ledger/payPoint");
const url = uri.toString();
const response = await client.post(url, {
purchaseId: purchase.purchaseId,
Expand All @@ -479,7 +479,7 @@ describe("Test of Server", function () {
assert.ok(response.data.error.message === "Signature is not valid.");
});

it("Success Test of the path /payPoint", async () => {
it("Success Test of the path /ledger/payPoint", async () => {
const purchaseAmount = Amount.make(purchase.amount, 18).value;
const nonce = await ledgerContract.nonceOf(users[0].address);
const signature = await ContractUtils.signPayment(
Expand All @@ -490,7 +490,7 @@ describe("Test of Server", function () {
shop.shopId,
nonce
);
const uri = URI(serverURL).directory("payPoint");
const uri = URI(serverURL).directory("ledger/payPoint");
const url = uri.toString();
const response = await client.post(url, {
purchaseId: purchase.purchaseId,
Expand All @@ -508,7 +508,7 @@ describe("Test of Server", function () {
assert.ok(response.data.data.txHash !== undefined);
});

it("Failure test of the path /payToken 'Insufficient balance'", async () => {
it("Failure test of the path /ledger/payToken 'Insufficient balance'", async () => {
const over_purchaseAmount = Amount.make(90_000_000, 18).value;
const nonce = await ledgerContract.nonceOf(users[0].address);
const signature = await ContractUtils.signPayment(
Expand All @@ -519,7 +519,7 @@ describe("Test of Server", function () {
shop.shopId,
nonce
);
const uri = URI(serverURL).directory("payToken");
const uri = URI(serverURL).directory("ledger/payToken");
const url = uri.toString();
const response = await client.post(url, {
purchaseId: purchase.purchaseId,
Expand All @@ -534,7 +534,7 @@ describe("Test of Server", function () {
assert.ok(response.data.error.message === "Insufficient balance");
});

it("Failure test of the path /payToken 'Invalid signature'", async () => {
it("Failure test of the path /ledger/payToken 'Invalid signature'", async () => {
const purchaseAmount = Amount.make(purchase.amount, 18).value;
const nonce = await ledgerContract.nonceOf(users[0].address);
const signature = await ContractUtils.signPayment(
Expand All @@ -545,7 +545,7 @@ describe("Test of Server", function () {
shop.shopId,
nonce
);
const uri = URI(serverURL).directory("payToken");
const uri = URI(serverURL).directory("ledger/payToken");
const url = uri.toString();
const response = await client.post(url, {
purchaseId: purchase.purchaseId,
Expand All @@ -560,7 +560,7 @@ describe("Test of Server", function () {
assert.ok(response.data.error.message === "Signature is not valid.");
});

it("Success Test of the path /payToken", async () => {
it("Success Test of the path /ledger/payToken", async () => {
const purchaseAmount = Amount.make(purchase.amount, 18).value;
const nonce = await ledgerContract.nonceOf(users[0].address);
const signature = await ContractUtils.signPayment(
Expand All @@ -571,7 +571,7 @@ describe("Test of Server", function () {
shop.shopId,
nonce
);
const uri = URI(serverURL).directory("payToken");
const uri = URI(serverURL).directory("ledger/payToken");
const url = uri.toString();
const response = await client.post(url, {
purchaseId: purchase.purchaseId,
Expand Down Expand Up @@ -599,7 +599,7 @@ describe("Test of Server", function () {
const userIndex = 0;
const nonce = await ledgerContract.nonceOf(users[userIndex].address);
const signature = await ContractUtils.signLoyaltyType(users[userIndex], nonce);
const uri = URI(serverURL).directory("changeToLoyaltyToken");
const uri = URI(serverURL).directory("ledger/changeToLoyaltyToken");
const url = uri.toString();
const response = await client.post(url, {
account: users[userIndex].address,
Expand Down Expand Up @@ -776,7 +776,7 @@ describe("Test of Server", function () {
nonce
);

const uri = URI(serverURL).directory("changeToPayablePoint");
const uri = URI(serverURL).directory("ledger/changeToPayablePoint");
const url = uri.toString();
const response = await client.post(url, {
phone: phoneHash,
Expand Down

0 comments on commit 7deaa1a

Please sign in to comment.