Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[connectors] Include isolated Categories in Zendesk article incremental sync #8908

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions connectors/src/connectors/zendesk/temporal/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,25 @@ export async function syncZendeskBrandActivity({
}

/**
* Retrieves the IDs of every brand stored in db that has read permissions on their Help Center.
* Retrieves the IDs of every brand in db that has read permissions on their Help Center or in one of their Categories.
* This activity will be used to retrieve the brands that need to be incrementally synced.
*
* Note: in this approach; if a single category has read permissions and not its Help Center,
* diffs for the whole Help Center are fetched since there is no endpoint that returns the diff for the Category.
*/
export async function getZendeskHelpCenterReadAllowedBrandIdsActivity(
connectorId: ModelId
): Promise<number[]> {
return ZendeskBrandResource.fetchHelpCenterReadAllowedBrandIds(connectorId);
// fetching the brands that have a Help Center selected as a whole
const brandsWithHelpCenter =
await ZendeskBrandResource.fetchHelpCenterReadAllowedBrandIds(connectorId);
// fetching the brands that have at least one Category selected
const brandWithCategories =
await ZendeskCategoryResource.fetchBrandIdsOfReadOnlyCategories(
connectorId
);
// removing duplicates
return [...new Set([...brandsWithHelpCenter, ...brandWithCategories])];
}

/**
Expand Down
12 changes: 11 additions & 1 deletion connectors/src/resources/zendesk_resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
ModelStatic,
Transaction,
} from "sequelize";
import { Op } from "sequelize";
import { col, fn, Op } from "sequelize";

import {
getArticleInternalId,
Expand Down Expand Up @@ -498,6 +498,16 @@ export class ZendeskCategoryResource extends BaseResource<ZendeskCategory> {
return categories.map((category) => category.get().categoryId);
}

static async fetchBrandIdsOfReadOnlyCategories(
connectorId: number
): Promise<number[]> {
const categories = await ZendeskCategory.findAll({
where: { connectorId, permission: "read" },
attributes: [[fn("DISTINCT", col("brandId")), "brandId"]],
});
return categories.map((category) => category.get().brandId);
}

static async fetchByBrandIdReadOnly({
connectorId,
brandId,
Expand Down