Small refactoring
This commit is contained in:
		
							parent
							
								
									8e02bf62bf
								
							
						
					
					
						commit
						edefd702a8
					
				| 
						 | 
				
			
			@ -20,8 +20,4 @@ export default class ExoCommands {
 | 
			
		|||
			new CreateEffortExoCommand(ctx)
 | 
			
		||||
		];
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	static bySlug(ctx: ExoContext, slug: string): ExoCommand | undefined {
 | 
			
		||||
		return ExoCommands.all(ctx).find(c => c.slug === slug);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -118,10 +118,6 @@ export default class AppUtils {
 | 
			
		|||
		return this.app.vault.getMarkdownFiles();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	getFileCache(file: TFile): CachedMetadata | null {
 | 
			
		||||
		return this.app.metadataCache.getFileCache(file);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	findMdWith(filter: (f: TFile) => boolean) {
 | 
			
		||||
		return this.getAllMdFiles().filter(filter);
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,7 +25,7 @@ export default class KObjectUtility {
 | 
			
		|||
 | 
			
		||||
		for (let f of withoutId) {
 | 
			
		||||
			await this.ctx.app.fileManager.processFrontMatter(f, (frontmatter) => {
 | 
			
		||||
				frontmatter['uid'] = crypto.randomUUID();
 | 
			
		||||
				frontmatter['uid'] = this.ctx.utils.generateUid();
 | 
			
		||||
			});
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,7 @@ import {UUID} from "node:crypto";
 | 
			
		|||
import ExoContext from "../../../../common/ExoContext";
 | 
			
		||||
 | 
			
		||||
export default abstract class AbstractCreator<KO> {
 | 
			
		||||
	constructor(protected ctx: ExoContext) {
 | 
			
		||||
	protected constructor(protected ctx: ExoContext) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	async create(file: TFile): Promise<KO> {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,7 +38,7 @@ export default class ExoContext {
 | 
			
		|||
	public readonly effortPathRulesHelper: EffortPathRulesHelper;
 | 
			
		||||
 | 
			
		||||
	constructor(public app: App) {
 | 
			
		||||
		this.utils = new Utils(this.app);
 | 
			
		||||
		this.utils = new Utils();
 | 
			
		||||
		this.appUtils = new AppUtils(this.app);
 | 
			
		||||
		this.layoutFactory = new LayoutFactory(this);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -53,7 +53,7 @@ export default class ExoContext {
 | 
			
		|||
		this.countNotesUseCase = new CountNotesService(this.appUtils);
 | 
			
		||||
		this.getCurrentDNUseCase = new GetCurrentDailyNoteService(this.dailyNoteRepository);
 | 
			
		||||
		this.effortRepository = new EffortPersistenceAdapter(this);
 | 
			
		||||
		this.createEffortUseCase = new CreateEffortService(this.effortRepository);
 | 
			
		||||
		this.createEffortUseCase = new CreateEffortService(this);
 | 
			
		||||
		this.effortPathRulesHelper = new EffortPathRulesHelper(this);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,30 +1,29 @@
 | 
			
		|||
import CreateEffortUseCase from "../ports/input/CreateEffortUseCase";
 | 
			
		||||
import Area from "../domain/Area";
 | 
			
		||||
import {EffortStatus} from "../domain/effort/EffortStatus";
 | 
			
		||||
import EffortRepository from "../ports/output/EffortRepository";
 | 
			
		||||
import {UUID} from "node:crypto";
 | 
			
		||||
import Effort from "../domain/effort/Effort";
 | 
			
		||||
import ExoContext from "../../../common/ExoContext";
 | 
			
		||||
 | 
			
		||||
export default class CreateEffortService implements CreateEffortUseCase {
 | 
			
		||||
	constructor(private effortRepository: EffortRepository) {
 | 
			
		||||
	constructor(private ctx: ExoContext) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	async taskUnderArea(area: Area): Promise<Effort> {
 | 
			
		||||
		const title = crypto.randomUUID();
 | 
			
		||||
		const id = crypto.randomUUID() as UUID;
 | 
			
		||||
		const title = this.ctx.utils.generateUid();
 | 
			
		||||
		const id = this.ctx.utils.generateUid();
 | 
			
		||||
		const effort = new Effort(id, title, EffortStatus.DRAFT, null, null, area, null, "Body");
 | 
			
		||||
 | 
			
		||||
		await this.effortRepository.save(effort);
 | 
			
		||||
		await this.ctx.effortRepository.save(effort);
 | 
			
		||||
 | 
			
		||||
		return effort;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	async taskUnderEffort(parentEffort: Effort): Promise<Effort> {
 | 
			
		||||
		const title = crypto.randomUUID();
 | 
			
		||||
		const id = crypto.randomUUID() as UUID;
 | 
			
		||||
		const title = this.ctx.utils.generateUid();
 | 
			
		||||
		const id = this.ctx.utils.generateUid();
 | 
			
		||||
		const effort = new Effort(id, title, EffortStatus.DRAFT, null, null, null, parentEffort, "Body");
 | 
			
		||||
 | 
			
		||||
		await this.effortRepository.save(effort);
 | 
			
		||||
		await this.ctx.effortRepository.save(effort);
 | 
			
		||||
 | 
			
		||||
		return effort;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,12 +1,7 @@
 | 
			
		|||
import {App} from "obsidian";
 | 
			
		||||
import {UUID} from "node:crypto";
 | 
			
		||||
 | 
			
		||||
export default class Utils {
 | 
			
		||||
 | 
			
		||||
	constructor(private app: App) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	generateUid(): string {
 | 
			
		||||
		return crypto.randomUUID();
 | 
			
		||||
	generateUid(): UUID {
 | 
			
		||||
		return crypto.randomUUID() as UUID;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue