prravda / discord-hotdeal-keyword-typescript

A discord bot node.js with typescript to manage a hot deal notification keywords
0 stars 0 forks source link

[ Keyword notification system ] Design events - `HotDealUpdated`, `NotificationCreated` #4

Closed prravda closed 1 year ago

prravda commented 1 year ago

Goal

prravda commented 1 year ago

Summery

prravda commented 1 year ago

Result

HotDealUpdated

interface HotDeal {
  id: number;
  title: string;
  link: string;
}

interface PpomppuHotDeal extends HotDeal {}

interface FmKoreaPopularHotDeal extends HotDeal {}

interface FmKoreaGeneralHotDeal extends HotDeal {
  seller: string;
  productPrice: string;
  shippingCharge: string;
  category: string;
}

// candidate 0
interface HotDealUpdated_MK1 {
  version: number;
  timestamp: Date;
  listOfHotDeal: (
    | PpomppuHotDeal
    | FmKoreaPopularHotDeal
    | FmKoreaGeneralHotDeal
  )[];
}

// candidate_1
interface HotDealUpdated_MK2 {
  version: number;
    sourceAndType: string;
  timestamp: Date;
  listOfHotDeal:
    | PpomppuHotDeal[]
    | FmKoreaPopularHotDeal[]
    | FmKoreaGeneralHotDeal[];
}

After considering, I choose the HotDealUpdated_MK2. The reason is simple. First, I send the list of hot deal various source and various interval. Second, the structure of them are slightly different. And last, If I send the multiple lists of hot deal, the content size of message become larger so I should avoid this scenario.

So, I will design this event like this

interface HotDealUpdated {
  version: number;
    sourceAndType: string;
  timestamp: Date;
  listOfHotDeal:
    | PpomppuHotDeal[]
    | FmKoreaPopularHotDeal[]
    | FmKoreaGeneralHotDeal[];
}

NotificationCreated

Goal of this event

Structure of this event

enum USER_CAME_FROM {
  DISCORD,
}

interface NotificationCreated {
  sourceAndType: string;
  hotDeal: PpomppuHotDeal | FmKoreaPopularHotDeal | FmKoreaGeneralHotDeal;
  userId: string;
  destination: USER_CAME_FROM;
}
prravda commented 1 year ago

I described these whole processes in notion