// ex) offJoin = ["Company.User", "Partner"],
export const modifyWithOptions = (withOptions: any, offJoin: string[] | undefined, path: string = ''): any => {
if (!offJoin) {
return withOptions;
}
return Object.keys(withOptions).reduce((acc, key) => {
const currentPath = path ? `${path}.${key}` : key;
if (offJoin.includes(currentPath)) {
return acc;
}
const value = withOptions[key];
if (value.with) {
value.with = modifyWithOptions(value.with, offJoin, currentPath);
}
return { ...acc, [key]: value };
}, {});
};
const result = await dbToUse.query.user.findMany({
columns: { password: false },
...queryOptions,
with: modifyWithOptions(
{
Company: {
columns: companyJoinColumns,
with: { Users: true },
},
Partner: { columns: companyJoinColumns },
},
params.offJoin
),
});
//I want to use type inference in the modifyWithOptions function and have the data I include with in the results of findMany appear as recommendations.
// ex) offJoin = ["Company.User", "Partner"],
export const modifyWithOptions = (withOptions: any, offJoin: string[] | undefined, path: string = ''): any => {
if (!offJoin) {
return withOptions;
}
return Object.keys(withOptions).reduce((acc, key) => {
const currentPath = path ? `${path}.${key}` : key;
if (offJoin.includes(currentPath)) {
return acc;
}
const value = withOptions[key];
if (value.with) {
value.with = modifyWithOptions(value.with, offJoin, currentPath);
}
return { ...acc, [key]: value };
}, {});
};
const result = await dbToUse.query.user.findMany({
columns: { password: false },
...queryOptions,
with: modifyWithOptions(
{
Company: {
columns: companyJoinColumns,
with: { Users: true },
},
Partner: { columns: companyJoinColumns },
},
params.offJoin
),
});
//I want to use type inference in the modifyWithOptions function and have the data I include with in the results of findMany appear as recommendations.