allowing admin to choose which folders get synced
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { InvalidRequestError } from './core/errors.ts';
|
||||
import { applyExclusions } from './core/exclusion.ts';
|
||||
import type { Project, ProjectChanges } from './core/model.ts';
|
||||
import { withStatus } from './core/plan.ts';
|
||||
import type {
|
||||
@@ -26,6 +27,13 @@ export interface ProjectEdit {
|
||||
targetInput?: string;
|
||||
}
|
||||
|
||||
export interface FolderSyncChoice {
|
||||
/** Every folder the form offered. */
|
||||
shown: string[];
|
||||
/** The ones left ticked. */
|
||||
synced: string[];
|
||||
}
|
||||
|
||||
export interface ProjectServiceDeps {
|
||||
projects: ProjectRepository;
|
||||
items: ItemRepository;
|
||||
@@ -89,6 +97,31 @@ export class ProjectService {
|
||||
await this.deps.projects.delete(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves which of the folders on the admin's form sync. Folders that weren't on the form
|
||||
* (e.g. deleted in SharePoint since) keep their setting. The status view updates straight
|
||||
* away; ACC catches up on the next run.
|
||||
*/
|
||||
async setFolderSync(id: number, choice: FolderSyncChoice): Promise<void> {
|
||||
const project = await this.requireIdle(id);
|
||||
const items = new Map(
|
||||
(await this.deps.items.listByProject(id)).map((item) => [item.sourceId, item])
|
||||
);
|
||||
const shown = new Set(choice.shown);
|
||||
const synced = new Set(choice.synced);
|
||||
const excludedFolderIds = [
|
||||
...project.excludedFolderIds.filter((folderId) => !shown.has(folderId)),
|
||||
...[...shown].filter(
|
||||
(folderId) => !synced.has(folderId) && items.get(folderId)?.desired.isFolder
|
||||
)
|
||||
];
|
||||
|
||||
await this.deps.projects.update(id, { excludedFolderIds });
|
||||
const rootId = project.source.rootItemId;
|
||||
const { maxAttempts } = this.deps;
|
||||
await this.deps.items.save(id, applyExclusions(rootId, items, excludedFolderIds, maxAttempts));
|
||||
}
|
||||
|
||||
/** Give a failed item a fresh set of attempts on the next run. */
|
||||
async retryItem(projectId: number, sourceId: string): Promise<void> {
|
||||
await this.requireIdle(projectId);
|
||||
|
||||
Reference in New Issue
Block a user