feat(pipelines): merge stage-map util and shared DTOs
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
export type MergeStageLike = {
|
||||
id: string;
|
||||
name: string;
|
||||
isWon: boolean;
|
||||
isLost: boolean;
|
||||
};
|
||||
|
||||
export function dealStatusForStage(
|
||||
stage: Pick<MergeStageLike, 'isWon' | 'isLost'>,
|
||||
): 'open' | 'won' | 'lost' {
|
||||
if (stage.isWon) return 'won';
|
||||
if (stage.isLost) return 'lost';
|
||||
return 'open';
|
||||
}
|
||||
|
||||
export function assertStageMap(
|
||||
sourceStages: MergeStageLike[],
|
||||
targetStages: MergeStageLike[],
|
||||
stageMap: Record<string, string>,
|
||||
): void {
|
||||
const targetById = new Map(targetStages.map((s) => [s.id, s]));
|
||||
for (const src of sourceStages) {
|
||||
const tid = stageMap[src.id];
|
||||
if (!tid) {
|
||||
throw new Error(`همهٔ ستونهای مبدأ باید نگاشت شوند (ستون «${src.name}»).`);
|
||||
}
|
||||
const tgt = targetById.get(tid);
|
||||
if (!tgt) {
|
||||
throw new Error(`ستون مقصد برای «${src.name}» معتبر نیست.`);
|
||||
}
|
||||
if (src.isWon && !tgt.isWon) {
|
||||
throw new Error(`ستون برندهٔ «${src.name}» فقط به ستون برندهٔ مقصد نگاشت میشود.`);
|
||||
}
|
||||
if (src.isLost && !tgt.isLost) {
|
||||
throw new Error(`ستون از دسترفتهٔ «${src.name}» فقط به ستون از دسترفتهٔ مقصد نگاشت میشود.`);
|
||||
}
|
||||
if (!src.isWon && !src.isLost && (tgt.isWon || tgt.isLost)) {
|
||||
throw new Error(`ستون باز «${src.name}» را به ستون برد/باخت مقصد نگاشت نکنید.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user