summaryrefslogtreecommitdiff
path: root/pages/shop/order/state.fnl
blob: 1ff1ca97c3ee5e61f9c37936e13c9b37d534e576 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(local lib (require :lib))
(local shop (require :shop))

(fn render [request db authenticated?]
  (if (and (= request.method "POST") authenticated?)
    (let [vals (lib.parse-values request.body)]
      (if (and vals vals.id
               vals.state (or (= vals.state "done")
                              (= vals.state "canceled")))
        (do
          (if (= "done" vals.state)
            (shop.finish-order db vals.id)
            (shop.cancel-order db vals.id))
          (values 302 {:Location "/shop/order/list"} ""))
        (values 400 {} "bad body")))
    (values 404 {} "not found")))

{: render}