From 8813d81cfc083fbcf2313de30a925727ccd64650 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 21 Oct 2022 13:33:00 +0600 Subject: [PATCH] + noAuth cards, by-first-organization, by prop id --- src/services/cards/Card.ts | 31 ++++++++++++++++++++++++++++ src/services/cards/FilledProperty.ts | 17 ++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/services/cards/Card.ts b/src/services/cards/Card.ts index 2abf56c..887a320 100644 --- a/src/services/cards/Card.ts +++ b/src/services/cards/Card.ts @@ -3,6 +3,7 @@ import Card from "../../models/cards/Card" import FilledProperty from "../../models/cards/FilledProperty" import UserRole from "../../models/users/UserRole" import paginate from "../../utils/paginate" +import GeoProperty from '../../models/cards/GeoProperty' class CardService implements ICardService { async getAll (user: any, limit?: number, offset?: number): Promise { @@ -37,6 +38,21 @@ class CardService implements ICardService { let props = card.properties + // HOTFIX + for (const el of props) { + // console.log("EL: ", el.propertyId); + if (el.propertyId === 9) { + const geoProperty: GeoProperty | null = await GeoProperty + .findOne({ where: { filledPropertyId: el.id} }); + el.data = [{ + location: geoProperty?.location, + name: geoProperty?.name + }] + delete el.data[0]?.location?.crs + el.data = JSON.stringify(el.data); + } + } + props = props.map((prop: any) => { const { id, propertyId, data } = prop @@ -85,6 +101,21 @@ class CardService implements ICardService { let props = card.properties + // HOTFIX + for (const el of props) { + // console.log("EL: ", el.propertyId); + if (el.propertyId === 9) { + const geoProperty: GeoProperty | null = await GeoProperty + .findOne({ where: { filledPropertyId: el.id} }); + el.data = [{ + location: geoProperty?.location, + name: geoProperty?.name + }] + delete el.data[0]?.location?.crs + el.data = JSON.stringify(el.data); + } + } + props = props.map((prop: any) => { const { id, propertyId, data } = prop diff --git a/src/services/cards/FilledProperty.ts b/src/services/cards/FilledProperty.ts index eb94763..b979dc9 100644 --- a/src/services/cards/FilledProperty.ts +++ b/src/services/cards/FilledProperty.ts @@ -130,7 +130,22 @@ class FilledPropertyService implements IFilledPropertyService { async getByPk(propertyId: number): Promise { try { - const property: any = await FilledProperty.findByPk(propertyId) + const filledProperty: any = await FilledProperty.findByPk(propertyId) + // find and populate geoProperties + // FIXME: добавить работу с массивом, чтобы в нем было больше одного элемента. + const property: any = filledProperty.property?.dataValues; + + if (property?.dataType?.name === "GEO_POINT") { + const geoProperty: GeoProperty | null = await GeoProperty + .findOne({ where: { filledPropertyId: filledProperty.id} }); + + property.data = [{ + location: geoProperty?.location, + name: geoProperty?.name + }] + delete property.data[0]?.location?.crs + property.data = JSON.stringify(property.data); + } return { detail: property, status: 200 } } catch (e) {