MED-238: Fix "client.auth.getUser" cannot be used in job context
This commit is contained in:
@@ -507,11 +507,24 @@ class UserAnalysesApi {
|
||||
if (!analysisOrderId) {
|
||||
return;
|
||||
}
|
||||
const { data, error: userError } = await this.client.auth.getUser();
|
||||
if (userError) {
|
||||
throw userError;
|
||||
const analysisOrder = await this.getAnalysisOrder({ analysisOrderId });
|
||||
const userId = analysisOrder.user_id;
|
||||
const { data: account } = await this.client
|
||||
.schema('medreport')
|
||||
.from('accounts')
|
||||
.select('id')
|
||||
.eq('primary_owner_user_id', userId)
|
||||
.maybeSingle()
|
||||
.throwOnError();
|
||||
|
||||
const accountId = account?.id;
|
||||
if (!accountId) {
|
||||
console.warn(
|
||||
`Order ${analysisOrderId} got new responses but no account found for user_id=${userId}. Skipping notification.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
const { user } = data;
|
||||
|
||||
const notificationsApi = createNotificationsApi(this.client);
|
||||
const { t } = await createI18nServerInstance();
|
||||
|
||||
@@ -521,7 +534,7 @@ class UserAnalysesApi {
|
||||
|
||||
if (hasFullAnalysisResponse || hasPartialAnalysisResponse) {
|
||||
await notificationsApi.createNotification({
|
||||
account_id: user.id,
|
||||
account_id: accountId,
|
||||
body: t('analysis-results:notification.body'),
|
||||
link: `${pathsConfig.app.analysisResults}/${analysisOrderId}`,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user