Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Publish 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aradjdi committed Feb 5, 2021
1 parent a816b5c commit 2141eb8
Show file tree
Hide file tree
Showing 48 changed files with 3,517 additions and 17,779 deletions.
709 changes: 0 additions & 709 deletions -exports/graphql/schema.graphql

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.env

############################
# OS X
############################
Expand Down
5 changes: 5 additions & 0 deletions .strapi-updater.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"latest": "3.3.4",
"lastUpdateCheck": 1607681407609,
"lastNotification": 1607681528834
}
2 changes: 1 addition & 1 deletion api/parcours/config/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{
"method": "DELETE",
"path": "/parcours/:id",
"handler": "Parcours.destroy",
"handler": "Parcours.delete",
"config": {
"policies": []
}
Expand Down
1 change: 0 additions & 1 deletion api/parcours/config/schema.graphql

This file was deleted.

72 changes: 3 additions & 69 deletions api/parcours/controllers/Parcours.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,8 @@
'use strict';

/**
* Parcours.js controller
*
* @description: A set of functions called "actions" for managing `Parcours`.
* Read the documentation (https://strapi.io/documentation/3.0.0-beta.x/concepts/controllers.html#core-controllers)
* to customize this controller
*/

module.exports = {

/**
* Retrieve parcours records.
*
* @return {Object|Array}
*/

find: async (ctx, next, { populate } = {}) => {
if (ctx.query._q) {
return strapi.services.parcours.search(ctx.query);
} else {
return strapi.services.parcours.fetchAll(ctx.query, populate);
}
},

/**
* Retrieve a parcours record.
*
* @return {Object}
*/

findOne: async (ctx) => {
return strapi.services.parcours.fetch(ctx.params);
},

/**
* Count parcours records.
*
* @return {Number}
*/

count: async (ctx, next, { populate } = {}) => {
return strapi.services.parcours.count(ctx.query, populate);
},

/**
* Create a/an parcours record.
*
* @return {Object}
*/

create: async (ctx) => {
return strapi.services.parcours.add(ctx.request.body);
},

/**
* Update a/an parcours record.
*
* @return {Object}
*/

update: async (ctx, next) => {
return strapi.services.parcours.edit(ctx.params, ctx.request.body) ;
},

/**
* Destroy a/an parcours record.
*
* @return {Object}
*/

destroy: async (ctx, next) => {
return strapi.services.parcours.remove(ctx.params);
}
};
module.exports = {};
206 changes: 3 additions & 203 deletions api/parcours/services/Parcours.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,208 +2,8 @@
'use strict';

/**
* Parcours.js service
*
* @description: A set of functions similar to controller's actions to avoid code duplication.
* Read the documentation (https://strapi.io/documentation/3.0.0-beta.x/guides/services.html#core-services)
* to customize this service
*/

// Public dependencies.
const _ = require('lodash');

// Strapi utilities.
// const utils = require('strapi-hook-bookshelf/lib/utils/');
const { convertRestQueryParams, buildQuery } = require('strapi-utils');


module.exports = {

/**
* Promise to fetch all parcours.
*
* @return {Promise}
*/

fetchAll: (params, populate) => {
// Select field to populate.
const withRelated = populate || Parcours.associations
.filter(ast => ast.autoPopulate !== false)
.map(ast => ast.alias);

const filters = convertRestQueryParams(params);

return Parcours.query(buildQuery({ model: Parcours, filters }))
.fetchAll({ withRelated })
.then(data => data.toJSON());
},

/**
* Promise to fetch a/an parcours.
*
* @return {Promise}
*/

fetch: (params) => {
// Select field to populate.
const populate = Parcours.associations
.filter(ast => ast.autoPopulate !== false)
.map(ast => ast.alias);

return Parcours.forge(_.pick(params, 'id')).fetch({
withRelated: populate
});
},

/**
* Promise to count a/an parcours.
*
* @return {Promise}
*/

count: (params) => {
// Convert `params` object to filters compatible with Bookshelf.
const filters = convertRestQueryParams(params);

return Parcours.query(buildQuery({ model: Parcours, filters: _.pick(filters, 'where') })).count();
},

/**
* Promise to add a/an parcours.
*
* @return {Promise}
*/

add: async (values) => {
// Extract values related to relational data.
const relations = _.pick(values, Parcours.associations.map(ast => ast.alias));
const data = _.omit(values, Parcours.associations.map(ast => ast.alias));

// Create entry with no-relational data.
const entry = await Parcours.forge(data).save();

// Create relational data and return the entry.
return Parcours.updateRelations({ id: entry.id , values: relations });
},

/**
* Promise to edit a/an parcours.
*
* @return {Promise}
*/

edit: async (params, values) => {
// Extract values related to relational data.
const relations = _.pick(values, Parcours.associations.map(ast => ast.alias));
const data = _.omit(values, Parcours.associations.map(ast => ast.alias));

// Create entry with no-relational data.
const entry = await Parcours.forge(params).save(data);

// Create relational data and return the entry.
return Parcours.updateRelations(Object.assign(params, { values: relations }));
},

/**
* Promise to remove a/an parcours.
*
* @return {Promise}
*/

remove: async (params) => {
params.values = {};
Parcours.associations.map(association => {
switch (association.nature) {
case 'oneWay':
case 'oneToOne':
case 'manyToOne':
case 'oneToManyMorph':
params.values[association.alias] = null;
break;
case 'oneToMany':
case 'manyToMany':
case 'manyToManyMorph':
params.values[association.alias] = [];
break;
default:
}
});

await Parcours.updateRelations(params);

return Parcours.forge(params).destroy();
},

/**
* Promise to search a/an parcours.
*
* @return {Promise}
*/

search: async (params) => {
// Convert `params` object to filters compatible with Bookshelf.
const filters = strapi.utils.models.convertParams('parcours', params);
// Select field to populate.
const populate = Parcours.associations
.filter(ast => ast.autoPopulate !== false)
.map(ast => ast.alias);

const associations = Parcours.associations.map(x => x.alias);
const searchText = Object.keys(Parcours._attributes)
.filter(attribute => attribute !== Parcours.primaryKey && !associations.includes(attribute))
.filter(attribute => ['string', 'text'].includes(Parcours._attributes[attribute].type));

const searchInt = Object.keys(Parcours._attributes)
.filter(attribute => attribute !== Parcours.primaryKey && !associations.includes(attribute))
.filter(attribute => ['integer', 'decimal', 'float'].includes(Parcours._attributes[attribute].type));

const searchBool = Object.keys(Parcours._attributes)
.filter(attribute => attribute !== Parcours.primaryKey && !associations.includes(attribute))
.filter(attribute => ['boolean'].includes(Parcours._attributes[attribute].type));

const query = (params._q || '').replace(/[^a-zA-Z0-9.-\s]+/g, '');

return Parcours.query(qb => {
if (!_.isNaN(_.toNumber(query))) {
searchInt.forEach(attribute => {
qb.orWhereRaw(`${attribute} = ${_.toNumber(query)}`);
});
}

if (query === 'true' || query === 'false') {
searchBool.forEach(attribute => {
qb.orWhereRaw(`${attribute} = ${_.toNumber(query === 'true')}`);
});
}

// Search in columns with text using index.
switch (Parcours.client) {
case 'mysql':
qb.orWhereRaw(`MATCH(${searchText.join(',')}) AGAINST(? IN BOOLEAN MODE)`, `*${query}*`);
break;
case 'pg': {
const searchQuery = searchText.map(attribute =>
_.toLower(attribute) === attribute
? `to_tsvector(${attribute})`
: `to_tsvector('${attribute}')`
);

qb.orWhereRaw(`${searchQuery.join(' || ')} @@ to_tsquery(?)`, query);
break;
}
}

if (filters.sort) {
qb.orderBy(filters.sort.key, filters.sort.order);
}

if (filters.skip) {
qb.offset(_.toNumber(filters.skip));
}

if (filters.limit) {
qb.limit(_.toNumber(filters.limit));
}
}).fetchAll({
withRelated: populate
});
}
};
module.exports = {};
10 changes: 0 additions & 10 deletions config/application.json

This file was deleted.

3 changes: 0 additions & 3 deletions config/custom.json

This file was deleted.

17 changes: 17 additions & 0 deletions config/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = ({ env }) => ({
defaultConnection: 'default',
connections: {
default: {
connector: 'bookshelf',
settings: {
client: 'mysql',
host: env('DATABASE_HOST'),
port: env.int('DATABASE_PORT'),
database: env('DATABASE_NAME'),
username: env('DATABASE_USERNAME'),
password: env('DATABASE_PASSWORD'),
},
options: {},
},
},
});
3 changes: 0 additions & 3 deletions config/environments/development/custom.json

This file was deleted.

17 changes: 0 additions & 17 deletions config/environments/development/database.json

This file was deleted.

23 changes: 0 additions & 23 deletions config/environments/development/request.json

This file was deleted.

Loading

0 comments on commit 2141eb8

Please sign in to comment.