Last active
August 26, 2018 11:47
-
-
Save k1r0s/a780e2524aa70bc013ea73912f4b7892 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { AbstractResource } from "@ritley/core"; | |
| import DataService from "../services/database.service"; | |
| import UserModel from "../models/user.model"; | |
| import { Dependency, ReqTransformBodyAsync } from "@ritley/decorators"; | |
| @Dependency("userModel", UserModel) | |
| export default class UserResource extends AbstractResource { | |
| constructor(_database) { | |
| super("/users"); | |
| } | |
| @ReqTransformBodyAsync | |
| async post(req, res) { | |
| const body = await req.body; | |
| const payload = body.toJSON(); | |
| await this.userModel.validate(payload); | |
| await this.userModel.isUnique(payload); | |
| const user = await this.userModel.create(payload); | |
| res.statusCode = 200; | |
| res.end(JSON.stringify(user)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment