mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Removed use of i18n in snippets controllers
no issue - i18n is deprecated in favour of `tpl` - normalized method syntax so `add` matches the rest of the controller's methods (fixed a complexity warning but was not the primary intention)
This commit is contained in:
parent
810b052e01
commit
e5db28db00
3 changed files with 34 additions and 30 deletions
|
@ -1,8 +1,13 @@
|
|||
const Promise = require('bluebird');
|
||||
const i18n = require('../../../shared/i18n');
|
||||
const errors = require('@tryghost/errors');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
const models = require('../../models');
|
||||
|
||||
const messages = {
|
||||
snippetNotFound: 'Snippet not found.',
|
||||
snippetAlreadyExists: 'Snippet already exists.'
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
docName: 'snippets',
|
||||
|
||||
|
@ -29,7 +34,7 @@ module.exports = {
|
|||
.then((model) => {
|
||||
if (!model) {
|
||||
return Promise.reject(new errors.NotFoundError({
|
||||
message: i18n.t('errors.api.snippets.snippetNotFound')
|
||||
message: tpl(messages.snippetNotFound)
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -42,16 +47,15 @@ module.exports = {
|
|||
statusCode: 201,
|
||||
headers: {},
|
||||
permissions: true,
|
||||
async query(frame) {
|
||||
try {
|
||||
return await models.Snippet.add(frame.data.snippets[0], frame.options);
|
||||
} catch (error) {
|
||||
if (error.code && error.message.toLowerCase().indexOf('unique') !== -1) {
|
||||
throw new errors.ValidationError({message: i18n.t('errors.api.snippets.snippetAlreadyExists')});
|
||||
}
|
||||
query(frame) {
|
||||
return models.Snippet.add(frame.data.snippets[0], frame.options)
|
||||
.catch((error) => {
|
||||
if (error.code && error.message.toLowerCase().indexOf('unique') !== -1) {
|
||||
throw new errors.ValidationError({message: tpl(messages.snippetAlreadyExists)});
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -73,7 +77,7 @@ module.exports = {
|
|||
.then((model) => {
|
||||
if (!model) {
|
||||
return Promise.reject(new errors.NotFoundError({
|
||||
message: i18n.t('errors.api.snippets.snippetNotFound')
|
||||
message: tpl(messages.snippetNotFound)
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -103,7 +107,7 @@ module.exports = {
|
|||
.then(() => null)
|
||||
.catch(models.Snippet.NotFoundError, () => {
|
||||
return Promise.reject(new errors.NotFoundError({
|
||||
message: i18n.t('errors.api.snippets.snippetNotFound')
|
||||
message: tpl(messages.snippetNotFound)
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
const Promise = require('bluebird');
|
||||
const i18n = require('../../../shared/i18n');
|
||||
const errors = require('@tryghost/errors');
|
||||
const tpl = require('@tryghost/tpl');
|
||||
const models = require('../../models');
|
||||
|
||||
const messages = {
|
||||
snippetNotFound: 'Snippet not found.',
|
||||
snippetAlreadyExists: 'Snippet already exists.'
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
docName: 'snippets',
|
||||
|
||||
|
@ -29,7 +34,7 @@ module.exports = {
|
|||
.then((model) => {
|
||||
if (!model) {
|
||||
return Promise.reject(new errors.NotFoundError({
|
||||
message: i18n.t('errors.api.snippets.snippetNotFound')
|
||||
message: tpl(messages.snippetNotFound)
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -42,16 +47,15 @@ module.exports = {
|
|||
statusCode: 201,
|
||||
headers: {},
|
||||
permissions: true,
|
||||
async query(frame) {
|
||||
try {
|
||||
return await models.Snippet.add(frame.data.snippets[0], frame.options);
|
||||
} catch (error) {
|
||||
if (error.code && error.message.toLowerCase().indexOf('unique') !== -1) {
|
||||
throw new errors.ValidationError({message: i18n.t('errors.api.snippets.snippetAlreadyExists')});
|
||||
}
|
||||
query(frame) {
|
||||
return models.Snippet.add(frame.data.snippets[0], frame.options)
|
||||
.catch((error) => {
|
||||
if (error.code && error.message.toLowerCase().indexOf('unique') !== -1) {
|
||||
throw new errors.ValidationError({message: tpl(messages.snippetAlreadyExists)});
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -73,7 +77,7 @@ module.exports = {
|
|||
.then((model) => {
|
||||
if (!model) {
|
||||
return Promise.reject(new errors.NotFoundError({
|
||||
message: i18n.t('errors.api.snippets.snippetNotFound')
|
||||
message: tpl(messages.snippetNotFound)
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -103,7 +107,7 @@ module.exports = {
|
|||
.then(() => null)
|
||||
.catch(models.Snippet.NotFoundError, () => {
|
||||
return Promise.reject(new errors.NotFoundError({
|
||||
message: i18n.t('errors.api.snippets.snippetNotFound')
|
||||
message: tpl(messages.snippetNotFound)
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -505,10 +505,6 @@
|
|||
"HostLimitError": "Host Limit error, cannot {action}.",
|
||||
"DisabledFeatureError": "Theme validation error, the {{{helperName}}} helper is not available. Cannot {action}.",
|
||||
"UpdateCollisionError": "Saving failed! Someone else is editing this post."
|
||||
},
|
||||
"snippets": {
|
||||
"snippetNotFound": "Snippet not found.",
|
||||
"snippetAlreadyExists": "Snippet already exists"
|
||||
}
|
||||
},
|
||||
"data": {
|
||||
|
|
Loading…
Add table
Reference in a new issue