diff --git a/modules/apis/models/apis.model.mongoose.js b/modules/apis/models/apis.model.mongoose.js index e2d7a290..d1314b69 100644 --- a/modules/apis/models/apis.model.mongoose.js +++ b/modules/apis/models/apis.model.mongoose.js @@ -26,6 +26,7 @@ const ApiMongoose = new Schema({ status: Boolean, banner: String, description: String, + savedb: Boolean, user: { type: Schema.ObjectId, ref: 'User', diff --git a/modules/apis/models/apis.schema.js b/modules/apis/models/apis.schema.js index c561dc3d..c9865591 100644 --- a/modules/apis/models/apis.schema.js +++ b/modules/apis/models/apis.schema.js @@ -25,6 +25,7 @@ const ApiSchema = Joi.object().keys({ description: Joi.string().allow('').default('').optional(), user: Joi.string().trim().default(''), history: Joi.array().items(historySchema).optional(), + savedb: Joi.boolean().default(false).optional(), }); module.exports = { diff --git a/modules/apis/services/apis.service.js b/modules/apis/services/apis.service.js index 37f515f3..4a461437 100644 --- a/modules/apis/services/apis.service.js +++ b/modules/apis/services/apis.service.js @@ -29,6 +29,7 @@ exports.list = async () => { */ exports.create = async (api, user) => { api.user = user.id; + api.slug = _.camelCase(api.title); if (api.password) api.password = await UserService.hashPassword(api.password); const result = await ApisRepository.create(api); return Promise.resolve(result); @@ -59,6 +60,7 @@ exports.update = async (api, body) => { api.params = body.params; api.status = body.status; api.banner = body.banner; + api.savedb = body.savedb; api.description = body.description; if (body.typing && body.typing !== '') api.typing = body.typing; else api.typing = null; @@ -117,7 +119,7 @@ exports.load = async (api) => { result.prepare = montaineSave.prepare(result.result, start); result.mongo = montaineSave.save(result.prepare, start); result.result = result.mongo; - result.result = await ApisRepository.import(api.slug, result.result); + if (api.savedb) result.result = await ApisRepository.import(api.slug, result.result); } const history = await HistoryRepository.create(montaineRequest.setScrapHistory(result.request, api, start));