-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kanekotic
committed
Dec 30, 2018
1 parent
ba4f6ab
commit 800b418
Showing
2 changed files
with
71 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
import { Router, Request, Response } from 'express' | ||
import { Request, Response, Router } from 'express' | ||
import { ActorSystem } from 'tarant' | ||
|
||
export default function SyncController(system: ActorSystem, config: any) { | ||
const SyncController = (system: ActorSystem, config: any): Router => { | ||
const router: Router = Router() | ||
|
||
router.get(`${config.paths.pull}/:id`, async (req: Request, res: Response) => { | ||
try { | ||
const actor = (await system.actorFor(req.params.id)) as any | ||
res.json(await actor.toJson()) | ||
const actor = (await system.actorFor(req.params.id)) as any | ||
res.json(await actor.toJson()) | ||
} catch (_) { | ||
res.sendStatus(404) | ||
} | ||
}) | ||
|
||
router.post(`${config.paths.push}/:id`, async (req: Request, res: Response) => { | ||
let actor | ||
let actor | ||
try { | ||
actor = (await system.actorFor(req.params.id)) as any | ||
actor = (await system.actorFor(req.params.id)) as any | ||
} 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])) as any | ||
} | ||
actor.updateFrom(req.body) | ||
res.sendStatus(200) | ||
}) | ||
|
||
return router | ||
} | ||
|
||
export default SyncController |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters