-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathindex.ts
30 lines (21 loc) · 917 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
// @ts-expect-error untyped
import { buildTree } from 'ember-simple-tree/utils/tree';
import { query } from '@ember-data/json-api/request';
import { setBuildURLConfig } from '@ember-data/request-utils';
import type Person from '../models/person';
import type Store from '../services/store';
setBuildURLConfig({ host: `http://${window.location.host}`, namespace: 'api' });
export default class IndexRoute extends Route {
@service declare store: Store;
override async model() {
const {
content: { data: people },
} = await this.store.request(query<Person>('person', {}, { resourcePath: 'people.json' }));
console.log(people.slice());
const tree = buildTree(people.map((person) => person.toNode()));
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return tree;
}
}