UNPKG

@batolye/bdk-core

Version:

Module to provide core utilities for BulusAtolyesi applications and services

72 lines (61 loc) 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createTagService = createTagService; exports.removeTagService = removeTagService; exports.createStorageService = createStorageService; exports.removeStorageService = removeStorageService; var _multer = _interopRequireDefault(require("multer")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const multipart = (0, _multer.default)().single("file"); function createTagService(zone, db) { const app = this; app.core_createService("tags", { servicesPath, modelsPath, zone, db }); } function removeTagService(zone) {// TODO } function proxyStorageId(zone) { return id => { if (!zone) return id; const prefix = (typeof zone === "object" ? zone._id.toString() : zone) + "/"; // Check if zone is already in ID, in this case we have to remove it on output if (id.startsWith(prefix)) return id.replace(prefix, ""); // Otherwise we have to add it on input else return prefix + id; }; } function createStorageService(blobService, zone) { const app = this; // Closure to keep track of zone const proxyId = proxyStorageId(zone); app.core_createService("storage", { servicesPath, modelsPath, zone, // Create a proxy on top of a Feathers blob service, // adding zone as prefix on all keys on input // removing zone as prefix on all keys as result proxy: { service: blobService, id: proxyId, data: data => data.id ? Object.assign(data, { id: proxyId(data.id) }) : data, result: data => data._id ? Object.assign(data, { _id: proxyId(data._id) }) : data }, // Add required middlewares to handle multipart form data middlewares: { before: [multipart, (req, res, next) => { req.feathers.file = req.file; next(); }] } }); } function removeStorageService(zone) {// TODO }