From 6ce83828fad910b6295b9c62dc431cd6477767ef Mon Sep 17 00:00:00 2001 From: Shahar Solomianik Date: Tue, 20 Aug 2019 12:40:51 +0300 Subject: [PATCH 1/4] added submitData option on the title field in offers --- scripts/src/admin/services.ts | 19 +++++++++++++++++-- scripts/src/admin/wrapper.html | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/scripts/src/admin/services.ts b/scripts/src/admin/services.ts index 8bad001f..cd37a38d 100644 --- a/scripts/src/admin/services.ts +++ b/scripts/src/admin/services.ts @@ -1,7 +1,7 @@ import { Request, RequestHandler, Response } from "express"; import { Application, ApplicationConfig, AppOffer } from "../models/applications"; -import { Cap, Offer, OfferContent, PollAnswer } from "../models/offers"; +import { Cap, Offer, OfferContent, PollAnswer, OfferMeta } from "../models/offers"; import { GradualMigrationUser, User, WalletApplication, Wallet as UserWallets } from "../models/users"; import { OpenOrderStatus, Order, OrderContext } from "../models/orders"; import { IdPrefix, isNothing } from "../utils/utils"; @@ -107,6 +107,10 @@ async function offerToHtml(offer: Offer, appOffer?: AppOffer): Promise { return ``; } + function getTitleElement() { + return ``; + } + const offerContent = ((await OfferContent.get(offer.id)) || { contentType: "poll", content: "{}" }); const offerIdHtml = offerContent.contentType === "coupon" ? offer.id : `${ offer.id }`; return ` @@ -116,7 +120,7 @@ async function offerToHtml(offer: Offer, appOffer?: AppOffer): Promise { ${ offer.name } ${ offer.type } ${ getAmountElement() } -${ offer.meta.title } +${ getTitleElement() } ${ offer.meta.description } ${ total() } @@ -520,12 +524,18 @@ export async function changeAppOffer(body: { cap: Cap }, params: { app_id: strin export type ChangeOfferData = Partial & { content: string; + is_meta?: boolean; + [key: string]: string | boolean | undefined; }; function isInOffer(key: string, offer: Offer): key is keyof Offer { return key in offer; } +function isInMeta(key: string, offer: Offer): key is keyof Offer { + return key in offer.meta; +} + export async function changeOffer(body: ChangeOfferData, params: { offer_id: string }, query: any): Promise { const offer = await Offer.findOneById(params.offer_id); console.log("changeOffer:", offer, "with:", body); @@ -545,6 +555,11 @@ export async function changeOffer(body: ChangeOfferData, params: { offer_id: str offer[key] = body[key]!; console.log("updating:", key, "with:", body[key]); } + // if (body.is_meta && isInMeta(key, offer)){ + if (body.is_meta && key === "title"){ + offer.meta.title = body[key]!.toString(); + console.log("updating meta.title to ", body[key]); + } }); await offer.save(); diff --git a/scripts/src/admin/wrapper.html b/scripts/src/admin/wrapper.html index 2febf7de..d6566cb8 100644 --- a/scripts/src/admin/wrapper.html +++ b/scripts/src/admin/wrapper.html @@ -504,6 +504,7 @@

Marketplace Admin

cb(); }; } + From 1b0f083c26c4f0621fb0f15df2dfbb43ae93ef54 Mon Sep 17 00:00:00 2001 From: Shahar Solomianik Date: Tue, 20 Aug 2019 12:48:18 +0300 Subject: [PATCH 2/4] added indexSignature to offerMera --- scripts/src/models/offers.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/src/models/offers.ts b/scripts/src/models/offers.ts index 1f79f41d..258122e3 100644 --- a/scripts/src/models/offers.ts +++ b/scripts/src/models/offers.ts @@ -22,6 +22,7 @@ export type OfferMeta = { image: string; description: string; order_meta: OrderMeta; + [key: string]: string | OrderMeta; }; export type Cap = { From 68aecca27d033151bebd85a6862935f80ad9bb5c Mon Sep 17 00:00:00 2001 From: Shahar Solomianik Date: Tue, 20 Aug 2019 12:48:41 +0300 Subject: [PATCH 3/4] generalize and allow changing any meta field, not just the title. --- scripts/src/admin/services.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/src/admin/services.ts b/scripts/src/admin/services.ts index cd37a38d..b560d37a 100644 --- a/scripts/src/admin/services.ts +++ b/scripts/src/admin/services.ts @@ -555,10 +555,9 @@ export async function changeOffer(body: ChangeOfferData, params: { offer_id: str offer[key] = body[key]!; console.log("updating:", key, "with:", body[key]); } - // if (body.is_meta && isInMeta(key, offer)){ - if (body.is_meta && key === "title"){ - offer.meta.title = body[key]!.toString(); - console.log("updating meta.title to ", body[key]); + if (body.is_meta && isInMeta(key, offer)){ + offer.meta[key] = body[key]!.toString(); + console.log("updating meta:", key, "with:", body[key]); } }); From 089e735ca42d4aa7eb7242aff7f7c8f14f149421 Mon Sep 17 00:00:00 2001 From: Shahar Solomianik Date: Tue, 20 Aug 2019 12:50:30 +0300 Subject: [PATCH 4/4] removed empty line added accidentaly --- scripts/src/admin/wrapper.html | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/src/admin/wrapper.html b/scripts/src/admin/wrapper.html index d6566cb8..2febf7de 100644 --- a/scripts/src/admin/wrapper.html +++ b/scripts/src/admin/wrapper.html @@ -504,7 +504,6 @@

Marketplace Admin

cb(); }; } -