feat: delete from ticketCollection and sectorCollection when a ticket is deleted
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2022-06-16 09:58:15 +02:00
parent b64174ff5d
commit 84ffe3f594
3 changed files with 44 additions and 0 deletions

View File

@ -142,6 +142,25 @@ module.exports = Self => {
const updatedTicket = await ticket.updateAttribute('isDeleted', true, myOptions);
const [ticketCollection] = await models.TicketCollection.find({
fields: ['id'],
where: {
ticketFk: ticket.id
}
});
if (ticketCollection)
await models.TicketCollection.destroyById(ticketCollection.id, myOptions);
await Self.rawSql(`
DELETE sc
FROM vn.saleGroup sg
JOIN vn.sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sg.id
JOIN vn.sectorCollection sc ON sc.id = scsg.sectorCollectionFk
JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = sg.id
JOIN vn.sale s ON s.id = sgd.saleFk
WHERE s.ticketFk = ?;`, [ticket.id], myOptions);
if (tx) await tx.commit();
return updatedTicket;

View File

@ -44,6 +44,9 @@
"Ticket": {
"dataSource": "vn"
},
"TicketCollection": {
"dataSource": "vn"
},
"TicketDms": {
"dataSource": "vn"
},

View File

@ -0,0 +1,22 @@
{
"name": "TicketCollection",
"base": "VnModel",
"options": {
"mysql": {
"table": "ticketCollection"
}
},
"properties": {
"id": {
"id": true,
"type": "number"
}
},
"relations": {
"ticket": {
"type": "belongsTo",
"model": "Ticket",
"foreignKey": "ticketFk"
}
}
}