refs #4823 Insert in models if exists

This commit is contained in:
Guillermo Bonet 2023-06-29 14:53:19 +02:00
parent fa34a22c02
commit f3d9ad8ff0
2 changed files with 27 additions and 11 deletions

View File

@ -76,11 +76,11 @@ let models = {
seasonalPeriod: seasonalPeriod(sequelize),
supplyLine: supplyLine(sequelize),
supplyLinePackingConfiguration: supplyLinePackingConfiguration(sequelize),
volumePrice: volumePrice(sequelize),
package: packageModel(sequelize),
clockPresaleSupply: clockPresaleSupply(sequelize),
clockPresaleSupplyPackingConfiguration: clockPresaleSupplyPackingConfiguration(sequelize),
clockPresaleSupplyPackage: clockPresaleSupplyPackage(sequelize),
volumePrice: volumePrice(sequelize),
clockPresaleSupply: clockPresaleSupply(sequelize),
package: packageModel(sequelize),
};
try {

View File

@ -252,9 +252,13 @@ export async function insertSequenceNumber(model, sequenceNumber) {
export async function insertTradeItems(tradeItems) {
const tx = await models.sequelize.transaction();
try {
const dbData = await models.tradeItem.findAll();
let filteredTradeItems = [];
for (let tradeItem of tradeItems)
if (!tradeItem.isDeleted) filteredTradeItems.push(tradeItem);
tradeItems.forEach(value => {
if (!value.isDeleted || dbData.includes(value.tradeItemId))
filteredTradeItems.push(value);
});
const tradeItemsData = filteredTradeItems.map((tradeItem) => ({
...tradeItem,
@ -406,9 +410,13 @@ export async function insertTradeItems(tradeItems) {
export async function insertClockPresalesSupply(clockPresalesSupply) {
const tx = await models.sequelize.transaction();
try {
const dbData = await models.clockPresaleSupply.findAll();
let filteredclockPresalesSupply = [];
for (let clockPresaleSupply of clockPresalesSupply)
if (!(clockPresaleSupply.status === 'UNAVAILABLE')) filteredclockPresalesSupply.push(clockPresaleSupply);
clockPresalesSupply.forEach(value => {
if (!(value.status === 'UNAVAILABLE') || dbData.includes(value.supplyLineId))
filteredclockPresalesSupply.push(value);
});
const clockPresalesSupplyWithDefaults = filteredclockPresalesSupply.map((clockPresaleSupply) => ({
...clockPresaleSupply,
@ -492,9 +500,13 @@ export async function insertClockPresalesSupply(clockPresalesSupply) {
export async function insertWarehouses(warehouses) {
const tx = await models.sequelize.transaction();
try {
const dbData = await models.warehouse.findAll();
let filteredWarehouses = [];
for (let warehouse of warehouses)
if (!warehouse.isDeleted) filteredWarehouses.push(warehouse);
warehouses.forEach(value => {
if (!value.isDeleted || dbData.includes(value.warehouseId))
filteredWarehouses.push(value);
});
const warehousesWithDefaults = filteredWarehouses.map((warehouse) => ({
...warehouse,
@ -614,9 +626,13 @@ export async function insertOrganizations(organizations) {
export async function insertSupplyLines(supplyLines) {
const tx = await models.sequelize.transaction();
try {
const dbData = await models.supplyLine.findAll();
let filteredSupplyLines = [];
for (let supplyLine of supplyLines)
if (!supplyLine.isDeleted) filteredSupplyLines.push(supplyLine);
supplyLines.forEach(value => {
if ((!value.isDeleted && !(value.status === 'UNAVAILABLE')) || dbData.includes(value.supplyLineId))
filteredSupplyLines.push(value);
});
const supplyLinesData = filteredSupplyLines.map((supplyLine) => ({
...supplyLine,