oak-pay-business/es/components/sysAccount/survey/index.js

74 lines
2.1 KiB
JavaScript

import assert from 'assert';
import { uniq } from "oak-domain/lib/utils/lodash";
export default OakComponent({
properties: {
entities: [],
systemId: '',
},
lifetimes: {
ready() {
this.refreshData();
}
},
methods: {
refreshData() {
const { entities, systemId } = this.props;
const schema = this.features.cache.getSchema();
uniq(['wpAccount', 'offlineAccount'].concat(entities || [])).forEach((entity) => {
const projection = {
id: 1,
$$createAt$$: 1,
$$updateAt$$: 1,
};
Object.keys(schema[entity].attributes).forEach(ele => {
if (!ele.startsWith('$$')) {
projection[ele] = 1;
}
});
this.features.cache.refresh(entity, {
data: projection,
filter: {
systemId,
}
});
});
},
},
formData({ features }) {
const { entities, systemId } = this.props;
assert(systemId);
const schema = features.cache.getSchema();
let total = 0;
const accounts = uniq(['wpAccount', 'offlineAccount'].concat(entities || [])).map((entity) => {
const projection = {
id: 1,
$$createAt$$: 1,
$$updateAt$$: 1,
};
Object.keys(schema[entity].attributes).forEach(ele => {
if (!ele.startsWith('$$')) {
projection[ele] = 1;
}
});
const [data] = this.features.cache.get(entity, {
data: projection,
filter: {
systemId,
}
}, true);
const { price, id } = data;
total += price;
return {
entity,
id,
price,
data,
};
});
return {
total,
accounts,
};
}
});