diff --git a/scripts/src/admin/services.ts b/scripts/src/admin/services.ts index 8bad001f..b560d37a 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,10 @@ 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)){ + offer.meta[key] = body[key]!.toString(); + console.log("updating meta:", key, "with:", body[key]); + } }); await offer.save(); 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 = {