summaryrefslogtreecommitdiff
path: root/pages/shop/cart/remove.fnl
blob: d5e3531a91d0c11355f2a20e6957952d0f2cd694 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(local lib (require :lib))

(fn render [request db]
  (if (= request.method "POST")
    (let [order-id (lib.order-id request)]
      (if (and order-id request.body)
        (do
          (local body-values (lib.parse-values request.body))
          (_G.must
            (luna.db.exec
              db
              "DELETE FROM order_lines WHERE id = ? AND order_id = ?"
              [body-values.id order-id]))
          (values
            302
            {:Location (_G.must
                         (luna.http.decode-url
                           (or body-values.redirect-url "/shop")))}
            ""))
        (values 400 {} "bad body")))
    (values 404 {} "not found")))

{: render}