Skip to content

Instantly share code, notes, and snippets.

@yosukehasumi
Created January 28, 2020 20:00
Show Gist options
  • Save yosukehasumi/dfa6655a0937caf0fc947b49feeda664 to your computer and use it in GitHub Desktop.
Save yosukehasumi/dfa6655a0937caf0fc947b49feeda664 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
# GuestList.find(4)
# {
# guest_id: id,
# additional_guests: {
# '123': {
# name: 'New Name'
# }
# }
# }
# UPDATE PARENT
{
parent_guest_id: nil,
guest_id: 'guest_123',
column_id: 'name',
value: 'New Name'
}
{
parent_guest_id: nil,
guest_id: 'guest_123',
column_id: 'tags',
value: {
'1': {
tag_id: '1',
qty: 3
},
'2': {
tag_id: '2',
qty: 5
}
}
}
# UPDATE PLUS ONE
{
parent_guest_id: 'guest_123',
guest_id: 'plusone_abc',
column_id: 'name',
value: 'New Name'
}
{
parent_guest_id: 'guest_123',
guest_id: 'plusone_abc',
column_id: 'tags',
value: {
'1': {
tag_id: '1',
qty: 3
},
'2': {
tag_id: '2',
qty: 5
}
}
}
# ADD PARENT GUEST
{
parent_guest_id: nil,
guest_id: 'guest_123',
column_id: 'name',
value: 'New name',
created_at: 1_580_240_269_595 # only during creation
}
# ADD PLUS ONE GUEST
{
parent_guest_id: 'guest_123',
guest_id: 'plusone_abc',
column_id: 'name',
value: 'New name',
created_at: 1_580_240_269_595 # only during creation
}
# DELETE PARENT GUEST
{
parent_guest_id: nil,
guest_id: 'plusone_abc'
}
# DELETE PLUSONE GUEST
{
parent_guest_id: 'guest_123',
guest_id: 'plusone_abc'
}
@alexdunae
Copy link

alexdunae commented Jan 28, 2020

/** Second-precision timestamp with decimals for precision */
type DecimalTimestamp = number;

interface GuestTagRefs {
  [key: string]: {
    tag_id: string;
    quantity: number;
  };
}

interface StringColumnPayload {
  column_id: string;
  column_value: string;
}

interface TagColumnPayload {
  column_id: 'tags';
  column_value: GuestTagRefs;
}

/** Dictionary of columns to be updated */
interface GuestColumns {
  name?: string;
  email?: string;
  affiliation?: string;
  comments?: string;
  tags?: GuestTagRefs;
}

interface AddGuest {
  parent_guest_id: null;
  guest_id: string;
  created_at: DecimalTimestamp;
  columns?: GuestColumns;
}

interface AddPlusOne {
  parent_guest_id: string;
  guest_id: string;
  created_at: DecimalTimestamp;
  columns?: GuestColumns;
}

interface UpdateGuest {
  parent_guest_id: string | null;
  guest_id: string;
  columns?: GuestColumns;
}

interface UpdatePlusOne {
  parent_guest_id: string;
  guest_id: string;
  columns?: GuestColumns;
}

interface DeleteGuest {
  parent_guest_id: null;
  guest_id: string;
}

interface DeletePlusOne {
  parent_guest_id: string;
  guest_id: string;
}

interface RequestMeta {
  queued_at: DecimalTimestamp;
  /** client-generated UUID used to keep track of which actions each client has already processed */
  uuid: string;
}

export interface AddGuestRequest {
  type: 'guests/add';
  payload: AddGuest;
  meta: RequestMeta;
}

export interface AddPlusOneRequest {
  type: 'guests/addPlusOne';
  payload: AddPlusOne;
  meta: RequestMeta;
}
export interface UpdateGuestRequest {
  type: 'guests/update';
  payload: AddGuest;
  meta: RequestMeta;
}

export interface UpdatePlusOneRequest {
  type: 'guests/update';
  payload: AddPlusOne;
  meta: RequestMeta;
}

export interface DeleteGuestRequest {
  type: 'guests/delete';
  payload: DeleteGuest;
  meta: RequestMeta;
}

export interface DeletePlusOneRequest {
  type: 'guests/deletePlusOne';
  payload: DeleteGuest;
  meta: RequestMeta;
}

// const upd: AddGuest = {
//   parent_guest_id: null,
//   guest_id: 'guest_b',
//   columns: {
//     name: 'x'
//   }
// };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment