2020-04-08 17:03:18 +00:00
|
|
|
import Service, { inject as service } from '@ember/service';
|
|
|
|
import { setProperties } from '@ember/object';
|
|
|
|
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class HttpService extends Service {
|
2021-09-15 18:50:11 +00:00
|
|
|
@service('settings') settings;
|
|
|
|
@service('repository/intention') intention;
|
|
|
|
@service('repository/kv') kv;
|
|
|
|
@service('repository/session') session;
|
2020-11-09 09:25:35 +00:00
|
|
|
|
|
|
|
prepare(sink, data, instance) {
|
2020-05-01 08:49:33 +00:00
|
|
|
return setProperties(instance, data);
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
2021-10-01 10:07:58 +00:00
|
|
|
// TODO: Currently we don't use the other properties here So dc, nspace and
|
|
|
|
// partition, but confusingly they currently are in a different order to all
|
|
|
|
// our @dataSource uris @dataSource uses /:partition/:nspace/:dc/thing whilst
|
|
|
|
// here DataSink uses /:parition/:dc/:nspace/thing We should change DataSink
|
|
|
|
// to also use a @dataSink decorator and make sure the order of the parameters
|
|
|
|
// is the same throughout the app As it stands right now, if we do need to use
|
|
|
|
// those parameters for DataSink it will be very easy to introduce a bug due
|
|
|
|
// to this inconsistency
|
2020-11-09 09:25:35 +00:00
|
|
|
persist(sink, instance) {
|
2021-09-15 18:50:11 +00:00
|
|
|
const [, , , , model] = sink.split('/');
|
2020-04-08 17:03:18 +00:00
|
|
|
const repo = this[model];
|
|
|
|
return repo.persist(instance);
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
remove(sink, instance) {
|
2021-09-15 18:50:11 +00:00
|
|
|
const [, , , , model] = sink.split('/');
|
2020-04-08 17:03:18 +00:00
|
|
|
const repo = this[model];
|
|
|
|
return repo.remove(instance);
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|