Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
schema.created = function() {
this.adapter = adapter || new MemoryAdapter();
this.adapter.init(this.broker, this);
this.$fields = null;
if (_.isObject(this.settings.fields)) {
this.$fields = _.compact(_.map(this.settings.fields, (value, name) => {
// Disabled field
if (value === false)
return;
// Shorthand format { title: true } => { title: {} }
if (value === true)
value = {};
// Shorthand format: { title: "string" } => { title: { type: "string" } }
"use strict";
const { MoleculerClientError } = require("moleculer").Errors;
const { ForbiddenError } = require("moleculer-web").Errors;
const _ = require("lodash");
const slug = require("slug");
const DbService = require("moleculer-db");
module.exports = {
name: "articles",
mixins: [DbService],
adapter: new DbService.MemoryAdapter({ filename: "./data/articles.db" }),
/**
* Default settings
*/
settings: {
fields: ["_id", "title", "slug", "description", "body", "tagList", "createdAt", "updatedAt", "favorited", "favoritesCount", "author", "comments"],
// Populates
populates: {
author: {
action: "users.get",
params: {
fields: ["username", "bio", "image"]
}
},
comments: {
return {
mixins: [DbService],
adapter: new MongoAdapter(process.env.MONGO_URI),
collection
};
}
// --- NeDB fallback DB adapter
// Create data folder
mkdir(path.resolve("./data"));
return {
mixins: [DbService],
adapter: new DbService.MemoryAdapter({ filename: `./data/${collection}.db` })
};
};
"use strict";
const { MoleculerClientError } = require("moleculer").Errors;
const DbService = require("moleculer-db");
module.exports = {
name: "follows",
mixins: [DbService],
adapter: new DbService.MemoryAdapter({ filename: "./data/follows.db" }),
/**
* Default settings
*/
settings: {
},
/**
* Actions
*/
actions: {
/**
* Create a new following record
*
"use strict";
const { ForbiddenError } = require("moleculer-web").Errors;
const DbService = require("moleculer-db");
module.exports = {
name: "comments",
mixins: [DbService],
adapter: new DbService.MemoryAdapter({ filename: "./data/comments.db" }),
/**
* Default settings
*/
settings: {
fields: ["_id", "author", "article", "body", "createdAt", "updatedAt"],
populates: {
"author": {
action: "users.get",
params: {
fields: ["_id", "username", "bio", "image"]
}
}
},
entityValidator: {
article: { type: "string" },
"use strict";
const { MoleculerClientError } = require("moleculer").Errors;
const DbService = require("moleculer-db");
module.exports = {
name: "favorites",
mixins: [DbService],
adapter: new DbService.MemoryAdapter({ filename: "./data/favorites.db" }),
/**
* Default settings
*/
settings: {
},
/**
* Actions
*/
actions: {
/**
* Create a new favorite record
*
entityNotFoundHook(ctx) {
if (!ctx.locals.entity)
return Promise.reject(new EntityNotFoundError(ctx.locals.entityID));
},