Replaced i18n with tpl in accept.js (#13471)

refs: #13380

- The i18n package is deprecated. It is being replaced with the tpl package.
This commit is contained in:
PJ 2021-10-09 01:21:22 +11:00 committed by GitHub
parent 940d10fc3b
commit 684721b1bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,14 @@
const errors = require('@tryghost/errors');
const i18n = require('../../../shared/i18n');
const tpl = require('@tryghost/tpl');
const models = require('../../models');
const security = require('@tryghost/security');
const messages = {inviteNotFound: 'Invite not found.',
inviteExpired: 'Invite is expired.',
inviteEmailAlreadyExist: {
message: 'Could not create an account, email is already in use.',
context: 'Attempting to create an account with existing email address.',
help: 'Use different email address to register your account.'
}};
async function accept(invitation) {
const data = invitation.invitation[0];
@ -11,19 +18,19 @@ async function accept(invitation) {
let invite = await models.Invite.findOne({token: inviteToken, status: 'sent'}, options);
if (!invite) {
throw new errors.NotFoundError({message: i18n.t('errors.api.invites.inviteNotFound')});
throw new errors.NotFoundError({message: tpl(messages.inviteNotFound)});
}
if (invite.get('expires') < Date.now()) {
throw new errors.NotFoundError({message: i18n.t('errors.api.invites.inviteExpired')});
throw new errors.NotFoundError({message: tpl(messages.inviteExpired)});
}
let user = await models.User.findOne({email: data.email});
if (user) {
throw new errors.ValidationError({
message: i18n.t('errors.api.invites.inviteEmailAlreadyExist.message'),
context: i18n.t('errors.api.invites.inviteEmailAlreadyExist.context'),
help: i18n.t('errors.api.invites.inviteEmailAlreadyExist.help')
message: tpl(messages.inviteEmailAlreadyExist.message),
context: tpl(messages.inviteEmailAlreadyExist.context),
help: tpl(messages.inviteEmailAlreadyExist.help)
});
}