2021-01-04 22:01:37 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const _ = require('lodash');
|
2021-02-15 11:27:01 +01:00
|
|
|
const pluralize = require('pluralize');
|
2021-02-15 11:24:28 +01:00
|
|
|
const { getService } = require('../../utils');
|
2021-01-04 22:01:37 +01:00
|
|
|
|
|
|
|
module.exports = () => {
|
2021-03-11 16:19:49 +01:00
|
|
|
Object.values(strapi.contentTypes).forEach(model => {
|
2021-02-15 11:24:28 +01:00
|
|
|
if (getService('content-types').isLocalized(model)) {
|
2021-01-04 22:01:37 +01:00
|
|
|
_.set(model.attributes, 'localizations', {
|
2021-03-12 14:34:04 +01:00
|
|
|
writable: true,
|
2021-01-04 22:01:37 +01:00
|
|
|
private: false,
|
|
|
|
configurable: false,
|
2021-03-12 14:34:04 +01:00
|
|
|
visible: false,
|
2021-03-05 15:43:48 +01:00
|
|
|
collection: model.modelName,
|
|
|
|
populate: ['id', 'locale', 'published_at'],
|
2021-01-04 22:01:37 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
_.set(model.attributes, 'locale', {
|
2021-03-12 14:34:04 +01:00
|
|
|
writable: true,
|
2021-01-04 22:01:37 +01:00
|
|
|
private: false,
|
|
|
|
configurable: false,
|
2021-03-12 14:34:04 +01:00
|
|
|
visible: false,
|
2021-01-04 22:01:37 +01:00
|
|
|
type: 'string',
|
|
|
|
});
|
2021-02-15 11:27:01 +01:00
|
|
|
|
|
|
|
// add new route
|
|
|
|
const route =
|
|
|
|
model.kind === 'singleType'
|
|
|
|
? _.kebabCase(model.modelName)
|
|
|
|
: _.kebabCase(pluralize(model.modelName));
|
|
|
|
|
|
|
|
const localizationRoutes = [
|
|
|
|
{
|
|
|
|
method: 'POST',
|
|
|
|
path: `/${route}/:id/localizations`,
|
|
|
|
handler: `${model.modelName}.createLocalization`,
|
|
|
|
config: {
|
|
|
|
policies: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const handler = function(ctx) {
|
|
|
|
ctx.body = 'works';
|
|
|
|
};
|
|
|
|
|
|
|
|
strapi.config.routes.push(...localizationRoutes);
|
|
|
|
|
|
|
|
_.set(
|
|
|
|
strapi,
|
|
|
|
`api.${model.apiName}.controllers.${model.modelName}.createLocalization`,
|
|
|
|
handler
|
|
|
|
);
|
2021-01-04 22:01:37 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-02-12 12:52:29 +01:00
|
|
|
strapi.db.migrations.register({
|
2021-02-15 08:43:59 +01:00
|
|
|
before() {},
|
|
|
|
after() {},
|
2021-02-12 12:52:29 +01:00
|
|
|
});
|
2021-01-04 22:01:37 +01:00
|
|
|
};
|