mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-11-09 22:33:09 +02:00
transactions
This commit is contained in:
parent
35d4a73c4d
commit
c5b8ff0a07
@ -18,12 +18,12 @@ module.exports = class TicketArchives {
|
|||||||
|
|
||||||
async addMessage(message) {
|
async addMessage(message) {
|
||||||
try {
|
try {
|
||||||
await this.client.db.transaction(async t => {
|
// await this.client.db.transaction(async t => {
|
||||||
let t_row = await this.client.db.models.Ticket.findOne({
|
let t_row = await this.client.db.models.Ticket.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: message.channel.id
|
id: message.channel.id
|
||||||
},
|
},
|
||||||
transaction: t
|
/* transaction: t */
|
||||||
});
|
});
|
||||||
|
|
||||||
if (t_row) {
|
if (t_row) {
|
||||||
@ -39,11 +39,11 @@ module.exports = class TicketArchives {
|
|||||||
attachments: [...message.attachments.values()]
|
attachments: [...message.attachments.values()]
|
||||||
})),
|
})),
|
||||||
createdAt: new Date(message.createdTimestamp)
|
createdAt: new Date(message.createdTimestamp)
|
||||||
}, { transaction: t });
|
}, /* { transaction: t } */);
|
||||||
|
|
||||||
await this.updateEntities(message);
|
await this.updateEntities(message);
|
||||||
}
|
}
|
||||||
});
|
// });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.client.log.warn('Failed to add a message to the ticket archive');
|
this.client.log.warn('Failed to add a message to the ticket archive');
|
||||||
this.client.log.error(e);
|
this.client.log.error(e);
|
||||||
@ -52,12 +52,12 @@ module.exports = class TicketArchives {
|
|||||||
|
|
||||||
async updateMessage(message) {
|
async updateMessage(message) {
|
||||||
try {
|
try {
|
||||||
await this.client.db.transaction(async t => {
|
// await this.client.db.transaction(async t => {
|
||||||
let m_row = await this.client.db.models.Message.findOne({
|
let m_row = await this.client.db.models.Message.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: message.id
|
id: message.id
|
||||||
},
|
},
|
||||||
transaction: t
|
/* transaction: t */
|
||||||
});
|
});
|
||||||
|
|
||||||
if (m_row) {
|
if (m_row) {
|
||||||
@ -74,9 +74,9 @@ module.exports = class TicketArchives {
|
|||||||
await this.updateEntities(message);
|
await this.updateEntities(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
await m_row.save({ transaction: t }); // save changes
|
await m_row.save(/* { transaction: t } */); // save changes
|
||||||
}
|
}
|
||||||
});
|
// });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.client.log.warn('Failed to update message in the ticket archive');
|
this.client.log.warn('Failed to update message in the ticket archive');
|
||||||
this.client.log.error(e);
|
this.client.log.error(e);
|
||||||
@ -85,19 +85,19 @@ module.exports = class TicketArchives {
|
|||||||
|
|
||||||
async deleteMessage(message) {
|
async deleteMessage(message) {
|
||||||
try {
|
try {
|
||||||
await this.client.db.transaction(async t => {
|
// await this.client.db.transaction(async t => {
|
||||||
let msg = await this.client.db.models.Message.findOne({
|
let msg = await this.client.db.models.Message.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: message.id
|
id: message.id
|
||||||
},
|
},
|
||||||
transaction: t
|
/* transaction: t */
|
||||||
});
|
});
|
||||||
|
|
||||||
if (msg) {
|
if (msg) {
|
||||||
msg.deleted = true;
|
msg.deleted = true;
|
||||||
await msg.save({ transaction: t }); // save changes to message row
|
await msg.save(/* { transaction: t } */); // save changes to message row
|
||||||
}
|
}
|
||||||
});
|
// });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.client.log.warn('Failed to delete message in ticket archive');
|
this.client.log.warn('Failed to delete message in ticket archive');
|
||||||
this.client.log.error(e);
|
this.client.log.error(e);
|
||||||
@ -128,7 +128,7 @@ module.exports = class TicketArchives {
|
|||||||
await this.updateRole(ticket_id, member.roles.highest);
|
await this.updateRole(ticket_id, member.roles.highest);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.client.db.transaction(async t => {
|
// await this.client.db.transaction(async t => {
|
||||||
let u_model_data = {
|
let u_model_data = {
|
||||||
user: member.user.id,
|
user: member.user.id,
|
||||||
ticket: ticket_id
|
ticket: ticket_id
|
||||||
@ -140,7 +140,7 @@ module.exports = class TicketArchives {
|
|||||||
...u_model_data,
|
...u_model_data,
|
||||||
role: member.roles.highest.id
|
role: member.roles.highest.id
|
||||||
},
|
},
|
||||||
transaction: t
|
/* transaction: t */
|
||||||
});
|
});
|
||||||
|
|
||||||
await u_row.update({
|
await u_row.update({
|
||||||
@ -150,10 +150,10 @@ module.exports = class TicketArchives {
|
|||||||
display_name: this.encrypt(member.displayName),
|
display_name: this.encrypt(member.displayName),
|
||||||
role: member.roles.highest.id,
|
role: member.roles.highest.id,
|
||||||
bot: member.user.bot
|
bot: member.user.bot
|
||||||
}, { transaction: t });
|
}, /* { transaction: t } */);
|
||||||
|
|
||||||
return u_row;
|
return u_row;
|
||||||
});
|
// });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.client.log.warn('Failed to update message author entity in ticket archive');
|
this.client.log.warn('Failed to update message author entity in ticket archive');
|
||||||
this.client.log.error(e);
|
this.client.log.error(e);
|
||||||
@ -162,7 +162,7 @@ module.exports = class TicketArchives {
|
|||||||
|
|
||||||
async updateChannel(ticket_id, channel) {
|
async updateChannel(ticket_id, channel) {
|
||||||
try {
|
try {
|
||||||
await this.client.db.transaction(async t => {
|
// await this.client.db.transaction(async t => {
|
||||||
let c_model_data = {
|
let c_model_data = {
|
||||||
channel: channel.id,
|
channel: channel.id,
|
||||||
ticket: ticket_id
|
ticket: ticket_id
|
||||||
@ -170,15 +170,15 @@ module.exports = class TicketArchives {
|
|||||||
let [c_row] = await this.client.db.models.ChannelEntity.findOrCreate({
|
let [c_row] = await this.client.db.models.ChannelEntity.findOrCreate({
|
||||||
where: c_model_data,
|
where: c_model_data,
|
||||||
defaults: c_model_data,
|
defaults: c_model_data,
|
||||||
transaction: t
|
/* transaction: t */
|
||||||
});
|
});
|
||||||
|
|
||||||
await c_row.update({
|
await c_row.update({
|
||||||
name: this.encrypt(channel.name)
|
name: this.encrypt(channel.name)
|
||||||
}, { transaction: t });
|
}, /* { transaction: t } */);
|
||||||
|
|
||||||
return c_row;
|
return c_row;
|
||||||
});
|
// });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.client.log.warn('Failed to update mentioned channels entities in ticket archive');
|
this.client.log.warn('Failed to update mentioned channels entities in ticket archive');
|
||||||
this.client.log.error(e);
|
this.client.log.error(e);
|
||||||
@ -187,7 +187,7 @@ module.exports = class TicketArchives {
|
|||||||
|
|
||||||
async updateRole(ticket_id, role) {
|
async updateRole(ticket_id, role) {
|
||||||
try {
|
try {
|
||||||
await this.client.db.transaction(async t => {
|
// await this.client.db.transaction(async t => {
|
||||||
let r_model_data = {
|
let r_model_data = {
|
||||||
role: role.id,
|
role: role.id,
|
||||||
ticket: ticket_id
|
ticket: ticket_id
|
||||||
@ -195,16 +195,16 @@ module.exports = class TicketArchives {
|
|||||||
let [r_row] = await this.client.db.models.RoleEntity.findOrCreate({
|
let [r_row] = await this.client.db.models.RoleEntity.findOrCreate({
|
||||||
where: r_model_data,
|
where: r_model_data,
|
||||||
defaults: r_model_data,
|
defaults: r_model_data,
|
||||||
transaction: t
|
/* transaction: t */
|
||||||
});
|
});
|
||||||
|
|
||||||
await r_row.update({
|
await r_row.update({
|
||||||
name: this.encrypt(role.name),
|
name: this.encrypt(role.name),
|
||||||
colour: role.color === 0 ? '7289DA' : int2hex(role.color) // 7289DA = 7506394
|
colour: role.color === 0 ? '7289DA' : int2hex(role.color) // 7289DA = 7506394
|
||||||
}, { transaction: t });
|
}, /* { transaction: t } */);
|
||||||
|
|
||||||
return r_row;
|
return r_row;
|
||||||
});
|
// });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.client.log.warn('Failed to update mentioned roles entities in ticket archive');
|
this.client.log.warn('Failed to update mentioned roles entities in ticket archive');
|
||||||
this.client.log.error(e);
|
this.client.log.error(e);
|
||||||
|
Loading…
Reference in New Issue
Block a user