Skip to content

Commit

Permalink
ongoing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kanekotic committed Mar 30, 2019
1 parent 0422aea commit d79265b
Show file tree
Hide file tree
Showing 4 changed files with 432 additions and 13 deletions.
12 changes: 9 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@ import { Request, Response, Router } from 'express'
import { ActorSystem } from 'tarant'

const SyncController = (system: ActorSystem, config: any): Router => {
console.log(config.actorTypes)
const router: Router = Router()

router.get(`${config.paths.pull}/:id`, async (req: Request, res: Response) => {
console.log('get', req.params.id)
try {
const actor = (await system.actorFor(req.params.id)) as any
res.json(await actor.toJson())
console.log('get result', actor)
} catch (_) {
console.log('get error')
res.sendStatus(404)
}
})

router.post(`${config.paths.push}/:id`, async (req: Request, res: Response) => {
let actor
let actor: any
try {
actor = (await system.actorFor(req.params.id)) as any
actor = await system.actorFor(req.params.id)
} catch (_) {
actor = (await system.actorOf(config.actorTypes[req.body.type], [req.params.id])) as any
actor = await system.actorOf(config.actorTypes[req.body.type], [req.params.id])
}
console.log('here', actor, (actor as any).updateFrom)
actor.updateFrom(req.body)
console.log('here2')
res.sendStatus(200)
})

Expand Down
5 changes: 5 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"watch": ["lib"],
"ext": "ts",
"exec": "yarn build"
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"scripts": {
"prepare": "yarn build",
"build": "tsc",
"build:dev": "nodemon",
"format": "prettier --write \"**/*.ts\" && tslint -p tsconfig.json --fix lib/**/*.ts -t verbose",
"lint": "tslint -p tsconfig.json",
"test": "yarn format && yarn lint && jest test",
Expand Down Expand Up @@ -48,6 +49,7 @@
"coveralls": "3.0.2",
"faker": "4.1.0",
"jest": "23.6.0",
"nodemon": "1.18.10",
"prettier": "1.15.3",
"supertest": "3.3.0",
"ts-jest": "23.10.5",
Expand Down
Loading

0 comments on commit d79265b

Please sign in to comment.