Skip to content

Commit

Permalink
feat(apis): add option to work without save ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreBrisorgueil committed Mar 18, 2020
1 parent a53082f commit ee88134
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/apis/models/apis.model.mongoose.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const ApiMongoose = new Schema({
status: Boolean,
banner: String,
description: String,
savedb: Boolean,
user: {
type: Schema.ObjectId,
ref: 'User',
Expand Down
1 change: 1 addition & 0 deletions modules/apis/models/apis.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 3 additions & 1 deletion modules/apis/services/apis.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit ee88134

Please sign in to comment.