@ai-ecom/medusa-plugin-patient-record
Version:
A plugin for patient record
261 lines (260 loc) • 12.6 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _medusa = require("@medusajs/medusa");
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
var EthnicitiesHaveReferencesService = /*#__PURE__*/function (_TransactionBaseServi) {
function EthnicitiesHaveReferencesService(_ref) {
var _this;
var ethnicitiesHaveReferencesRepository = _ref.ethnicitiesHaveReferencesRepository,
eventBusService = _ref.eventBusService;
(0, _classCallCheck2["default"])(this, EthnicitiesHaveReferencesService);
// eslint-disable-next-line prefer-rest-params
_this = _callSuper(this, EthnicitiesHaveReferencesService, [arguments[0]]);
_this.ethnicitiesHaveReferencesRepository_ = ethnicitiesHaveReferencesRepository;
_this.eventBus_ = eventBusService;
return _this;
}
(0, _inherits2["default"])(EthnicitiesHaveReferencesService, _TransactionBaseServi);
return (0, _createClass2["default"])(EthnicitiesHaveReferencesService, [{
key: "list",
value: function () {
var _list = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(selector) {
var config,
_yield$this$listAndCo,
_yield$this$listAndCo2,
ethnicitiesHaveReferences,
_args = arguments;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
config = _args.length > 1 && _args[1] !== undefined ? _args[1] : {
skip: 0,
take: 50,
relations: []
};
_context.next = 3;
return this.listAndCount(selector, config);
case 3:
_yield$this$listAndCo = _context.sent;
_yield$this$listAndCo2 = (0, _slicedToArray2["default"])(_yield$this$listAndCo, 1);
ethnicitiesHaveReferences = _yield$this$listAndCo2[0];
return _context.abrupt("return", ethnicitiesHaveReferences);
case 7:
case "end":
return _context.stop();
}
}, _callee, this);
}));
function list(_x) {
return _list.apply(this, arguments);
}
return list;
}()
}, {
key: "listAndCount",
value: function () {
var _listAndCount = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(selector) {
var config,
ethnicitiesHaveReferencesRepo,
query,
_args2 = arguments;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
config = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {
skip: 0,
take: 50,
relations: []
};
ethnicitiesHaveReferencesRepo = this.activeManager_.withRepository(this.ethnicitiesHaveReferencesRepository_);
query = (0, _medusa.buildQuery)(selector, config);
return _context2.abrupt("return", ethnicitiesHaveReferencesRepo.findAndCount(query));
case 4:
case "end":
return _context2.stop();
}
}, _callee2, this);
}));
function listAndCount(_x2) {
return _listAndCount.apply(this, arguments);
}
return listAndCount;
}()
}, {
key: "retrieve_",
value: function () {
var _retrieve_ = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(selector, config) {
var ethnicitiesHaveReferencesRepo, query, ethnicitiesHaveReferences;
return _regenerator["default"].wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
ethnicitiesHaveReferencesRepo = this.activeManager_.withRepository(this.ethnicitiesHaveReferencesRepository_);
query = (0, _medusa.buildQuery)(selector, config);
_context3.next = 4;
return ethnicitiesHaveReferencesRepo.findOne(query);
case 4:
ethnicitiesHaveReferences = _context3.sent;
return _context3.abrupt("return", ethnicitiesHaveReferences);
case 6:
case "end":
return _context3.stop();
}
}, _callee3, this);
}));
function retrieve_(_x3, _x4) {
return _retrieve_.apply(this, arguments);
}
return retrieve_;
}()
}, {
key: "create",
value: function () {
var _create = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(ethnicitiesHaveReferencesObject) {
var _this2 = this;
return _regenerator["default"].wrap(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return this.atomicPhase_( /*#__PURE__*/function () {
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(manager) {
var ethnicitiesHaveReferencesRepo, ethnicitiesHaveReferences, result;
return _regenerator["default"].wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
ethnicitiesHaveReferencesRepo = manager.withRepository(_this2.ethnicitiesHaveReferencesRepository_);
_context4.prev = 1;
ethnicitiesHaveReferences = ethnicitiesHaveReferencesRepo.create(ethnicitiesHaveReferencesObject);
_context4.next = 5;
return ethnicitiesHaveReferencesRepo.save(ethnicitiesHaveReferences);
case 5:
ethnicitiesHaveReferences = _context4.sent;
_context4.next = 8;
return _this2.retrieve_({
ethnicity_id: ethnicitiesHaveReferences.ethnicity_id,
reference_id: ethnicitiesHaveReferences.reference_id
}, {
relations: []
});
case 8:
result = _context4.sent;
_context4.next = 11;
return _this2.eventBus_.withTransaction(manager).emit(EthnicitiesHaveReferencesService.Events.CREATED, {
ethnicity_id: ethnicitiesHaveReferences.ethnicity_id,
reference_id: ethnicitiesHaveReferences.reference_id
});
case 11:
return _context4.abrupt("return", result);
case 14:
_context4.prev = 14;
_context4.t0 = _context4["catch"](1);
throw (0, _medusa.formatException)(_context4.t0);
case 17:
case "end":
return _context4.stop();
}
}, _callee4, null, [[1, 14]]);
}));
return function (_x6) {
return _ref2.apply(this, arguments);
};
}());
case 2:
return _context5.abrupt("return", _context5.sent);
case 3:
case "end":
return _context5.stop();
}
}, _callee5, this);
}));
function create(_x5) {
return _create.apply(this, arguments);
}
return create;
}()
}, {
key: "delete",
value: function () {
var _delete2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(ethnicityId, referenceId) {
var _this3 = this;
return _regenerator["default"].wrap(function _callee7$(_context7) {
while (1) switch (_context7.prev = _context7.next) {
case 0:
_context7.next = 2;
return this.atomicPhase_( /*#__PURE__*/function () {
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(manager) {
var ethnicitiesHaveReferencesRepo, ethnicitiesHaveReferences;
return _regenerator["default"].wrap(function _callee6$(_context6) {
while (1) switch (_context6.prev = _context6.next) {
case 0:
ethnicitiesHaveReferencesRepo = manager.withRepository(_this3.ethnicitiesHaveReferencesRepository_);
_context6.next = 3;
return ethnicitiesHaveReferencesRepo.findOne({
where: {
ethnicity_id: ethnicityId,
reference_id: referenceId
}
});
case 3:
ethnicitiesHaveReferences = _context6.sent;
if (ethnicitiesHaveReferences) {
_context6.next = 6;
break;
}
return _context6.abrupt("return");
case 6:
_context6.next = 8;
return ethnicitiesHaveReferencesRepo["delete"](ethnicitiesHaveReferences);
case 8:
_context6.next = 10;
return _this3.eventBus_.withTransaction(manager).emit(EthnicitiesHaveReferencesService.Events.DELETED, {
ethnicity_id: ethnicityId,
reference_id: referenceId
});
case 10:
return _context6.abrupt("return", Promise.resolve());
case 11:
case "end":
return _context6.stop();
}
}, _callee6);
}));
return function (_x9) {
return _ref3.apply(this, arguments);
};
}());
case 2:
return _context7.abrupt("return", _context7.sent);
case 3:
case "end":
return _context7.stop();
}
}, _callee7, this);
}));
function _delete(_x7, _x8) {
return _delete2.apply(this, arguments);
}
return _delete;
}()
}]);
}(_medusa.TransactionBaseService);
// eslint-disable-next-line max-len
(0, _defineProperty2["default"])(EthnicitiesHaveReferencesService, "IndexName", "ethnicities-have-references");
(0, _defineProperty2["default"])(EthnicitiesHaveReferencesService, "Events", {
CREATED: "ethnicities-have-references.created",
DELETED: "ethnicities-have-references.deleted"
});
var _default = exports["default"] = EthnicitiesHaveReferencesService;