afssequelize
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -5,2 +5,5 @@ 'use strict'; | ||
const Translatable = require('./lib/translatable'); | ||
const LanguageDAO = require('./lib/language-dao'); | ||
const Language = require('./lib/language-model'); | ||
const generator = require('./lib/generator'); | ||
@@ -10,2 +13,7 @@ module.exports = { | ||
Translatable, | ||
LanguageDAO, | ||
Language, | ||
generateDb: generator.generateDb, | ||
generateConfig: generator.generateConfig, | ||
Sequelize: generator.Sequelize, | ||
}; |
@@ -33,3 +33,3 @@ 'use strict'; | ||
createTextTx(input, transaction) { | ||
async createTextTx(input, transaction) { | ||
const Table = this.db[this.tableName]; | ||
@@ -40,11 +40,9 @@ const { parentIdField } = this; | ||
where[parentIdField] = input.id; | ||
return Table.destroy({ where, transaction }) | ||
.then(() => { | ||
const record = this.createRecord(input); | ||
return Table.create(record, { transaction }) | ||
.then(() => input); | ||
}); | ||
await Table.destroy({ where, transaction }) | ||
const record = this.createRecord(input); | ||
await Table.create(record, { transaction }) | ||
return input | ||
} | ||
deleteTextTx(parentId, transaction) { | ||
async deleteTextTx(parentId, transaction) { | ||
const Table = this.db[this.tableName]; | ||
@@ -58,3 +56,3 @@ const { parentIdField } = this; | ||
createMultipleTextsTx(inputs, inputLanguage, transaction) { | ||
async createMultipleTextsTx(inputs, inputLanguage, transaction) { | ||
const Table = this.db[this.tableName]; | ||
@@ -65,18 +63,16 @@ const { parentIdField } = this; | ||
const where = { language, [parentIdField]: { [Op.in]: ids } }; | ||
return Table.destroy({ where, transaction }) | ||
.then(() => { | ||
const records = inputs.map((input) => this.createRecord(input, language)); | ||
return Table.bulkCreate(records, { transaction }); | ||
}); | ||
await Table.destroy({ where, transaction }) | ||
const records = inputs.map((input) => this.createRecord(input, language)); | ||
return Table.bulkCreate(records, { transaction }); | ||
} | ||
createText(input) { | ||
async createText(input) { | ||
return this.transaction((transaction) => this.createTextTx(input, transaction)); | ||
} | ||
createMultipleTexts(input) { | ||
async createMultipleTexts(input) { | ||
return this.transaction((transaction) => this.createMultipleTextsTx(input, transaction)); | ||
} | ||
getText(parentId, language = 'en') { | ||
async getText(parentId, language = 'en') { | ||
const Table = this.db[this.tableName]; | ||
@@ -86,10 +82,8 @@ const where = { language }; | ||
const query = { where, raw: true, attributes: this.textFields }; | ||
return Table.findOne(query) | ||
.then((result) => { | ||
if ((language === 'en') || result) { | ||
return result; | ||
} | ||
query.where.language = 'en'; | ||
return Table.findOne(query); | ||
}); | ||
const result = await Table.findOne(query); | ||
if ((language === 'en') || result) { | ||
return result; | ||
} | ||
query.where.language = 'en'; | ||
return Table.findOne(query); | ||
} | ||
@@ -111,8 +105,9 @@ | ||
updateText(parent, language) { | ||
return this.getText(parent.id, language) | ||
.then((result) => this.updateTextFields(parent, result)); | ||
async updateText(parent, language) { | ||
const result = await this.getText(parent.id, language); | ||
this.updateTextFields(parent, result); | ||
return parent; | ||
} | ||
getAllTexts(ids, language = 'en') { | ||
async getAllTexts(ids, language = 'en') { | ||
const Table = this.db[this.tableName]; | ||
@@ -127,28 +122,24 @@ const { parentIdField } = this; | ||
_.set(options, `where.${parentIdField}`, { [Op.in]: ids }); | ||
return Table.findAll(options) | ||
.then((records) => { | ||
if (language === 'en') { | ||
return _.keyBy(records, parentIdField); | ||
} | ||
const enRecords = _.remove(records, (r) => r.language === 'en'); | ||
const map = _.keyBy(records, parentIdField); | ||
enRecords.forEach((record) => { | ||
const parentId = record[parentIdField]; | ||
if (!map[parentId]) { | ||
map[parentId] = record; | ||
records.push(record); | ||
} | ||
}); | ||
return map; | ||
}); | ||
const records = await Table.findAll(options); | ||
if (language === 'en') { | ||
return _.keyBy(records, parentIdField); | ||
} | ||
const enRecords = _.remove(records, (r) => r.language === 'en'); | ||
const map = _.keyBy(records, parentIdField); | ||
enRecords.forEach((record) => { | ||
const parentId = record[parentIdField]; | ||
if (!map[parentId]) { | ||
map[parentId] = record; | ||
records.push(record); | ||
} | ||
}); | ||
return map; | ||
} | ||
updateAllTexts(parents, language, idField = 'id') { | ||
async updateAllTexts(parents, language, idField = 'id') { | ||
const ids = _.map(parents, idField); | ||
return this.getAllTexts(ids, language) | ||
.then((map) => { | ||
parents.forEach((parent) => this.updateTextFields(parent, map[parent[idField]])); | ||
return parents; | ||
}); | ||
const map = await this.getAllTexts(ids, language); | ||
parents.forEach((parent) => this.updateTextFields(parent, map[parent[idField]])); | ||
return parents; | ||
} | ||
}; |
{ | ||
"name": "afssequelize", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "sequelize utilities", | ||
@@ -24,4 +24,5 @@ "main": "index.js", | ||
"lodash": "^4.17.15", | ||
"pg": "^7.17.1", | ||
"sequelize": "^5.21.3" | ||
} | ||
} |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
25697
11
390
3
11
+ Addedpg@^7.17.1
+ Addedbuffer-writer@2.0.0(transitive)
+ Addedpacket-reader@1.0.0(transitive)
+ Addedpg@7.18.2(transitive)
+ Addedpg-connection-string@0.1.3(transitive)
+ Addedpg-int8@1.0.1(transitive)
+ Addedpg-packet-stream@1.1.0(transitive)
+ Addedpg-pool@2.0.10(transitive)
+ Addedpg-types@2.2.0(transitive)
+ Addedpgpass@1.0.5(transitive)
+ Addedpostgres-array@2.0.0(transitive)
+ Addedpostgres-bytea@1.0.0(transitive)
+ Addedpostgres-date@1.0.7(transitive)
+ Addedpostgres-interval@1.2.0(transitive)
+ Addedsemver@4.3.2(transitive)
+ Addedsplit2@4.2.0(transitive)
+ Addedxtend@4.0.2(transitive)