import { queryDomains, queryDomainAddresses } from '../api/domains';
import updateCollection from '../helpers/updateCollection';

export const updateDomainsModel = (api, Domains) => {
    return Promise.all(
        Domains.map(async (domain) => {
            const { Addresses = [] } = await api(queryDomainAddresses(domain.ID));
            return {
                ...domain,
                addresses: Addresses,
            };
        })
    );
};

export const getDomainsModel = (api) => {
    return api(queryDomains()).then(({ Domains }) => updateDomainsModel(api, Domains));
};

export const DomainsModel = {
    key: 'Domains',
    get: getDomainsModel,
    update: (model, events) =>
        updateCollection({ model, events, item: ({ Domain }) => ({ ...Domain, addresses: [] }) }),
};

@@ -18,30 +18,8 @@
 ains
-, queryDomainAddresses
  %7D f
@@ -105,332 +105,8 @@
 ';%0A%0A
-export const updateDomainsModel = (api, Domains) =%3E %7B%0A    return Promise.all(%0A        Domains.map(async (domain) =%3E %7B%0A            const %7B Addresses = %5B%5D %7D = await api(queryDomainAddresses(domain.ID));%0A            return %7B%0A                ...domain,%0A                addresses: Addresses,%0A            %7D;%0A        %7D)%0A    );%0A%7D;%0A%0A
 expo
@@ -200,40 +200,15 @@
  =%3E 
-update
 Domains
-Model(api, Domains)
 );%0A%7D
@@ -320,16 +320,8 @@
 ) =%3E
-%0A       
  upd
@@ -377,38 +377,14 @@
  =%3E 
-(%7B ...Domain, addresses: %5B%5D %7D)
+Domain
  %7D),

Fix domain request