simplex/app.moon

45 lines
1.2 KiB
Plaintext
Raw Normal View History

2018-04-23 12:22:27 +00:00
import Application from require "lapis"
2018-04-23 12:02:59 +00:00
2018-04-23 12:46:07 +00:00
import APIKeys, Tasks from require "models"
2018-04-23 12:22:27 +00:00
import autoload, locate, registry from require "locator"
import settings from autoload "utility"
import main from autoload "layouts"
2018-04-23 12:22:27 +00:00
class Simplex extends Application
@before_filter =>
settings.load!
registry.before_filter(@)
layout: main
2018-04-23 12:22:27 +00:00
@include locate "users"
@include locate "api"
2018-04-25 03:55:12 +00:00
@include locate "docs"
2018-04-23 12:22:27 +00:00
2018-04-25 01:35:31 +00:00
handle_error: (err, trace) =>
if @original_request.route_name\find "api_"
2018-04-25 04:00:29 +00:00
-- return status: 500, json: { errors: {err}, :trace } -- NOTE trace should be saved and NOT returned to the user
return status: 500, json: { errors: {err} }
2018-04-25 01:35:31 +00:00
else
2018-04-25 04:00:29 +00:00
super err --, trace
2018-04-25 01:35:31 +00:00
2018-04-23 12:22:27 +00:00
[index: "/"]: =>
if @user
2018-05-02 00:24:43 +00:00
@keys = APIKeys\select "WHERE user_id = ? ORDER BY created_at ASC", @user.id
2018-05-02 01:46:58 +00:00
@tasks = Tasks\select "WHERE user_id = ? ORDER BY done, created_at ASC", @user.id
2018-04-23 12:22:27 +00:00
unless @keys and #@keys > 0
@keys = {APIKeys\create(@user)}
return render: "index.logged_in"
else
2018-04-25 05:02:41 +00:00
return render: "index.logged_out"
2018-04-23 13:06:56 +00:00
2018-04-23 13:08:09 +00:00
[console: "/console"]: =>
2018-04-23 13:09:47 +00:00
if @user and @user.admin
console = require "lapis.console"
return console.make(env: "all")(@)
2018-04-25 01:33:18 +00:00
else
return status: 404, "Not found."