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) => {
|
Self.delete = async(saleFk, stateCode, options) => {
|
||||||
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
|
|
||||||
|
@ -37,15 +38,27 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await Self.rawSql(`CALL vn.saleTracking_del(?, ?)`,
|
const itemShelvingSales = await models.ItemShelvingSale.find({where: {saleFk: saleFk}}, myOptions);
|
||||||
[
|
for (let itemShelvingSale of itemShelvingSales)
|
||||||
saleFk,
|
await itemShelvingSale.destroy(myOptions);
|
||||||
stateCode,
|
|
||||||
], 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();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return result;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
@ -33,6 +33,7 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.new = async(ctx, saleFk, isChecked, quantity, stateCode, options) => {
|
Self.new = async(ctx, saleFk, isChecked, quantity, stateCode, options) => {
|
||||||
|
const models = Self.app.models;
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
|
@ -45,19 +46,42 @@ module.exports = Self => {
|
||||||
myOptions.transaction = tx;
|
myOptions.transaction = tx;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const result = await Self.rawSql(`CALL vn.saleTracking_new(?, ?, ?, ?, ?, ?)`,
|
const state = await models.State.findOne({
|
||||||
[
|
where: {code: stateCode}
|
||||||
saleFk,
|
}, myOptions);
|
||||||
isChecked,
|
|
||||||
quantity,
|
const saleTracking = await models.SaleTracking.findOne({
|
||||||
userId,
|
where: {
|
||||||
stateCode,
|
saleFk: saleFk,
|
||||||
null
|
stateFk: state.id,
|
||||||
], myOptions);
|
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();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return result;
|
return newSaleTracking;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
|
|
Loading…
Reference in New Issue