Skip to content

Instantly share code, notes, and snippets.

@k1r0s
Last active August 26, 2018 11:47
Show Gist options
  • Select an option

  • Save k1r0s/a780e2524aa70bc013ea73912f4b7892 to your computer and use it in GitHub Desktop.

Select an option

Save k1r0s/a780e2524aa70bc013ea73912f4b7892 to your computer and use it in GitHub Desktop.
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