From 1921bb77f1c2844cb411055e93d1474b8c6c1d7f Mon Sep 17 00:00:00 2001 From: Roman Date: Thu, 6 Oct 2022 16:48:28 +0600 Subject: [PATCH] Fixed CSV import (now fills DateCatalogs) --- src/models/cards/FilledProperty.ts | 15 ++++++++++++++- src/routes/v1/cards/CsvImport.ts | 15 +++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/models/cards/FilledProperty.ts b/src/models/cards/FilledProperty.ts index c136143..8292742 100644 --- a/src/models/cards/FilledProperty.ts +++ b/src/models/cards/FilledProperty.ts @@ -13,7 +13,8 @@ import { BelongsTo, AfterCreate, AfterDestroy, - Scopes + Scopes, + AfterBulkCreate } from 'sequelize-typescript' import Card, { FilledPropertyCard } from './Card' import DataType from './DataType' @@ -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; diff --git a/src/routes/v1/cards/CsvImport.ts b/src/routes/v1/cards/CsvImport.ts index 139e2c1..04aa41d 100644 --- a/src/routes/v1/cards/CsvImport.ts +++ b/src/routes/v1/cards/CsvImport.ts @@ -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, @@ -103,9 +104,11 @@ class Controller { // создадим одним запросом все остальные свойства const createdFilledProps = await FilledProperty.bulkCreate( [ - datePropertyData, cytePropertyData, + // Временно убраны цитаты, т.к. в текущем CSV они не заполнены. + datePropertyData, // cytePropertyData, sourcePropertyData, tagsPropertyData, annotationPropertyData, geoPropertyData + ] )