@kohanajs/mod-admin
Advanced tools
Comparing version 5.5.1 to 5.6.0
@@ -5,2 +5,9 @@ # Changelog | ||
## [5.6.0](https://gitlab.com/kohana-js/modules/admin/compare/v5.5.1...v5.6.0) (2023-07-19) | ||
### Features | ||
* list duplicated, update and created records ([1cc5959](https://gitlab.com/kohana-js/modules/admin/commit/1cc59599c7de9439f6a4053ebd240d8f83907e72)) | ||
### [5.5.1](https://gitlab.com/kohana-js/modules/admin/compare/v5.5.0...v5.5.1) (2023-07-19) | ||
@@ -7,0 +14,0 @@ |
@@ -18,5 +18,10 @@ const { ControllerMixin } = require('@kohanajs/core-mvc'); | ||
static DUPLICATED_CSV_RECORDS = 'import_duplicated_csv_records'; | ||
static CREATED_CSV_RECORDS = 'import_created_csv_records'; | ||
static UPDATED_CSV_RECORDS = 'import_updated_csv_records'; | ||
static init(state) { | ||
state.set(this.DUPLICATED_CSV_RECORDS, []); | ||
state.set(this.CREATED_CSV_RECORDS, []); | ||
state.set(this.UPDATED_CSV_RECORDS, []); | ||
if(!state.get(this.UNIQUE_KEY))state.set(this.UNIQUE_KEY, 'email'); | ||
@@ -93,2 +98,6 @@ if(!state.get(this.HEADER_COLUMN_MAP))state.set(this.HEADER_COLUMN_MAP, new Map()); | ||
const duplicatedCSVRecords = state.get(this.DUPLICATED_CSV_RECORDS); | ||
const createdCSVRecords = state.get(this.CREATED_CSV_RECORDS); | ||
const updatedCSVRecords = state.get(this.UPDATED_CSV_RECORDS); | ||
//create or update records | ||
@@ -107,7 +116,7 @@ await Promise.all( | ||
//update exist record | ||
Object.assign(existRecord, result); | ||
await existRecord.write(); | ||
await state.get(this.IMPORT_INSTANCE_HANDLER)(state, existRecord, result); | ||
await this.writeRecord(state, existRecord, result); | ||
updatedCSVRecords.push(Object.assign({}, result)); | ||
return; | ||
} | ||
duplicatedCSVRecords.push(Object.assign({},result)); | ||
return; | ||
@@ -123,10 +132,15 @@ } | ||
const newRecord = ORM.create(Model, options); | ||
Object.assign(newRecord, result); | ||
await newRecord.write(); | ||
await state.get(this.IMPORT_INSTANCE_HANDLER)(state, newRecord, result); | ||
await this.writeRecord(state, newRecord, result); | ||
createdCSVRecords.push(Object.assign({id: newRecord.id}, result)); | ||
}) | ||
); | ||
} | ||
static async writeRecord(state, instance, csvRecord){ | ||
Object.assign(instance, csvRecord); | ||
await instance.write(); | ||
await state.get(this.IMPORT_INSTANCE_HANDLER)(state, instance, csvRecord); | ||
} | ||
} | ||
module.exports = ControllerMixinImport; |
{ | ||
"name": "@kohanajs/mod-admin", | ||
"version": "5.5.1", | ||
"version": "5.6.0", | ||
"description": "Admin templates for KohanaJS ORM", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59399
988