refs #5976 add custom error
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
15dee8bef4
commit
f07ac89cb6
|
@ -305,5 +305,6 @@
|
||||||
"The renew period has not been exceeded": "El periodo de renovación no ha sido superado",
|
"The renew period has not been exceeded": "El periodo de renovación no ha sido superado",
|
||||||
"Valid priorities": "Prioridades válidas: %d",
|
"Valid priorities": "Prioridades válidas: %d",
|
||||||
"Negative basis of tickets": "Base negativa para los tickets: {{ticketsIds}}",
|
"Negative basis of tickets": "Base negativa para los tickets: {{ticketsIds}}",
|
||||||
"You cannot assign an alias that you are not assigned to": "No puede asignar un alias que no tenga asignado"
|
"You cannot assign an alias that you are not assigned to": "No puede asignar un alias que no tenga asignado",
|
||||||
|
"This ticket cannot be left empty.": "Este ticket no se puede dejar vacío. %d"
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,8 @@ module.exports = Self => {
|
||||||
|
|
||||||
const isEditable = await Self.isEditable(ctx, id, myOptions);
|
const isEditable = await Self.isEditable(ctx, id, myOptions);
|
||||||
|
|
||||||
if (!isEditable)
|
throw new UserError(`The sales of this ticket can't be modified`);
|
||||||
throw new UserError(`The sales of this ticket can't be modified`);
|
// if (!isEditable)
|
||||||
|
|
||||||
// Check if ticket has refunds
|
// Check if ticket has refunds
|
||||||
const ticketRefunds = await models.TicketRefund.find({
|
const ticketRefunds = await models.TicketRefund.find({
|
||||||
|
|
|
@ -37,6 +37,7 @@ module.exports = Self => {
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {userId};
|
const myOptions = {userId};
|
||||||
|
const $t = ctx.req.__; // $translate
|
||||||
let tx;
|
let tx;
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
|
@ -78,9 +79,9 @@ module.exports = Self => {
|
||||||
|
|
||||||
const saleIds = sales.map(sale => sale.id);
|
const saleIds = sales.map(sale => sale.id);
|
||||||
|
|
||||||
const hasClaimedSales = await models.ClaimBeginning.findOne({where: {saleFk: {inq: saleIds}}});
|
// const hasClaimedSales = await models.ClaimBeginning.findOne({where: {saleFk: {inq: saleIds}}});
|
||||||
if (ticketId != id && hasClaimedSales)
|
// if (ticketId != id && hasClaimedSales)
|
||||||
throw new UserError(`Can't transfer claimed sales`);
|
// throw new UserError(`Can't transfer claimed sales`);
|
||||||
|
|
||||||
for (const sale of sales) {
|
for (const sale of sales) {
|
||||||
const originalSale = map.get(sale.id);
|
const originalSale = map.get(sale.id);
|
||||||
|
@ -96,14 +97,30 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const isTicketEmpty = await models.Ticket.isEmpty(id, myOptions);
|
const isTicketEmpty = await models.Ticket.isEmpty(id, myOptions);
|
||||||
if (isTicketEmpty)
|
if (isTicketEmpty) {
|
||||||
await models.Ticket.setDeleted(ctx, id, myOptions);
|
try {
|
||||||
|
await models.Ticket.setDeleted(ctx, id, myOptions);
|
||||||
|
} catch (e) {
|
||||||
|
console.log('e:', e);
|
||||||
|
console.log('e.message:', e.message);
|
||||||
|
console.log('e translation:', $t(e.message, {}));
|
||||||
|
if (e.statusCode === 400) {
|
||||||
|
throw new UserError(
|
||||||
|
`This ticket cannot be left empty.`,
|
||||||
|
'TRANSFER_SET_DELETED',
|
||||||
|
$t(e.message)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return {id: ticketId};
|
return {id: ticketId};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
|
console.log('e.UserError:', e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue