diff --git a/api/build.hxml b/api/build.hxml index 01413e3..f3bd0ac 100644 --- a/api/build.hxml +++ b/api/build.hxml @@ -4,6 +4,7 @@ -lib tink_json -lib tink_sql -lib hxnodejs +-D await_catch_none -cp src --main Server -js build/out.js diff --git a/api/src/Server.hx b/api/src/Server.hx index cc3ea8b..c5b6b1c 100644 --- a/api/src/Server.hx +++ b/api/src/Server.hx @@ -63,10 +63,10 @@ class Root { public function user() return new User(); - @:sub('/projects') - @:produces('application/json') - public function projects() - return new Projects(); + // @:sub('/projects') + // @:produces('application/json') + // public function projects() + // return new Projects(); @:get('/hello') @:produces('application/json') diff --git a/api/src/controller/User.hx b/api/src/controller/User.hx index d4d3392..14aa8c6 100644 --- a/api/src/controller/User.hx +++ b/api/src/controller/User.hx @@ -5,6 +5,8 @@ import Utils; import db.Db; import model.MUser; +using tink.CoreApi; + class User{ public function new() {} @@ -20,24 +22,25 @@ class User{ } @:get('/registerDummyUser') - @:produces('text/plain') + @:produces('application/json') public function registerdummyuser(){ - //@await var db = new Db('daba2', driver); - db.MUser.create().next(function(){ - db.MUser.insertOne({ + // var failed:tink.core.Next> = null + @await var result = db.MUser.create().next( + return db.MUser.insertOne({ id: cast null, name: 'Alice', email: 'alice@example.com', password: 'jew' - }).next(function(){ - db.MUser.select({name: MUser.name, email: MUser.email}).where(MUser.email == 'alice@example.com').first().next(function(row) { - trace(row.name); - // return "$row"; - }); - }); + })); + result.handle(function(outcome) { + switch outcome { + case Success(data): return data; + case Failure(e): + trace("failure: "+e); + return null; + } }); - return "success"; // @await var three = ; // trace(@await one); // trace(@await two); diff --git a/api/src/db/Db.hx b/api/src/db/Db.hx index 9432931..f0bd131 100644 --- a/api/src/db/Db.hx +++ b/api/src/db/Db.hx @@ -13,5 +13,5 @@ typedef Db = tink.sql.Database; @:tables(MUser) interface Def extends tink.sql.DatabaseDefinition { //@:procedure var func:Int->{x:Int, point:tink.s2d.Point}; - //@:table('user') var UserAlias:User; + @:table('user') var UserAlias:MUser; } \ No newline at end of file