---
# System prepended metadata

title: Sisärinki loyalty program

---

# Sisärinki loyalty program 

#### Systems

Hygraph
Backend
Application
POS

## EARNING POINTS

```mermaid
sequenceDiagram
        participant app as Application
        participant cs as CodeService
        participant pos as POS
        participant rb as S3Receipts
        participant l as lamda
        participant rs as RewardService
        
        Note over app, pos: Normal transactions user<br />shows coupon or ID QR-code<br />and transactions end to sale
        
        pos->>rb: send receipt JSON
        Note over rb, rs: receipt triggers lambda and BE functions *2
        
        rect rgb(250,230,170)
            l->>rb: getReceipt
            rb->>l: "returns JSON"
            l->>rs: Save necessary data
        end
        
        
```

## USING POINTS

```mermaid
sequenceDiagram
        participant app as Application
        participant hg as Hygraph
        participant cs as CodeService
        participant pos as POS
        participant rb as S3Receipts
        participant l as lamda
        participant rs as RewardService
        
                
        app->>hg: query GetRewardCoupons()
        hg->>app: return rewardCoupons
        
        app->>rs: query GetUserRewardPoints()
        rs->>app: return rewardPoints
        
        app->>app: Filter rewards
        Note over app: User clicks reward
        app->>cs: send coupon data *1
        cs->>cs: Create OTP
        cs->>cs: Save rewardPointsValue
        cs->>app: return OTP
        app-->>pos: User shows QRcode to reader
        pos->>cs: Request data for OTP
        cs->>pos: return reward data <br /> (same as coupons)
        
        pos->>rb: send receipt JSON
        Note over rb, rs: receipt triggers lambda and BE functions *2
        
        rect rgb(250,230,170)
            l->>rb: getReceipt
            rb->>l: "returns JSON"
            l->>rs: Save necessary data
        end
        
        
```

### Receipt handling




#### GetRewards-query
Slightly modified GetCouponsByType() query 

```
added fields:

rewardLevel
connectedProducts {
      id
      productName
      productImage {
        url
      }
}
    
----

query GetCouponsByType() {
  coupons(
    where: { active: true, type: reward }
    orderBy: order_ASC
    locales: [fi, en]
    first: 100
  ) {
    couponId
    type
    title
    couponImage {
      url
    }
    longDescription {
      html
    }
    exceptions
    priceView
    singleUse
    posReply
    theme
    userRole
    rewardLevel
    connectedProducts {
      productId
      productName
      productImage {
        url
      }
    }
  }
}
```

#### send coupon data *1

Same fields as coupon with rewardLevel added

```
 Check code and copy
```