- this should be accomplished through HTTP POST request to
/users
- if JSON payload isn't well formed we have to file a Bad Request 400 and provide a specific error message
- users have to provide several fields: name, mail, pass . If any field is missing we have to file a Bad Request 400 and provide a specific error message
- if provided email is already taken we have to file a Conflict 409 and provide a specific error message
- if above requirements are meet we should encrypt the password and store all newly provided data on the database
- if all above processes are success we should file a Created 201 response and send newly created user as a JSON content
- any errors not mentioned above need to be handled. A Internal Server Error 500 response should be filed to the user
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 { setAdapter, AbstractResource } from "@ritley/core"; | |
import Adapter from "@ritley/standalone-adapter"; | |
setAdapter(Adapter, { | |
"port": 8080 | |
}); | |
class SessionResource extends AbstractResource { | |
constructor() { | |
super("/sessions"); |
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 { setAdapter } from "@ritley/core"; | |
import Adapter from "@ritley/standalone-adapter"; | |
import SessionResource from "./resources/session.resource" | |
import UserResource from "./resources/user.resource" | |
setAdapter(Adapter, { | |
"port": 8080 | |
}); |
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 low from "lowdb"; | |
import FileAsync from "lowdb/adapters/FileAsync"; | |
import shortid from "shortid"; | |
import config from "../config/database.config"; | |
import { Provider } from "@ritley/decorators"; | |
@Provider.singleton | |
export default class DataService { | |
onConnected = undefined |
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 { AbstractResource } from "@ritley/core"; | |
import DataService from "../services/database.service"; | |
import { Dependency, ReqTransformBodySync } from "@ritley/decorators"; | |
@Dependency("database", DataService) | |
export default class UserResource extends AbstractResource { | |
constructor(_database) { | |
super("/users"); | |
} |
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 DataService from "../services/database.service"; | |
import EncryptService from "../services/encrypt.service"; | |
import { Provider, Dependency } from "@ritley/decorators"; | |
@Provider.factory | |
@Dependency("database", DataService) | |
@Dependency("encrypt", EncryptService) | |
export default class UserModel { |
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 { 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"); |
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 { 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"); |
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 { AbstractResource } from "@ritley/core"; | |
import DataService from "../services/database.service"; | |
import UserModel from "../models/user.model"; | |
import { | |
Dependency, | |
ReqTransformBodyAsync, | |
Default, | |
Catch, | |
InternalServerError, |
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
const { setAdapter, AbstractResource } = require("@ritley/core"); | |
const Adapter = require("@ritley/standalone-adapter"); | |
setAdapter(Adapter, { | |
"port": 8080 | |
}); | |
class DefaultResource extends AbstractResource { | |
get(req, res) { |