Skip to content

Commit

Permalink
feat(apis): add slug ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreBrisorgueil committed Mar 17, 2020
1 parent 6155968 commit 7ccb023
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions modules/apis/models/apis.model.mongoose.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const ApiMongoose = new Schema({
type: String,
unique: 'Title already exists',
},
slug: {
type: String,
unique: 'slug already exists',
},
url: String,
auth: String,
serviceId: String,
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 @@ -12,6 +12,7 @@ const Joi = PlainJoi.extend(joiZxcvbn(PlainJoi));
*/
const ApiSchema = Joi.object().keys({
title: Joi.string().trim().default('').required(),
slug: Joi.string().trim().optional(),
url: Joi.string().trim().required(),
auth: Joi.string().valid(['lou']).required(),
serviceId: Joi.string().trim().default('').required(),
Expand Down
3 changes: 2 additions & 1 deletion modules/apis/services/apis.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ exports.get = async (id) => {
*/
exports.update = async (api, body) => {
api.title = body.title;
api.slug = _.camelCase(body.title);
api.url = body.url;
api.auth = body.auth;
api.serviceId = body.serviceId;
Expand Down Expand Up @@ -116,7 +117,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(_.camelCase(api.title), result.result);
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 7ccb023

Please sign in to comment.