diff --git a/modules/ticket/back/methods/ticket/restore.js b/modules/ticket/back/methods/ticket/restore.js
new file mode 100644
index 000000000..c455484b0
--- /dev/null
+++ b/modules/ticket/back/methods/ticket/restore.js
@@ -0,0 +1,58 @@
+const UserError = require('vn-loopback/util/user-error');
+
+module.exports = Self => {
+ Self.remoteMethodCtx('restore', {
+ description: 'Restores a ticket within the first hour of deletion',
+ accessType: 'WRITE',
+ accepts: [{
+ arg: 'id',
+ type: 'Number',
+ required: true,
+ description: 'The ticket id',
+ http: {source: 'path'}
+ }],
+ returns: {
+ type: 'string',
+ root: true
+ },
+ http: {
+ path: `/:id/restore`,
+ verb: 'post'
+ }
+ });
+
+ Self.restore = async(ctx, id) => {
+ const models = Self.app.models;
+ const userId = ctx.req.accessToken.userId;
+ const isEditable = await Self.isEditable(ctx, id);
+ const $t = ctx.req.__; // $translate
+
+ /* if (!isEditable)
+ throw new UserError(`The sales of this ticket can't be modified`);
+ */
+ // Check if has sales with shelving
+ // const isSalesAssistant = await models.Account.hasRole(userId, 'salesAssistant');
+
+ const ticket = await models.Ticket.findById(id, {
+ include: [{
+ relation: 'client',
+ scope: {
+ fields: ['id', 'salesPersonFk']
+ }
+ }]
+ });
+
+ // Send notification to salesPerson
+ const salesPersonId = ticket.client().salesPersonFk;
+ if (salesPersonId) {
+ const origin = ctx.req.headers.origin;
+ const message = $t(`Has restored the ticket id`, {
+ id: id,
+ url: `${origin}/#!/ticket/${id}/summary`
+ });
+ await models.Chat.sendCheckingPresence(ctx, salesPersonId, message);
+ }
+
+ return ticket.updateAttribute('isDeleted', false);
+ };
+};
diff --git a/modules/ticket/back/methods/ticket/setDeleted.js b/modules/ticket/back/methods/ticket/setDeleted.js
index 208333aad..ed71524d0 100644
--- a/modules/ticket/back/methods/ticket/setDeleted.js
+++ b/modules/ticket/back/methods/ticket/setDeleted.js
@@ -102,7 +102,7 @@ module.exports = Self => {
}]
});
- // Change state to "fixing" if contains an stowaway and removed the link between them
+ // Change state to "fixing" if contains an stowaway and remove the link between them
let otherTicketId;
if (ticket.stowaway())
otherTicketId = ticket.stowaway().shipFk;
diff --git a/modules/ticket/front/descriptor/index.html b/modules/ticket/front/descriptor/index.html
index c24b4c843..7758bfc8b 100644
--- a/modules/ticket/front/descriptor/index.html
+++ b/modules/ticket/front/descriptor/index.html
@@ -28,6 +28,13 @@
translate>
Delete ticket
+
+ Restore ticket
+
+
+
{
+ this.vnApp.showSuccess(this.$t('Ticket restored'));
+ this.cardReload();
+ });
+ }
+
canStowaway() {
this.canShowStowaway = false;
if (!this.isTicketModule || !this.ticket) return;