Hello
Feature(s) impacted
collection.addOneToOneRelation()
collection.addOneToManyRelation()
Observed behavior
Important info: the relationships I add to my table can sometimes be null, i.e. there’s no data, this is deliberate.
When I add relationships to my beneficiaries table, I have a display problem that only occurs in certain cases.
Here is my code, which you can scroll down to see:
agent.customizeCollection('beneficiaries', collection => {
// RELATIONS
collection.addOneToOneRelation('np_contract', 'NP_contracts', {
originKey: 'fk_beneficiaryId',
originKeyTarget: 'id',
});
collection.addOneToOneRelation('np_subscription', 'NP_subscriptions', {
originKey: 'fk_beneficiaryId',
originKeyTarget: 'id',
});
collection.addOneToManyRelation('np_refundRequests', 'NP_refundRequests', {
originKey: 'fk_beneficiaryId',
originKeyTarget: 'id',
});
// collection.addOneToOneRelation('nv_contract', 'NV_contracts', {
// originKey: 'fk_beneficiaryId',
// originKeyTarget: 'id',
// });
collection.addOneToOneRelation('nv_subscription', 'NV_subscriptions', {
originKey: 'fk_beneficiaryId',
originKeyTarget: 'id',
});
// collection.addOneToManyRelation('nv_refundRequests', 'NV_refundRequests', {
// originKey: 'fk_beneficiaryId',
// originKeyTarget: 'id',
// });
// FIELDS
collection.importField('user_email', { path: 'fk_user:email', readonly: true});
collection.importField('user_phone', { path: 'fk_user:phone', readonly: true});
collection.importField('user_firstname', { path: 'fk_user:firstname', readonly: true});
collection.importField('user_status', { path: 'fk_user:status', readonly: true});
collection.importField('user_lastname', { path: 'fk_user:lastname', readonly: true});
collection.importField('user_gender', { path: 'fk_user:gender', readonly: true});
collection.importField('user_discoveryProcess', { path: 'fk_user:discoveryProcess', readonly: true});
collection.addField('np_subscription_amount', {
columnType: 'Number',
dependencies: ['np_subscription:rk_pspSubscriptionId'],
getValues: (records, context) =>
records.map(async r => {
if (r.np_subscription !== null) {
const invoices = await stripe.listInvoices({
subscription: r.np_subscription.rk_pspSubscriptionId,
status: 'paid'
});
if (invoices !== null) {
return invoices[0].amount_paid / 100;
}
return 0;
}
return 0;
}),
});
collection.importField('np_contract_subscriptionDate', { path: 'np_contract:subscriptionDate', readonly: true});
collection.importField('np_contract_startDate', { path: 'np_contract:subscriptionDate', readonly: true});
collection.importField('np_plan_title', { path: 'np_contract:fk_plan:title', readonly: true});
collection.importField('np_subscription_status', { path: 'np_subscription:status', readonly: true});
collection.addField('np_coupon_code', {
columnType: 'String',
dependencies: ['np_subscription:rk_pspSubscriptionId'],
getValues: (records, context) =>
records.map(async r => {
if (r.np_subscription !== null) {
const invoices = await stripe.listInvoices({
subscription: r.np_subscription.rk_pspSubscriptionId,
status: 'paid'
});
return invoices[0].discount?.coupon?.name;
}
return null;
}),
});
collection.addField('nv_subscription_amount', {
columnType: 'Number',
dependencies: ['nv_subscription:rk_pspSubscriptionId'],
getValues: (records, context) =>
records.map(async r => {
if (r.nv_subscription) {
const invoices = await stripe.listInvoices({
subscription: r.nv_subscription?.rk_pspSubscriptionId,
status: 'paid'
});
if (invoices !== null) {
return invoices[0].amount_paid / 100;
}
return 0;
}
return 0;
}),
});
// collection.importField('nv_contract_subscriptionDate', { path: 'nv_contract:subscriptionDate', readonly: true});
// collection.importField('nv_contract_startDate', { path: 'nv_contract:startDate', readonly: true});
// collection.importField('nv_product_name', { path: 'nv_contract:fk_product:name', readonly: true});
// collection.addField('nv_contract_beneficiaries', {
// columnType: 'String',
// dependencies: ['nv_contract:beneficiaries'],
// getValues: (records, context) =>
// records.map(r => {
// if (r.nv_contract?.beneficiaries?.length > 0) {
// return true
// }
// return false;
// }),
// });
// collection.importField('nv_contract_status', { path: 'nv_contract:status', readonly: true});
// collection.importField('nv_contract_adherentId', { path: 'nv_contract:rk_adherentId', readonly: true});
// collection.importField('nv_contract_endDate', { path: 'nv_contract:endDate', readonly: true});
// collection.addField('nv_subscription_type', {
// columnType: 'String',
// dependencies: ['nv_contract:filename'],
// getValues: (records, context) =>
// records.map(r => {
// if (r.nv_contract?.filename?.slice(0, 3) === "PV3") {
// return "PV3";
// }
// return '';
// }),
// });
// collection.addField('nv_coupon_code', {
// columnType: 'String',
// dependencies: ['nv_subscription:rk_pspSubscriptionId'],
// getValues: (records, context) =>
// records.map(async r => {
// if (r.nv_subscription !== null) {
// const invoices = await stripe.listInvoices({
// subscription: r.nv_subscription.rk_pspSubscriptionId,
// status: 'paid'
// });
// return invoices[0].discount?.coupon?.name;
// }
// return null;
// }),
// });
// collection.addField('nv_subscription_channel', {
// columnType: 'String',
// dependencies: ['nv_contract:filename'],
// getValues: (records, context) =>
// records.map(async r => {
// if (r.nv_contract?.filename?.slice(0, 3) === "PV3") {
// return "web";
// }
// return "app";
// }),
// });
// ACTIONS
});
if I comment on all relationships starting with nv_, everything is displayed correctly
and you can see the details when you click on it
But if I uncomment the relation that start with nv_, I can no longer access certain details.
But the surprising thing is that when I click on those with data beginning with nv_ , it works.
For the example, I click on the one with Nv subscription amount at 40.1
Whereas if I click on one that is 0 I get the error
In the logs server I have this
and console.log I have this : 500
I’ve seen in the other tables that everything is fine, it’s only this beneficiaries table where when I add these relationships, I have this little problem
Expected behavior
The relations I add can all be displayed, even if the data is empty in the relation I’m adding.
Context
- Project name: Nostrum Care v3
- Team name: Op
- Environment name: Local
- Agent (forest package) name & version:
“@forestadmin/agent”: “^1.0.0”,
“@forestadmin/datasource-sequelize”: “^1.5.21”,
“@forestadmin/datasource-sql”: “^1.0.0”,
“dotenv”: “^16.0.1”,
“pg”: “^8.8.0”,
“sequelize”: “^6.33.0”,
“stripe”: “^14.17.0” - Database type: Postgresql
Thank you in advance for your help !!