2473 - Added restore method
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
61872dec43
commit
eceb33cce0
|
@ -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);
|
||||||
|
};
|
||||||
|
};
|
|
@ -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;
|
let otherTicketId;
|
||||||
if (ticket.stowaway())
|
if (ticket.stowaway())
|
||||||
otherTicketId = ticket.stowaway().shipFk;
|
otherTicketId = ticket.stowaway().shipFk;
|
||||||
|
|
|
@ -28,6 +28,13 @@
|
||||||
translate>
|
translate>
|
||||||
Delete ticket
|
Delete ticket
|
||||||
</vn-item>
|
</vn-item>
|
||||||
|
<vn-item
|
||||||
|
ng-click="restoreConfirmation.show()"
|
||||||
|
ng-show="$ctrl.ticket.isDeleted"
|
||||||
|
name="restoreTicket"
|
||||||
|
translate>
|
||||||
|
Restore ticket
|
||||||
|
</vn-item>
|
||||||
<vn-item
|
<vn-item
|
||||||
ng-click="$ctrl.showChangeShipped()"
|
ng-click="$ctrl.showChangeShipped()"
|
||||||
ng-show="$ctrl.isEditable"
|
ng-show="$ctrl.isEditable"
|
||||||
|
@ -239,6 +246,12 @@
|
||||||
question="You are going to delete this ticket"
|
question="You are going to delete this ticket"
|
||||||
message="This ticket will be removed from current route! Continue anyway?">
|
message="This ticket will be removed from current route! Continue anyway?">
|
||||||
</vn-confirm>
|
</vn-confirm>
|
||||||
|
<vn-confirm
|
||||||
|
vn-id="restoreConfirmation"
|
||||||
|
on-accept="$ctrl.restoreTicket()"
|
||||||
|
question="You are going to restore this ticket"
|
||||||
|
message="You can only restore a ticket within the first hour after deletion! Continue anyway?">
|
||||||
|
</vn-confirm>
|
||||||
<vn-confirm
|
<vn-confirm
|
||||||
vn-id="deleteStowaway"
|
vn-id="deleteStowaway"
|
||||||
on-accept="$ctrl.deleteStowaway()"
|
on-accept="$ctrl.deleteStowaway()"
|
||||||
|
|
|
@ -90,6 +90,14 @@ class Controller extends Descriptor {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
restoreTicket() {
|
||||||
|
return this.$http.post(`Tickets/${this.id}/restore`)
|
||||||
|
.then(() => {
|
||||||
|
this.vnApp.showSuccess(this.$t('Ticket restored'));
|
||||||
|
this.cardReload();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
canStowaway() {
|
canStowaway() {
|
||||||
this.canShowStowaway = false;
|
this.canShowStowaway = false;
|
||||||
if (!this.isTicketModule || !this.ticket) return;
|
if (!this.isTicketModule || !this.ticket) return;
|
||||||
|
|
Loading…
Reference in New Issue