refs #5561 refactor: sustituidos sql por loopback
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
7d2e98267f
commit
f52b398596
|
@ -25,6 +25,7 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.delete = async(saleFk, stateCode, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
|
@ -37,15 +38,27 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
try {
|
||||
const result = await Self.rawSql(`CALL vn.saleTracking_del(?, ?)`,
|
||||
[
|
||||
saleFk,
|
||||
stateCode,
|
||||
], myOptions);
|
||||
const itemShelvingSales = await models.ItemShelvingSale.find({where: {saleFk: saleFk}}, myOptions);
|
||||
for (let itemShelvingSale of itemShelvingSales)
|
||||
await itemShelvingSale.destroy(myOptions);
|
||||
|
||||
const state = await models.State.findOne({
|
||||
where: {code: stateCode}
|
||||
}, myOptions);
|
||||
|
||||
const filter = {
|
||||
where: {
|
||||
saleFk: saleFk,
|
||||
stateFk: state.id
|
||||
}
|
||||
};
|
||||
const saleTrackings = await models.SaleTracking.find(filter, myOptions);
|
||||
for (let saleTracking of saleTrackings)
|
||||
await saleTracking.destroy(myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return result;
|
||||
return true;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
|
|
|
@ -33,6 +33,7 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.new = async(ctx, saleFk, isChecked, quantity, stateCode, options) => {
|
||||
const models = Self.app.models;
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
@ -45,19 +46,42 @@ module.exports = Self => {
|
|||
myOptions.transaction = tx;
|
||||
}
|
||||
try {
|
||||
const result = await Self.rawSql(`CALL vn.saleTracking_new(?, ?, ?, ?, ?, ?)`,
|
||||
[
|
||||
saleFk,
|
||||
isChecked,
|
||||
quantity,
|
||||
userId,
|
||||
stateCode,
|
||||
null
|
||||
], myOptions);
|
||||
const state = await models.State.findOne({
|
||||
where: {code: stateCode}
|
||||
}, myOptions);
|
||||
|
||||
const saleTracking = await models.SaleTracking.findOne({
|
||||
where: {
|
||||
saleFk: saleFk,
|
||||
stateFk: state.id,
|
||||
workerFk: userId
|
||||
}
|
||||
}, myOptions);
|
||||
|
||||
let newSaleTracking;
|
||||
if (saleTracking) {
|
||||
newSaleTracking = await saleTracking.updateAttributes({
|
||||
saleFk: saleFk,
|
||||
stateFk: state.id,
|
||||
workerFk: userId,
|
||||
isChecked: isChecked,
|
||||
originalQuantity: quantity,
|
||||
isScanned: null
|
||||
}, myOptions);
|
||||
} else {
|
||||
newSaleTracking = await models.SaleTracking.create({
|
||||
saleFk: saleFk,
|
||||
stateFk: state.id,
|
||||
workerFk: userId,
|
||||
isChecked: isChecked,
|
||||
originalQuantity: quantity,
|
||||
isScanned: null
|
||||
});
|
||||
}
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return result;
|
||||
return newSaleTracking;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
|
|
Loading…
Reference in New Issue