Skip to content

Commit

Permalink
Merge pull request #47 from dh-center/SOROKA-149
Browse files Browse the repository at this point in the history
SOROKA-149 4: + noAuth cards, by-first-organization, by prop id
  • Loading branch information
RomanKuzovlev authored Oct 21, 2022
2 parents 7318524 + 8813d81 commit 1ec541f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/services/cards/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
17 changes: 16 additions & 1 deletion src/services/cards/FilledProperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,22 @@ class FilledPropertyService implements IFilledPropertyService {

async getByPk(propertyId: number): Promise<any> {
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) {
Expand Down

0 comments on commit 1ec541f

Please sign in to comment.