Router/Responder.js

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var object_hash_1 = __importDefault(require("object-hash"));
var ExpressTS_1 = __importDefault(require("../app/ExpressTS"));
/**
 * This decorator is used to define a Responder.
 * Responders are **automatically** injected.
 *
 * All the responders must be in ``src/responders`` and they must have [\@Inject]{@link Inject}
 *
 * For an example on how the responder is used, check the [example from \@Post]{@link Post}.
 * @static
 * @return {any}
 * @method Responder
 * @memberof module:Router
 * @param {!string} name The name of the responder (This will have as prefix ``Responder.``)
 * @example <caption>Example usage of [\@Responder]{@link Responder}.</caption>
 * [\@Inject]{@link Inject}
 * [\@Responder]{@link Responder}('Name') // This will be accessed as 'Responder.Name'
 * export default class ResponderName {
 *    public success(res: Response) {
 *      return res.status(200).json({
 *        success: true
 *      });
 *    }
 *
 *    public created(res: Response, userId: string) {
 *      return res.status(201).json({
 *        success: true,
 *        userId
 *      });
 *    }
 * }
 */
exports.default = (function (name) { return function (constructor) {
    if (constructor.name === '_injected') {
        throw new Error('The responder must be called first!');
    }
    var responderHash = (0, object_hash_1.default)(constructor);
    if (!ExpressTS_1.default.getData(responderHash, 'responders')) {
        ExpressTS_1.default.setData(responderHash, name, 'responders');
    }
    return constructor;
}; });
//# sourceMappingURL=Responder.js.map