@azteam/express 1.2.444 → 1.2.446

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,12 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "AdminController", {
7
- enumerable: true,
8
- get: function get() {
9
- return _AdminController["default"];
10
- }
11
- });
12
6
  Object.defineProperty(exports, "Controller", {
13
7
  enumerable: true,
14
8
  get: function get() {
@@ -16,5 +10,4 @@ Object.defineProperty(exports, "Controller", {
16
10
  }
17
11
  });
18
12
  var _Controller = _interopRequireDefault(require("./Controller"));
19
- var _AdminController = _interopRequireDefault(require("./AdminController"));
20
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/express",
3
- "version": "1.2.444",
3
+ "version": "1.2.446",
4
4
  "license": "MIT",
5
5
  "author": "toda <sp.azsolution.net@gmail.com>",
6
6
  "main": "./lib/index.js",
@@ -1,2 +1 @@
1
1
  export {default as Controller} from './Controller';
2
- export {default as AdminController} from './AdminController';
@@ -1,760 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _lodash = _interopRequireDefault(require("lodash"));
8
- var _error = require("@azteam/error");
9
- var _validator = require("@azteam/validator");
10
- var _constant = require("../constant");
11
- var _middleware = require("../middleware");
12
- var _Controller2 = _interopRequireDefault(require("./Controller"));
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
15
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
16
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
17
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
18
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
19
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
20
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
21
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
22
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
23
- function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
24
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
25
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
26
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
27
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
28
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
29
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
30
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
31
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
32
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
33
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
34
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
35
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
36
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
37
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
38
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
39
- var ALLOW_FIELDS = ['created_at', 'created_id', 'modified_at', 'modified_id', 'deleted_at', 'deleted_id', 'restored_id', 'resource', 'priority', 'is_synchronized', 'is_indexing', 'status', 'message'];
40
- var AdminController = /*#__PURE__*/function (_Controller) {
41
- _inherits(AdminController, _Controller);
42
- var _super = _createSuper(AdminController);
43
- function AdminController(repository) {
44
- var _this;
45
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
46
- var pathName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
47
- _classCallCheck(this, AdminController);
48
- _this = _super.call(this, repository, pathName);
49
- _defineProperty(_assertThisInitialized(_this), "methodGetAll", /*#__PURE__*/function () {
50
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, res) {
51
- var data;
52
- return _regeneratorRuntime().wrap(function _callee$(_context) {
53
- while (1) switch (_context.prev = _context.next) {
54
- case 0:
55
- _context.next = 2;
56
- return _this.repository.findAll(req.query, {
57
- limit: 2000,
58
- lean: true
59
- });
60
- case 2:
61
- data = _context.sent;
62
- return _context.abrupt("return", res.success(data, _this.guardResponse, _this.allowResponse));
63
- case 4:
64
- case "end":
65
- return _context.stop();
66
- }
67
- }, _callee);
68
- }));
69
- return function (_x, _x2) {
70
- return _ref.apply(this, arguments);
71
- };
72
- }());
73
- _defineProperty(_assertThisInitialized(_this), "methodGetPaginate", /*#__PURE__*/function () {
74
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(req, res) {
75
- var paginateData;
76
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
77
- while (1) switch (_context2.prev = _context2.next) {
78
- case 0:
79
- _context2.next = 2;
80
- return _this.repository.find(req.query, _objectSpread(_objectSpread({}, req.paginate), {}, {
81
- lean: true
82
- }));
83
- case 2:
84
- paginateData = _context2.sent;
85
- return _context2.abrupt("return", res.success(paginateData, _this.guardResponse, _this.allowResponse));
86
- case 4:
87
- case "end":
88
- return _context2.stop();
89
- }
90
- }, _callee2);
91
- }));
92
- return function (_x3, _x4) {
93
- return _ref2.apply(this, arguments);
94
- };
95
- }());
96
- _defineProperty(_assertThisInitialized(_this), "methodGetPaginateTrash", /*#__PURE__*/function () {
97
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(req, res) {
98
- var paginateData;
99
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
100
- while (1) switch (_context3.prev = _context3.next) {
101
- case 0:
102
- _context3.next = 2;
103
- return _this.repository.findTrash(req.query, _objectSpread(_objectSpread({}, req.paginate), {}, {
104
- lean: true
105
- }));
106
- case 2:
107
- paginateData = _context3.sent;
108
- return _context3.abrupt("return", res.success(paginateData, _this.guardResponse, _this.allowResponse));
109
- case 4:
110
- case "end":
111
- return _context3.stop();
112
- }
113
- }, _callee3);
114
- }));
115
- return function (_x5, _x6) {
116
- return _ref3.apply(this, arguments);
117
- };
118
- }());
119
- _defineProperty(_assertThisInitialized(_this), "methodGetOne", /*#__PURE__*/function () {
120
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(req, res) {
121
- var item;
122
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
123
- while (1) switch (_context4.prev = _context4.next) {
124
- case 0:
125
- _context4.next = 2;
126
- return _this.repository.findOneById(req.params.id);
127
- case 2:
128
- item = _context4.sent;
129
- if (item) {
130
- _context4.next = 5;
131
- break;
132
- }
133
- return _context4.abrupt("return", res.error(_error.NOT_EXISTS));
134
- case 5:
135
- return _context4.abrupt("return", res.success(item, _this.guardResponse, _this.allowResponse));
136
- case 6:
137
- case "end":
138
- return _context4.stop();
139
- }
140
- }, _callee4);
141
- }));
142
- return function (_x7, _x8) {
143
- return _ref4.apply(this, arguments);
144
- };
145
- }());
146
- _defineProperty(_assertThisInitialized(_this), "methodGetOneTrash", /*#__PURE__*/function () {
147
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(req, res) {
148
- var item;
149
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
150
- while (1) switch (_context5.prev = _context5.next) {
151
- case 0:
152
- _context5.next = 2;
153
- return _this.repository.findOneTrashById(req.params.id);
154
- case 2:
155
- item = _context5.sent;
156
- if (item) {
157
- _context5.next = 5;
158
- break;
159
- }
160
- return _context5.abrupt("return", res.error(_error.NOT_EXISTS));
161
- case 5:
162
- return _context5.abrupt("return", res.success(item, _this.guardResponse, _this.allowResponse));
163
- case 6:
164
- case "end":
165
- return _context5.stop();
166
- }
167
- }, _callee5);
168
- }));
169
- return function (_x9, _x10) {
170
- return _ref5.apply(this, arguments);
171
- };
172
- }());
173
- _defineProperty(_assertThisInitialized(_this), "methodPostCreate", /*#__PURE__*/function () {
174
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(data, user) {
175
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
176
- while (1) switch (_context6.prev = _context6.next) {
177
- case 0:
178
- return _context6.abrupt("return", _this.repository.createByUser(user.id, data));
179
- case 1:
180
- case "end":
181
- return _context6.stop();
182
- }
183
- }, _callee6);
184
- }));
185
- return function (_x11, _x12) {
186
- return _ref6.apply(this, arguments);
187
- };
188
- }());
189
- _defineProperty(_assertThisInitialized(_this), "methodPutModify", /*#__PURE__*/function () {
190
- var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(item, data, user) {
191
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
192
- while (1) switch (_context7.prev = _context7.next) {
193
- case 0:
194
- return _context7.abrupt("return", item.modify(data, user.id));
195
- case 1:
196
- case "end":
197
- return _context7.stop();
198
- }
199
- }, _callee7);
200
- }));
201
- return function (_x13, _x14, _x15) {
202
- return _ref7.apply(this, arguments);
203
- };
204
- }());
205
- _defineProperty(_assertThisInitialized(_this), "methodDelete", /*#__PURE__*/function () {
206
- var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(req, res) {
207
- var item;
208
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
209
- while (1) switch (_context8.prev = _context8.next) {
210
- case 0:
211
- _context8.next = 2;
212
- return _this.repository.findOneById(req.params.id);
213
- case 2:
214
- item = _context8.sent;
215
- if (item) {
216
- _context8.next = 5;
217
- break;
218
- }
219
- return _context8.abrupt("return", res.error(_error.NOT_EXISTS));
220
- case 5:
221
- _context8.next = 7;
222
- return _this.repository["delete"](item, req.user.id);
223
- case 7:
224
- _context8.next = 9;
225
- return _this.afterDelete(item);
226
- case 9:
227
- return _context8.abrupt("return", res.success(true));
228
- case 10:
229
- case "end":
230
- return _context8.stop();
231
- }
232
- }, _callee8);
233
- }));
234
- return function (_x16, _x17) {
235
- return _ref8.apply(this, arguments);
236
- };
237
- }());
238
- _defineProperty(_assertThisInitialized(_this), "methodPostRestoreTrash", /*#__PURE__*/function () {
239
- var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(req, res) {
240
- var item;
241
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
242
- while (1) switch (_context9.prev = _context9.next) {
243
- case 0:
244
- _context9.next = 2;
245
- return _this.repository.findOneTrashById(req.params.id);
246
- case 2:
247
- item = _context9.sent;
248
- if (item) {
249
- _context9.next = 5;
250
- break;
251
- }
252
- return _context9.abrupt("return", res.error(_error.NOT_EXISTS));
253
- case 5:
254
- _context9.next = 7;
255
- return _this.repository.restore(item, req.user.id);
256
- case 7:
257
- return _context9.abrupt("return", res.success(true));
258
- case 8:
259
- case "end":
260
- return _context9.stop();
261
- }
262
- }, _callee9);
263
- }));
264
- return function (_x18, _x19) {
265
- return _ref9.apply(this, arguments);
266
- };
267
- }());
268
- _defineProperty(_assertThisInitialized(_this), "methodDeleteDestroyTrash", /*#__PURE__*/function () {
269
- var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(req, res) {
270
- var item, oldItem;
271
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
272
- while (1) switch (_context10.prev = _context10.next) {
273
- case 0:
274
- _context10.next = 2;
275
- return _this.repository.findOneTrashById(req.params.id);
276
- case 2:
277
- item = _context10.sent;
278
- if (item) {
279
- _context10.next = 5;
280
- break;
281
- }
282
- return _context10.abrupt("return", res.error(_error.NOT_EXISTS));
283
- case 5:
284
- oldItem = _lodash["default"].cloneDeep(item);
285
- _context10.next = 8;
286
- return _this.repository.destroy(item.id);
287
- case 8:
288
- _context10.next = 10;
289
- return _this.afterDestroy(oldItem);
290
- case 10:
291
- return _context10.abrupt("return", res.success(true));
292
- case 11:
293
- case "end":
294
- return _context10.stop();
295
- }
296
- }, _callee10);
297
- }));
298
- return function (_x20, _x21) {
299
- return _ref10.apply(this, arguments);
300
- };
301
- }());
302
- _this.roles = _objectSpread({
303
- EXEC: null,
304
- READ: null,
305
- CREATE: null,
306
- UPDATE: null,
307
- DELETE: null,
308
- RESTORE: null,
309
- DESTROY: null,
310
- IMPORT: null,
311
- EXPORT: null
312
- }, options.roles);
313
- _this.roleMiddlewareOptions = {
314
- secretKey: options.secretKey || process.env.SECRET_KEY,
315
- systemURL: options.systemURL || process.env.SYSTEM_URL
316
- };
317
- _this.paginateOptions = options.paginateOptions || {
318
- autocompleteField: null,
319
- allowSearchFields: [],
320
- allowSortFields: []
321
- };
322
- _this.guardResponse = options.guardResponse || [];
323
- _this.allowResponse = options.allowResponse ? [].concat(_toConsumableArray(options.allowResponse), ALLOW_FIELDS) : ALLOW_FIELDS;
324
- if (options.indexing) {
325
- _this.paginateOptions.allowSearchFields = [].concat(_toConsumableArray(_this.paginateOptions.allowSearchFields), ['is_indexing']);
326
- }
327
- _this.paginateOptions.allowSearchFields = [].concat(_toConsumableArray(_this.paginateOptions.allowSearchFields), ['status', 'created_at_start', 'created_at_end', 'modified_at_start', 'modified_at_end']);
328
- _this.paginateOptions.allowSortFields = [].concat(_toConsumableArray(_this.paginateOptions.allowSortFields), ['priority', 'created_at', 'modified_at', 'status'
329
- //
330
- ]);
331
- return _this;
332
- }
333
- _createClass(AdminController, [{
334
- key: "getFilterOption",
335
- value: function getFilterOption() {
336
- var _this2 = this;
337
- return {
338
- disabled: !this.roles.READ,
339
- path: '/filter_option',
340
- method: [(0, _middleware.adminRoleMiddleware)([this.roles.READ], this.roleMiddlewareOptions), /*#__PURE__*/function () {
341
- var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(req, res) {
342
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
343
- while (1) switch (_context11.prev = _context11.next) {
344
- case 0:
345
- return _context11.abrupt("return", res.success(_this2.paginateOptions));
346
- case 1:
347
- case "end":
348
- return _context11.stop();
349
- }
350
- }, _callee11);
351
- }));
352
- return function (_x22, _x23) {
353
- return _ref11.apply(this, arguments);
354
- };
355
- }()]
356
- };
357
- }
358
- }, {
359
- key: "getAll",
360
- value: function getAll() {
361
- return {
362
- disabled: !this.roles.READ,
363
- path: '/all',
364
- method: [(0, _middleware.adminRoleMiddleware)([this.roles.READ], this.roleMiddlewareOptions), this.methodGetAll]
365
- };
366
- }
367
- }, {
368
- key: "getPaginate",
369
- value: function getPaginate() {
370
- return {
371
- disabled: !this.roles.READ,
372
- path: '/',
373
- method: [(0, _middleware.adminRoleMiddleware)([this.roles.READ], this.roleMiddlewareOptions), (0, _middleware.paginateMiddleware)(this.paginateOptions), this.methodGetPaginate]
374
- };
375
- }
376
- }, {
377
- key: "getPaginateTrash",
378
- value: function getPaginateTrash() {
379
- return {
380
- disabled: !this.roles.READ,
381
- path: '/',
382
- method: [(0, _middleware.adminRoleMiddleware)([this.roles.READ], this.roleMiddlewareOptions), (0, _middleware.paginateMiddleware)(this.paginateOptions), this.methodGetPaginateTrash]
383
- };
384
- }
385
- }, {
386
- key: "getOne",
387
- value: function getOne() {
388
- return {
389
- disabled: !this.roles.READ,
390
- path: '/:id([a-zA-Z0-9]+)',
391
- method: [(0, _middleware.adminRoleMiddleware)([this.roles.READ], this.roleMiddlewareOptions), (0, _middleware.validateMiddleware)(_constant.REQUEST_TYPE.PARAMS, _validator.rulesId), this.methodGetOne]
392
- };
393
- }
394
- }, {
395
- key: "getOneTrash",
396
- value: function getOneTrash() {
397
- return {
398
- disabled: !this.roles.READ,
399
- path: '/:id([a-zA-Z0-9]+)',
400
- method: [(0, _middleware.adminRoleMiddleware)([this.roles.READ], this.roleMiddlewareOptions), (0, _middleware.validateMiddleware)(_constant.REQUEST_TYPE.PARAMS, _validator.rulesId), this.methodGetOneTrash]
401
- };
402
- }
403
- }, {
404
- key: "beforeCreate",
405
- value: function () {
406
- var _beforeCreate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(data) {
407
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
408
- while (1) switch (_context12.prev = _context12.next) {
409
- case 0:
410
- return _context12.abrupt("return", data);
411
- case 1:
412
- case "end":
413
- return _context12.stop();
414
- }
415
- }, _callee12);
416
- }));
417
- function beforeCreate(_x24) {
418
- return _beforeCreate.apply(this, arguments);
419
- }
420
- return beforeCreate;
421
- }()
422
- }, {
423
- key: "afterCreate",
424
- value: function () {
425
- var _afterCreate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(item) {
426
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
427
- while (1) switch (_context13.prev = _context13.next) {
428
- case 0:
429
- return _context13.abrupt("return", item);
430
- case 1:
431
- case "end":
432
- return _context13.stop();
433
- }
434
- }, _callee13);
435
- }));
436
- function afterCreate(_x25) {
437
- return _afterCreate.apply(this, arguments);
438
- }
439
- return afterCreate;
440
- }()
441
- }, {
442
- key: "postCreate",
443
- value: function postCreate() {
444
- var _this3 = this;
445
- return {
446
- disabled: !this.roles.CREATE,
447
- path: '/',
448
- method: [(0, _middleware.adminRoleMiddleware)([this.roles.CREATE], this.roleMiddlewareOptions), /*#__PURE__*/function () {
449
- var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(req, res) {
450
- var data, item;
451
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
452
- while (1) switch (_context14.prev = _context14.next) {
453
- case 0:
454
- _context14.next = 2;
455
- return _this3.beforeCreate(req.body);
456
- case 2:
457
- data = _context14.sent;
458
- _context14.next = 5;
459
- return _this3.methodPostCreate(data, req.user);
460
- case 5:
461
- item = _context14.sent;
462
- _context14.next = 8;
463
- return _this3.afterCreate(item);
464
- case 8:
465
- item = _context14.sent;
466
- return _context14.abrupt("return", res.success(item, _this3.guardResponse, _this3.allowResponse));
467
- case 10:
468
- case "end":
469
- return _context14.stop();
470
- }
471
- }, _callee14);
472
- }));
473
- return function (_x26, _x27) {
474
- return _ref12.apply(this, arguments);
475
- };
476
- }()]
477
- };
478
- }
479
- }, {
480
- key: "beforeModify",
481
- value: function () {
482
- var _beforeModify = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(data) {
483
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
484
- while (1) switch (_context15.prev = _context15.next) {
485
- case 0:
486
- return _context15.abrupt("return", data);
487
- case 1:
488
- case "end":
489
- return _context15.stop();
490
- }
491
- }, _callee15);
492
- }));
493
- function beforeModify(_x28) {
494
- return _beforeModify.apply(this, arguments);
495
- }
496
- return beforeModify;
497
- }()
498
- }, {
499
- key: "afterModify",
500
- value: function () {
501
- var _afterModify = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(item) {
502
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
503
- while (1) switch (_context16.prev = _context16.next) {
504
- case 0:
505
- return _context16.abrupt("return", item);
506
- case 1:
507
- case "end":
508
- return _context16.stop();
509
- }
510
- }, _callee16);
511
- }));
512
- function afterModify(_x29) {
513
- return _afterModify.apply(this, arguments);
514
- }
515
- return afterModify;
516
- }()
517
- }, {
518
- key: "putModify",
519
- value: function putModify() {
520
- var _this4 = this;
521
- return {
522
- disabled: !this.roles.UPDATE,
523
- path: '/:id([a-zA-Z0-9]+)',
524
- method: [(0, _middleware.adminRoleMiddleware)([this.roles.UPDATE], this.roleMiddlewareOptions), (0, _middleware.validateMiddleware)(_constant.REQUEST_TYPE.PARAMS, _validator.rulesId), /*#__PURE__*/function () {
525
- var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(req, res) {
526
- var item, data;
527
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
528
- while (1) switch (_context17.prev = _context17.next) {
529
- case 0:
530
- _context17.next = 2;
531
- return _this4.repository.findOneById(req.params.id);
532
- case 2:
533
- item = _context17.sent;
534
- if (item) {
535
- _context17.next = 5;
536
- break;
537
- }
538
- return _context17.abrupt("return", res.error(_error.NOT_EXISTS));
539
- case 5:
540
- _context17.next = 7;
541
- return _this4.beforeModify(req.body);
542
- case 7:
543
- data = _context17.sent;
544
- item = _this4.methodPutModify(item, data, req.user);
545
- _context17.next = 11;
546
- return _this4.afterModify(item);
547
- case 11:
548
- item = _context17.sent;
549
- return _context17.abrupt("return", res.success(item, _this4.guardResponse, _this4.allowResponse));
550
- case 13:
551
- case "end":
552
- return _context17.stop();
553
- }
554
- }, _callee17);
555
- }));
556
- return function (_x30, _x31) {
557
- return _ref13.apply(this, arguments);
558
- };
559
- }()]
560
- };
561
- }
562
- }, {
563
- key: "putModifyStatusAvailable",
564
- value: function putModifyStatusAvailable() {
565
- var _this5 = this;
566
- return {
567
- disabled: !this.roles.UPDATE,
568
- path: '/available/:id([a-zA-Z0-9]+)',
569
- method: [(0, _middleware.adminRoleMiddleware)([this.roles.UPDATE], this.roleMiddlewareOptions), (0, _middleware.validateMiddleware)(_constant.REQUEST_TYPE.PARAMS, _validator.rulesId), /*#__PURE__*/function () {
570
- var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(req, res) {
571
- var item;
572
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
573
- while (1) switch (_context18.prev = _context18.next) {
574
- case 0:
575
- _context18.next = 2;
576
- return _this5.repository.findOneById(req.params.id);
577
- case 2:
578
- item = _context18.sent;
579
- if (item) {
580
- _context18.next = 5;
581
- break;
582
- }
583
- return _context18.abrupt("return", res.error(_error.NOT_EXISTS));
584
- case 5:
585
- _context18.next = 7;
586
- return item.modifyStatusAvailable(req.user.id);
587
- case 7:
588
- _context18.next = 9;
589
- return _this5.afterModify(item);
590
- case 9:
591
- item = _context18.sent;
592
- return _context18.abrupt("return", res.success(item, _this5.guardResponse, _this5.allowResponse));
593
- case 11:
594
- case "end":
595
- return _context18.stop();
596
- }
597
- }, _callee18);
598
- }));
599
- return function (_x32, _x33) {
600
- return _ref14.apply(this, arguments);
601
- };
602
- }()]
603
- };
604
- }
605
- }, {
606
- key: "putModifyStatusUnavailable",
607
- value: function putModifyStatusUnavailable() {
608
- var _this6 = this;
609
- return {
610
- disabled: !this.roles.UPDATE,
611
- path: '/unavailable/:id([a-zA-Z0-9]+)',
612
- method: [(0, _middleware.adminRoleMiddleware)([this.roles.UPDATE], this.roleMiddlewareOptions), (0, _middleware.validateMiddleware)(_constant.REQUEST_TYPE.PARAMS, _validator.rulesId), /*#__PURE__*/function () {
613
- var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(req, res) {
614
- var item;
615
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
616
- while (1) switch (_context19.prev = _context19.next) {
617
- case 0:
618
- _context19.next = 2;
619
- return _this6.repository.findOneById(req.params.id);
620
- case 2:
621
- item = _context19.sent;
622
- if (item) {
623
- _context19.next = 5;
624
- break;
625
- }
626
- return _context19.abrupt("return", res.error(_error.NOT_EXISTS));
627
- case 5:
628
- _context19.next = 7;
629
- return item.modifyStatusUnavailable(req.body.message, req.user.id);
630
- case 7:
631
- _context19.next = 9;
632
- return _this6.afterModify(item);
633
- case 9:
634
- item = _context19.sent;
635
- return _context19.abrupt("return", res.success(item, _this6.guardResponse, _this6.allowResponse));
636
- case 11:
637
- case "end":
638
- return _context19.stop();
639
- }
640
- }, _callee19);
641
- }));
642
- return function (_x34, _x35) {
643
- return _ref15.apply(this, arguments);
644
- };
645
- }()]
646
- };
647
- }
648
- }, {
649
- key: "putModifyStatusWaiting",
650
- value: function putModifyStatusWaiting() {
651
- var _this7 = this;
652
- return {
653
- disabled: !this.roles.UPDATE,
654
- path: '/waiting/:id([a-zA-Z0-9]+)',
655
- method: [(0, _middleware.adminRoleMiddleware)([this.roles.UPDATE], this.roleMiddlewareOptions), (0, _middleware.validateMiddleware)(_constant.REQUEST_TYPE.PARAMS, _validator.rulesId), /*#__PURE__*/function () {
656
- var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(req, res) {
657
- var item;
658
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
659
- while (1) switch (_context20.prev = _context20.next) {
660
- case 0:
661
- _context20.next = 2;
662
- return _this7.repository.findOneById(req.params.id);
663
- case 2:
664
- item = _context20.sent;
665
- if (item) {
666
- _context20.next = 5;
667
- break;
668
- }
669
- return _context20.abrupt("return", res.error(_error.NOT_EXISTS));
670
- case 5:
671
- _context20.next = 7;
672
- return item.modifyStatusWaiting(req.user.id);
673
- case 7:
674
- _context20.next = 9;
675
- return _this7.afterModify(item);
676
- case 9:
677
- item = _context20.sent;
678
- return _context20.abrupt("return", res.success(item, _this7.guardResponse, _this7.allowResponse));
679
- case 11:
680
- case "end":
681
- return _context20.stop();
682
- }
683
- }, _callee20);
684
- }));
685
- return function (_x36, _x37) {
686
- return _ref16.apply(this, arguments);
687
- };
688
- }()]
689
- };
690
- }
691
- }, {
692
- key: "afterDelete",
693
- value: function () {
694
- var _afterDelete = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(item) {
695
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
696
- while (1) switch (_context21.prev = _context21.next) {
697
- case 0:
698
- return _context21.abrupt("return", item);
699
- case 1:
700
- case "end":
701
- return _context21.stop();
702
- }
703
- }, _callee21);
704
- }));
705
- function afterDelete(_x38) {
706
- return _afterDelete.apply(this, arguments);
707
- }
708
- return afterDelete;
709
- }()
710
- }, {
711
- key: "delete",
712
- value: function _delete() {
713
- return {
714
- disabled: !this.roles.DELETE,
715
- path: '/:id([a-zA-Z0-9]+)',
716
- method: [(0, _middleware.adminRoleMiddleware)([this.roles.DELETE], this.roleMiddlewareOptions), (0, _middleware.validateMiddleware)(_constant.REQUEST_TYPE.PARAMS, _validator.rulesId), this.methodDelete]
717
- };
718
- }
719
- }, {
720
- key: "postRestoreTrash",
721
- value: function postRestoreTrash() {
722
- return {
723
- disabled: !this.roles.RESTORE,
724
- path: '/:id([a-zA-Z0-9]+)',
725
- method: [(0, _middleware.adminRoleMiddleware)([this.roles.RESTORE], this.roleMiddlewareOptions), (0, _middleware.validateMiddleware)(_constant.REQUEST_TYPE.PARAMS, _validator.rulesId), this.methodPostRestoreTrash]
726
- };
727
- }
728
- }, {
729
- key: "afterDestroy",
730
- value: function () {
731
- var _afterDestroy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(item) {
732
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
733
- while (1) switch (_context22.prev = _context22.next) {
734
- case 0:
735
- return _context22.abrupt("return", item);
736
- case 1:
737
- case "end":
738
- return _context22.stop();
739
- }
740
- }, _callee22);
741
- }));
742
- function afterDestroy(_x39) {
743
- return _afterDestroy.apply(this, arguments);
744
- }
745
- return afterDestroy;
746
- }()
747
- }, {
748
- key: "deleteDestroyTrash",
749
- value: function deleteDestroyTrash() {
750
- return {
751
- disabled: !this.roles.DESTROY,
752
- path: '/:id([a-zA-Z0-9]+)',
753
- method: [(0, _middleware.adminRoleMiddleware)([this.roles.DESTROY], this.roleMiddlewareOptions), (0, _middleware.validateMiddleware)(_constant.REQUEST_TYPE.PARAMS, _validator.rulesId), this.methodDeleteDestroyTrash]
754
- };
755
- }
756
- }]);
757
- return AdminController;
758
- }(_Controller2["default"]);
759
- var _default = AdminController;
760
- exports["default"] = _default;
@@ -1,390 +0,0 @@
1
- import _ from 'lodash';
2
-
3
- import {NOT_EXISTS} from '@azteam/error';
4
- import {rulesId} from '@azteam/validator';
5
-
6
- import {REQUEST_TYPE} from '../constant';
7
- import {adminRoleMiddleware, paginateMiddleware, validateMiddleware} from '../middleware';
8
- import Controller from './Controller';
9
-
10
- const ALLOW_FIELDS = [
11
- 'created_at',
12
- 'created_id',
13
- 'modified_at',
14
- 'modified_id',
15
- 'deleted_at',
16
- 'deleted_id',
17
- 'restored_id',
18
- 'resource',
19
- 'priority',
20
- 'is_synchronized',
21
- 'is_indexing',
22
- 'status',
23
- 'message',
24
- ];
25
-
26
- class AdminController extends Controller {
27
- constructor(repository, options = {}, pathName = null) {
28
- super(repository, pathName);
29
-
30
- this.roles = {
31
- EXEC: null,
32
- READ: null,
33
- CREATE: null,
34
- UPDATE: null,
35
- DELETE: null,
36
- RESTORE: null,
37
- DESTROY: null,
38
- IMPORT: null,
39
- EXPORT: null,
40
-
41
- ...options.roles,
42
- };
43
-
44
- this.roleMiddlewareOptions = {
45
- secretKey: options.secretKey || process.env.SECRET_KEY,
46
- systemURL: options.systemURL || process.env.SYSTEM_URL,
47
- };
48
-
49
- this.paginateOptions = options.paginateOptions || {
50
- autocompleteField: null,
51
- allowSearchFields: [],
52
- allowSortFields: [],
53
- };
54
- this.guardResponse = options.guardResponse || [];
55
- this.allowResponse = options.allowResponse ? [...options.allowResponse, ...ALLOW_FIELDS] : ALLOW_FIELDS;
56
-
57
- if (options.indexing) {
58
- this.paginateOptions.allowSearchFields = [...this.paginateOptions.allowSearchFields, 'is_indexing'];
59
- }
60
-
61
- this.paginateOptions.allowSearchFields = [
62
- ...this.paginateOptions.allowSearchFields,
63
- 'status',
64
- 'created_at_start',
65
- 'created_at_end',
66
- 'modified_at_start',
67
- 'modified_at_end',
68
- ];
69
- this.paginateOptions.allowSortFields = [
70
- ...this.paginateOptions.allowSortFields,
71
- 'priority',
72
- 'created_at',
73
- 'modified_at',
74
- 'status',
75
- //
76
- ];
77
- }
78
-
79
- getFilterOption() {
80
- return {
81
- disabled: !this.roles.READ,
82
- path: '/filter_option',
83
- method: [
84
- adminRoleMiddleware([this.roles.READ], this.roleMiddlewareOptions),
85
- async (req, res) => {
86
- return res.success(this.paginateOptions);
87
- },
88
- ],
89
- };
90
- }
91
-
92
- methodGetAll = async (req, res) => {
93
- const data = await this.repository.findAll(req.query, {
94
- limit: 2000,
95
- lean: true,
96
- });
97
- return res.success(data, this.guardResponse, this.allowResponse);
98
- };
99
-
100
- getAll() {
101
- return {
102
- disabled: !this.roles.READ,
103
- path: '/all',
104
- method: [adminRoleMiddleware([this.roles.READ], this.roleMiddlewareOptions), this.methodGetAll],
105
- };
106
- }
107
-
108
- methodGetPaginate = async (req, res) => {
109
- const paginateData = await this.repository.find(req.query, {
110
- ...req.paginate,
111
- lean: true,
112
- });
113
- return res.success(paginateData, this.guardResponse, this.allowResponse);
114
- };
115
-
116
- getPaginate() {
117
- return {
118
- disabled: !this.roles.READ,
119
- path: '/',
120
- method: [
121
- adminRoleMiddleware([this.roles.READ], this.roleMiddlewareOptions),
122
- paginateMiddleware(this.paginateOptions),
123
- this.methodGetPaginate,
124
- ],
125
- };
126
- }
127
-
128
- methodGetPaginateTrash = async (req, res) => {
129
- const paginateData = await this.repository.findTrash(req.query, {
130
- ...req.paginate,
131
- lean: true,
132
- });
133
- return res.success(paginateData, this.guardResponse, this.allowResponse);
134
- };
135
-
136
- getPaginateTrash() {
137
- return {
138
- disabled: !this.roles.READ,
139
- path: '/',
140
- method: [
141
- adminRoleMiddleware([this.roles.READ], this.roleMiddlewareOptions),
142
- paginateMiddleware(this.paginateOptions),
143
- this.methodGetPaginateTrash,
144
- ],
145
- };
146
- }
147
-
148
- methodGetOne = async (req, res) => {
149
- const item = await this.repository.findOneById(req.params.id);
150
- if (!item) return res.error(NOT_EXISTS);
151
- return res.success(item, this.guardResponse, this.allowResponse);
152
- };
153
-
154
- getOne() {
155
- return {
156
- disabled: !this.roles.READ,
157
- path: '/:id([a-zA-Z0-9]+)',
158
- method: [
159
- adminRoleMiddleware([this.roles.READ], this.roleMiddlewareOptions),
160
- validateMiddleware(REQUEST_TYPE.PARAMS, rulesId),
161
- this.methodGetOne,
162
- ],
163
- };
164
- }
165
-
166
- methodGetOneTrash = async (req, res) => {
167
- const item = await this.repository.findOneTrashById(req.params.id);
168
- if (!item) return res.error(NOT_EXISTS);
169
- return res.success(item, this.guardResponse, this.allowResponse);
170
- };
171
-
172
- getOneTrash() {
173
- return {
174
- disabled: !this.roles.READ,
175
- path: '/:id([a-zA-Z0-9]+)',
176
- method: [
177
- adminRoleMiddleware([this.roles.READ], this.roleMiddlewareOptions),
178
- validateMiddleware(REQUEST_TYPE.PARAMS, rulesId),
179
- this.methodGetOneTrash,
180
- ],
181
- };
182
- }
183
-
184
- async beforeCreate(data) {
185
- return data;
186
- }
187
-
188
- async afterCreate(item) {
189
- return item;
190
- }
191
-
192
- methodPostCreate = async (data, user) => {
193
- return this.repository.createByUser(user.id, data);
194
- };
195
-
196
- postCreate() {
197
- return {
198
- disabled: !this.roles.CREATE,
199
- path: '/',
200
- method: [
201
- adminRoleMiddleware([this.roles.CREATE], this.roleMiddlewareOptions),
202
- async (req, res) => {
203
- const data = await this.beforeCreate(req.body);
204
-
205
- let item = await this.methodPostCreate(data, req.user);
206
-
207
- item = await this.afterCreate(item);
208
-
209
- return res.success(item, this.guardResponse, this.allowResponse);
210
- },
211
- ],
212
- };
213
- }
214
-
215
- async beforeModify(data) {
216
- return data;
217
- }
218
-
219
- async afterModify(item) {
220
- return item;
221
- }
222
-
223
- methodPutModify = async (item, data, user) => {
224
- return item.modify(data, user.id);
225
- };
226
-
227
- putModify() {
228
- return {
229
- disabled: !this.roles.UPDATE,
230
- path: '/:id([a-zA-Z0-9]+)',
231
- method: [
232
- adminRoleMiddleware([this.roles.UPDATE], this.roleMiddlewareOptions),
233
- validateMiddleware(REQUEST_TYPE.PARAMS, rulesId),
234
- async (req, res) => {
235
- let item = await this.repository.findOneById(req.params.id);
236
- if (!item) return res.error(NOT_EXISTS);
237
-
238
- const data = await this.beforeModify(req.body);
239
-
240
- item = this.methodPutModify(item, data, req.user);
241
-
242
- item = await this.afterModify(item);
243
-
244
- return res.success(item, this.guardResponse, this.allowResponse);
245
- },
246
- ],
247
- };
248
- }
249
-
250
- putModifyStatusAvailable() {
251
- return {
252
- disabled: !this.roles.UPDATE,
253
- path: '/available/:id([a-zA-Z0-9]+)',
254
- method: [
255
- adminRoleMiddleware([this.roles.UPDATE], this.roleMiddlewareOptions),
256
- validateMiddleware(REQUEST_TYPE.PARAMS, rulesId),
257
- async (req, res) => {
258
- let item = await this.repository.findOneById(req.params.id);
259
- if (!item) return res.error(NOT_EXISTS);
260
-
261
- await item.modifyStatusAvailable(req.user.id);
262
-
263
- item = await this.afterModify(item);
264
-
265
- return res.success(item, this.guardResponse, this.allowResponse);
266
- },
267
- ],
268
- };
269
- }
270
-
271
- putModifyStatusUnavailable() {
272
- return {
273
- disabled: !this.roles.UPDATE,
274
- path: '/unavailable/:id([a-zA-Z0-9]+)',
275
- method: [
276
- adminRoleMiddleware([this.roles.UPDATE], this.roleMiddlewareOptions),
277
- validateMiddleware(REQUEST_TYPE.PARAMS, rulesId),
278
- async (req, res) => {
279
- let item = await this.repository.findOneById(req.params.id);
280
- if (!item) return res.error(NOT_EXISTS);
281
-
282
- await item.modifyStatusUnavailable(req.body.message, req.user.id);
283
-
284
- item = await this.afterModify(item);
285
-
286
- return res.success(item, this.guardResponse, this.allowResponse);
287
- },
288
- ],
289
- };
290
- }
291
-
292
- putModifyStatusWaiting() {
293
- return {
294
- disabled: !this.roles.UPDATE,
295
- path: '/waiting/:id([a-zA-Z0-9]+)',
296
- method: [
297
- adminRoleMiddleware([this.roles.UPDATE], this.roleMiddlewareOptions),
298
- validateMiddleware(REQUEST_TYPE.PARAMS, rulesId),
299
- async (req, res) => {
300
- let item = await this.repository.findOneById(req.params.id);
301
- if (!item) return res.error(NOT_EXISTS);
302
-
303
- await item.modifyStatusWaiting(req.user.id);
304
-
305
- item = await this.afterModify(item);
306
-
307
- return res.success(item, this.guardResponse, this.allowResponse);
308
- },
309
- ],
310
- };
311
- }
312
-
313
- async afterDelete(item) {
314
- return item;
315
- }
316
-
317
- methodDelete = async (req, res) => {
318
- const item = await this.repository.findOneById(req.params.id);
319
- if (!item) return res.error(NOT_EXISTS);
320
-
321
- await this.repository.delete(item, req.user.id);
322
- await this.afterDelete(item);
323
-
324
- return res.success(true);
325
- };
326
-
327
- delete() {
328
- return {
329
- disabled: !this.roles.DELETE,
330
- path: '/:id([a-zA-Z0-9]+)',
331
- method: [
332
- adminRoleMiddleware([this.roles.DELETE], this.roleMiddlewareOptions),
333
- validateMiddleware(REQUEST_TYPE.PARAMS, rulesId),
334
- this.methodDelete,
335
- ],
336
- };
337
- }
338
-
339
- methodPostRestoreTrash = async (req, res) => {
340
- const item = await this.repository.findOneTrashById(req.params.id);
341
- if (!item) return res.error(NOT_EXISTS);
342
-
343
- await this.repository.restore(item, req.user.id);
344
-
345
- return res.success(true);
346
- };
347
-
348
- postRestoreTrash() {
349
- return {
350
- disabled: !this.roles.RESTORE,
351
- path: '/:id([a-zA-Z0-9]+)',
352
- method: [
353
- adminRoleMiddleware([this.roles.RESTORE], this.roleMiddlewareOptions),
354
- validateMiddleware(REQUEST_TYPE.PARAMS, rulesId),
355
- this.methodPostRestoreTrash,
356
- ],
357
- };
358
- }
359
-
360
- async afterDestroy(item) {
361
- return item;
362
- }
363
-
364
- methodDeleteDestroyTrash = async (req, res) => {
365
- const item = await this.repository.findOneTrashById(req.params.id);
366
- if (!item) return res.error(NOT_EXISTS);
367
-
368
- const oldItem = _.cloneDeep(item);
369
-
370
- await this.repository.destroy(item.id);
371
-
372
- await this.afterDestroy(oldItem);
373
-
374
- return res.success(true);
375
- };
376
-
377
- deleteDestroyTrash() {
378
- return {
379
- disabled: !this.roles.DESTROY,
380
- path: '/:id([a-zA-Z0-9]+)',
381
- method: [
382
- adminRoleMiddleware([this.roles.DESTROY], this.roleMiddlewareOptions),
383
- validateMiddleware(REQUEST_TYPE.PARAMS, rulesId),
384
- this.methodDeleteDestroyTrash,
385
- ],
386
- };
387
- }
388
- }
389
-
390
- export default AdminController;