import BaseProvider from '~/services/data/BaseProvider' class StructuresProvider extends BaseProvider { protected normalize (s: any) : Structure { // Define the on-map address according to the chosen priorities s.mapAddress = s.addresses.find((a: Address) => { return a.type === 'ADDRESS_PRACTICE' }) || s.addresses.find((a: Address) => { return a.type === 'ADDRESS_HEAD_OFFICE' }) || s.addresses.find((a: Address) => { return a.type === 'ADDRESS_CONTACT' }) || null // Define the postal address according to the chosen priorities s.postalAddress = s.addresses.find((a: Address) => { return a.type === 'ADDRESS_CONTACT' }) || s.addresses.find((a: Address) => { return a.type === 'ADDRESS_HEAD_OFFICE' }) || null if (s.hasOwnProperty('articles') && s.articles) { s.articles.sort((a: Article, b: Article) => { return a.date > b.date ? -1 : 1 }) } return s } async getAll (parentId: number): Promise> { return await this.get( `/api/public/federation_structures?parents=${parentId}` ).then((res) => { return res["hydra:member"].map((s: any) => { return this.normalize(s) }) }) } async getById (organizationId: number): Promise { return await this.get( `/api/public/federation_structures/${organizationId}` ).then((s) => { return this.normalize(s) }) } } export default StructuresProvider