guard against errors when there are no results in certain contact queries

This commit is contained in:
2026-01-12 20:14:39 -07:00
parent 662da79df8
commit b6704b348b

View File

@@ -1507,7 +1507,7 @@ export const PlatformServiceMixin = {
"SELECT label FROM contact_labels WHERE did = ? ORDER BY label",
[did],
)) as QueryExecResult;
return results.values.map((r: SqlValue[]) => r[0] as string);
return results?.values?.map((r: SqlValue[]) => r[0] as string) || [];
} catch (error) {
logger.error(
`[PlatformServiceMixin] Error getting labels for contact ${did}:`,
@@ -1531,14 +1531,15 @@ export const PlatformServiceMixin = {
[...labels],
)) as QueryExecResult;
// count the occurrences of each did
const didCounts: Record<string, number> = results.values?.reduce(
(acc: Record<string, number>, curr: SqlValue[]) => {
acc[curr[0] as unknown as string] =
(acc[curr[0] as unknown as string] || 0) + 1;
return acc;
},
{},
);
const didCounts: Record<string, number> =
results?.values?.reduce(
(acc: Record<string, number>, curr: SqlValue[]) => {
acc[curr[0] as unknown as string] =
(acc[curr[0] as unknown as string] || 0) + 1;
return acc;
},
{},
) || {};
// filter out the dids that do not occur for as many labels as there are labels
const contactIdsWithAllLabels = Object.keys(didCounts).filter(
(did: string) => didCounts[did] === numberOfLabels,
@@ -1606,7 +1607,7 @@ export const PlatformServiceMixin = {
const results = (await this.$dbQuery(
"SELECT DISTINCT label FROM contact_labels ORDER BY label",
)) as QueryExecResult;
return results.values?.map((r: SqlValue[]) => r[0] as string) || [];
return results?.values?.map((r: SqlValue[]) => r[0] as string) || [];
} catch (error) {
logger.error(
"[PlatformServiceMixin] Error getting unique labels:",