Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ipa-customer-settings

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ipa-customer-settings - npm Package Compare versions

Comparing version 0.0.27 to 0.0.28

src/db/migrations/customer-settings/copyCustomerSettings.js

2

package-lock.json
{
"name": "ipa-customer-settings",
"version": "0.0.27",
"version": "0.0.28",
"lockfileVersion": 1,

@@ -5,0 +5,0 @@ "requires": true,

{
"name": "ipa-customer-settings",
"version": "0.0.27",
"version": "0.0.28",
"author": "OpusCapita",

@@ -5,0 +5,0 @@ "license": "Apache-2.0",

'use strict';
const lodash = require('lodash');
class CustomerSettingsApi {

@@ -25,2 +28,14 @@ static getInstance(db) {

static getCustomerSettingsDifference(from, to) {
return lodash.differenceWith(
from,
to,
(fromSettings, toSettings) => (
(fromSettings.customerId === toSettings.customerId) &&
(fromSettings.settingName === toSettings.settingName)
)
);
}
async findById(id) {

@@ -59,9 +74,15 @@ const setting = await this.db.models.CustomerSetting.findById(id);

const customerId = customerSettings[0] ? customerSettings[0].customerId : null;
const actualCustomerSettings = this.findAll({ where: { customerId } });
const itemsToRemove = CustomerSettingsApi.getCustomerSettingsDifference(actualCustomerSettings, customerSettings);
const transaction = await this.db.transaction();
try {
const items = [];
if (customerSettings.length) {
return Promise.all(
await Promise.all(
customerSettings.map(async item => {
await this.db.models.CustomerSetting.upsert(item);
return this.db.models.CustomerSetting.find({
const newItem = await this.db.models.CustomerSetting.find({
where: {

@@ -72,6 +93,14 @@ customerId: item.customerId,

});
})
if (newItem) {
items.push(newItem);
}
}).concat(
itemsToRemove.length ?
itemsToRemove.map(item => this.removeById(item.id, transaction)) :
Promise.resolve()
)
);
}
await transaction.commit();
return items;
} catch (err) {

@@ -81,4 +110,2 @@ await transaction.rollback();

}
return Promise.resolve();
}

@@ -85,0 +112,0 @@

'use strict';
const createCustomerSettings = require('./customer-settings/createCustomerSettings');
const copyCustomerSettings = require('./customer-settings/copyCustomerSettings');
const dropCustomerSettings = require('./customer-settings/dropCustomerSettings');

@@ -9,2 +10,3 @@

await createCustomerSettings(db.queryInterface, config);
await copyCustomerSettings(db.queryInterface, { tablePrefixFrom: 'IPA', tablePrefixTo: config.tablePrefix });
},

@@ -11,0 +13,0 @@ down: async (db, config) => {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc