oak-pay-business/es/components/wpProduct/upsert/index.js

59 lines
1.4 KiB
JavaScript

import { getAppTypeFromProductType } from "../../../utils/wpProduct";
export default OakComponent({
entity: 'wpProduct',
isList: false,
projection: {
id: 1,
type: 1,
wpAccountId: 1,
applicationId: 1,
enabled: 1,
shipping: 1,
application: {
id: 1,
type: 1,
name: 1,
},
},
properties: {
systemId: '',
wpAccountId: '',
},
formData({ data, features }) {
const { systemId } = this.props;
const applications = data?.type && features.cache.get('application', {
data: {
id: 1,
name: 1,
type: 1,
},
filter: {
systemId,
wpProduct$application: {
"#sqp": 'not in',
enabled: true,
type: data.type,
},
type: {
$in: getAppTypeFromProductType(data.type),
}
}
});
return {
applications,
wpProduct: data,
};
},
lifetimes: {
ready() {
if (this.isCreation()) {
const { wpAccountId } = this.props;
this.update({
wpAccountId,
enabled: true,
});
}
}
}
});