Sign inSign up

plazaar/postgres

By plazaar

•Updated over 7 years ago

plazaar/postgres

Image
0

2.1K

plazaar/postgres repository overview

⁠Mall-X

ssh -R lagofrontendapi.serveo.net:80:localhost:3002 serveo.net

Mall-X is a multi purpose on-promise gamification system written in node.js and go.

Table of content

⁠Data model

Data Model

⁠Sample stack scripts

Stack scripts get the delivery passed in the context. This is where the script can save it's state.

⁠Sample director scripts

⁠DELIVERY_DISMISSED / DELIVERY_RETURNED

This script makes sure that a new delivery is scheduled whenever a delivery has been dismissed or succeeded. It uses a scheduling, so for the time beweeen dismissal and the delivery of a new stack we don't have a delivery ready.

import { director, DELIVERY_DISMISSED, DELIVERY_SUBMITTED } from 'mallx-handler'

director.register([DELIVERY_DISMISSED, DELIVERY_SUBMITTED], 
  ({ actions, context, selector }) => {
    return actions.later(context.tenant.tags.stackTimeout,
      actions.deliverRandomStack({ 
        customers: selector.customers.byId(types.Customer, context.customer.id)
      })
    );
  }
);
⁠DELIVERY_DISMISSED / DELIVERY_RETURNED

This version delivers a random stack as soon as the previous one has been dismissed or succeeded. It sets the validFrom time to a point in the future. This way the card can be read but can not be succeeded before.

import { director, DELIVERY_DISMISSED, DELIVERY_RETURNED } from 'mallx-handler'

director.register([DELIVERY_DISMISSED, DELIVERY_RETURNED], 
  ({ actions, context, selector, moment }) => actions.deliverRandomStack({
    customers: selector.customers.byId(context.customer.id),
    validFrom: moment().add(10, 'minutes'),
  })
);
⁠HOUR_PASSED

This script spreads deliveries over the next 60 minutes every hour of the day. On every spread it selects 5 random customers and delivers a stack by it's ID.

import { director, HOUR_PASSED } from 'mallx-handler'

director.register([HOUR_PASSED], ({ types, selector, actions, moment }) => actions.spread({
  amount: 5,
  beginning: moment(),
  ending: moment().add(1, 'hour'),
  strategy: actions.spread.strategies.even(),
}, actions.deliverStacks({
  customers: selector.customers.sample(5, selector.strategies.random()),
  stacks: selector.stacks.byId('12312-213123-123123'),
}))));
⁠HOUR_PASSED

This version of the previous handler uses a shortcut on the spread syntax.

import { director, HOUR_PASSED } from 'mallx-handler'

director.register([HOUR_PASSED], ({ types, selector, actions, moment, spread }) => 
  actions.spread(12).over(1, 'hour').evenly().forEach(actions.deliverStacks({
    customers: selector.customers.sample(5, selector.strategies.random()),
    stacks: selector.stacks.byId('12312-213123-123123'),
  }))
);
⁠DAY_PASSED

This script delivers a stack 23 times for each day before christmas.

import { director, DAY_PASSED } from 'mallx-handler'

director.register([DAY_PASSED], ({ types, selector, actions, moment, spread, filter }) => 
  actions.within(moment(2018, 11, 29), moment(2018, 11, 30)).do(
    and([
      actions.spread(23).over(23, 'days').from(moment('01-12-2018')).evenly().hour(9).forEach(actions.deliverStacks({
        customers: selector.customers.all().activeWithin(1, 'year'),
        stacks: selector.stacks.byId('12312-213123-123123'),
      })),
      actions.schedule().once().month(12).day(24).hour(9).do(actions.deliverStacks({
        customers: selector.customers.all().activeWithin(1, 'year'),
        stacks: selector.stacks.byId('12312-213123-123123'),
      }))
    ])
  )
);
⁠DELIVERY_RETURNED

This script tags customers that have answered yes to our christmas contest.

director.register([DELIVERY_RETURNED], ({ types, selector, actions, moment, spread }) => 
  actions.select(
    selector.deliveries.withStack(selector.stack.byId('12312-213123-123123'))),
    selector.deliveries.withTag(selector.tag.byName('answers').byValue(selector.json.key('join-contest').value('yes'))),
  ).forEach(() =>
    actions.tagCustomers({
      customers: selector.customers.byId(context.customer.id),
      tags: {
        'christmas-action-2018-joined': true,
      },
    })
  );
);

Tag summary

Content type

Image

Digest

Size

81.1 MB

Last updated

over 7 years ago

docker pull plazaar/postgres