我在Angular 2+中使用打字稿进行交易时遇到问题。 这是后端代码:
return new Promise(async(resolve, reject) => {
switch (message.user.userGroupId) {
case UserLevel.SUPERADMIN:
case UserLevel.ADMIN_CALLCENTER:
case UserLevel.AGENT:
case UserLevel.ADMIN_COMMERCIAL:
const contractData = message.body.contract;
const opportunityID = message.params.opportunity_id;
const opportunity = await Opportunity.findOne({
where: {
_id: opportunityID
},
include: [
Customer,
Province,
{
model: User,
as: 'agent'
},
{
model: User,
as: 'operator'
},
{
model: OpportunityLog,
include: [User]
},
],
});
const customer = opportunity.customer;
const startedTransaction: Transaction = await Opportunity.sequelize.transaction();
try {
opportunity.set(message.body);
await opportunity.save({
transaction: startedTransaction
});
message.result = opportunity.toJSON();
//HERE
this.opLog.addLog(
message.user._id,
message.body.note,
'ESIT',
opportunityID, {
transaction: startedTransaction
});
//HERE
if (status == 5) {
const contract = new Contract(contractData);
contract.opportunityId = opportunityID;
contract.operatorOpener = opportunity.agentId;
contract.agentId = opportunity.agentId;
contract.channelType = opportunity.channelType;
contract.channelSpec = opportunity.channelSpec;
contract.customerId = customer._id;
contract.address = customer.address;
contract.city = customer.city;
contract.postcode = customer.postcode;
contract.phone = [];
contract.provinceId = customer.provinceId;
contract.regionId = customer.regionId;
if (customer.phone) {
contract.phone.push(customer.name + " " + customer.surname + ' (FISSO): ' + customer.phone);
}
if (customer.mobile) {
contract.phone.push(customer.name + " " + customer.surname + ' (MOBILE): ' + customer.mobile);
}
const c = await contract.save({
transaction: startedTransaction
});
this.contractLog.addLog(message.user._id, c._id,
'Contratto creato', {
transaction: startedTransaction
});
message.result.contract = c;
}
await startedTransaction.commit();
if (status == 2) {
const toPass = JSON.parse(JSON.stringify(opportunity));
toPass.customer = customer;
this.email.sendEmail(opportunity.agent.email, message.user.email, 'Appuntamento confermato',
this.generateHtml(toPass));
}
return resolve(message);
} catch (error) {
startedTransaction.rollback();
console.log(error);
message.error = {
code: 'NA0001',
detail: 'Error modifying',
status: 400,
};
return reject(message);
}
break;
default:
message.error = {
code: 'NA0001',
detail: 'Permission denied.',
status: 403,
};
return reject(message);
}
});
这是oppLog类:
export class OpportunityLogService extends Injectable {
public addLog(operatorId, note, action, opportunityId, options = {}) {
Opportunity
.findOne({
where: {
_id: opportunityId
}
})
.then((opp: Opportunity) => {
const oppLog = new OpportunityLog({
opportunityId: opp._id,
operatorId,
note,
action,
statusId: opp.statusId,
esitId: opp.esitId,
});
oppLog.save(options).then((c) => {
console.log(c.dataValues);
}, (err) => {
//HERE
console.log('errore');
console.log(err);
//HERE
});
});
}
}
当我启动angular时,终端上会出现以下错误:
已对此事务调用commit(0f7dace9-da2a-417c-a32a-2be0f0085771),您将无法再使用它。 (被拒绝的查询作为此错误的'sql'属性附加)*