Skip to content

Commit

Permalink
Merge pull request #39 from dh-center/SOROKA-136
Browse files Browse the repository at this point in the history
SOROKA-136: CSV import fix + temp. excluded quotes import
  • Loading branch information
RomanKuzovlev authored Oct 6, 2022
2 parents 7101c29 + 1921bb7 commit 2a08492
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
15 changes: 14 additions & 1 deletion src/models/cards/FilledProperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
BelongsTo,
AfterCreate,
AfterDestroy,
Scopes
Scopes,
AfterBulkCreate
} from 'sequelize-typescript'
import Card, { FilledPropertyCard } from './Card'
import DataType from './DataType'
Expand Down Expand Up @@ -67,6 +68,18 @@ class FilledProperty extends Model {
}
}

@AfterBulkCreate
static async onFilledPropertyBulkCreated(instance: FilledProperty[]) {
for (const el of instance) {
const property: Property | null = await Property.findByPk(el.propertyId)
const dataType: DataType | null = await DataType.findByPk(property?.dataTypeId)

if (dataType?.name) {
fillRelatedData(el, dataType.name)
}
}
}

@AfterDestroy
static async onFilledPropertyDestroyed(instance: FilledProperty) {
const filledPropertyId: number = instance.id;
Expand Down
15 changes: 9 additions & 6 deletions src/routes/v1/cards/CsvImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ class Controller {

const datePropertyData = {
propertyId: julianDateProp?.id,
data: [{ jd: julianDate.getJulianDate(), calendar }]
data: [{ startJD: julianDate.getJulianDate(), calendar }]
}

const cytePropertyData = {
data: card.cyte,
propertyId: cyteProp?.id
}
// Временно убраны цитаты, т.к. в текущем CSV они не заполнены.
// const cytePropertyData = {
// data: card.cyte,
// propertyId: cyteProp?.id
// }

const sourcePropertyData = {
data: card.source,
Expand All @@ -103,9 +104,11 @@ class Controller {
// создадим одним запросом все остальные свойства
const createdFilledProps = await FilledProperty.bulkCreate(
[
datePropertyData, cytePropertyData,
// Временно убраны цитаты, т.к. в текущем CSV они не заполнены.
datePropertyData, // cytePropertyData,
sourcePropertyData, tagsPropertyData,
annotationPropertyData, geoPropertyData

]
)

Expand Down

0 comments on commit 2a08492

Please sign in to comment.