Last active
August 20, 2019 14:36
-
-
Save frankzickert/4c8f52c7efcd50edb63f2f10796071cd to your computer and use it in GitHub Desktop.
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
import * as React from 'react'; | |
import { | |
callService, | |
Middleware, | |
mutate, | |
Service, | |
serviceWithDataLayer | |
} from "infrastructure-components"; | |
import { USER_ENTRY_ID, IUserEntry } from './user-entry'; | |
const ADDUSER_SERVICE_ID = "adduser"; | |
export default function AddUserService () { | |
return <Service | |
id={ ADDUSER_SERVICE_ID } | |
path="/adduser" | |
method="POST"> | |
<Middleware | |
callback={serviceWithDataLayer(async function (dataLayer, req, res, next) { | |
const parsedBody: IUserEntry = JSON.parse(req.body); | |
await mutate( | |
dataLayer.client, | |
dataLayer.setEntryMutation(USER_ENTRY_ID, parsedBody) | |
); | |
res.status(200).set({ | |
"Access-Control-Allow-Origin" : "*", // Required for CORS support to work | |
}).send("ok"); | |
})}/> | |
</Service> | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment