refactor: rename populate

This commit is contained in:
Mohamed Marrouchi 2025-06-04 17:32:30 +01:00
parent 98d79488a9
commit 286d21e069
2 changed files with 9 additions and 9 deletions

View File

@ -139,7 +139,7 @@ export class SubscriberRepository extends BaseRepository<
* @returns The found subscriber entity with populated fields. * @returns The found subscriber entity with populated fields.
*/ */
async findOneByForeignIdAndPopulate(id: string): Promise<SubscriberFull> { async findOneByForeignIdAndPopulate(id: string): Promise<SubscriberFull> {
const query = this.findByForeignIdQuery(id).populate(this.populate); const query = this.findByForeignIdQuery(id).populate(this.populatePaths);
const [result] = await this.execute(query, SubscriberFull); const [result] = await this.execute(query, SubscriberFull);
return result; return result;
} }

View File

@ -94,14 +94,14 @@ export abstract class BaseRepository<
constructor( constructor(
readonly model: Model<T>, readonly model: Model<T>,
private readonly cls: new () => T, private readonly cls: new () => T,
protected readonly populate: P[] = [], protected readonly populatePaths: P[] = [],
protected readonly clsPopulate?: new () => TFull, protected readonly clsPopulate?: new () => TFull,
) { ) {
this.registerLifeCycleHooks(); this.registerLifeCycleHooks();
} }
canPopulate(populate: string[]): boolean { canPopulate(populate: string[]): boolean {
return populate.some((p) => this.populate.includes(p as P)); return populate.some((p) => this.populatePaths.includes(p as P));
} }
getEventName(suffix: EHook) { getEventName(suffix: EHook) {
@ -303,7 +303,7 @@ export abstract class BaseRepository<
): Promise<TFull | null> { ): Promise<TFull | null> {
this.ensureCanPopulate(); this.ensureCanPopulate();
const query = this.findOneQuery(criteria, projection).populate( const query = this.findOneQuery(criteria, projection).populate(
this.populate, this.populatePaths,
); );
return await this.executeOne(query, this.clsPopulate!); return await this.executeOne(query, this.clsPopulate!);
} }
@ -375,7 +375,7 @@ export abstract class BaseRepository<
} }
private ensureCanPopulate(): void { private ensureCanPopulate(): void {
if (!this.populate || !this.clsPopulate) { if (!this.populatePaths || !this.clsPopulate) {
throw new Error('Cannot populate query'); throw new Error('Cannot populate query');
} }
} }
@ -403,13 +403,13 @@ export abstract class BaseRepository<
this.ensureCanPopulate(); this.ensureCanPopulate();
if (Array.isArray(pageQuery)) { if (Array.isArray(pageQuery)) {
const query = this.findQuery(filters, pageQuery, projection).populate( const query = this.findQuery(filters, pageQuery, projection).populate(
this.populate, this.populatePaths,
); );
return await this.execute(query, this.clsPopulate!); return await this.execute(query, this.clsPopulate!);
} }
const query = this.findQuery(filters, pageQuery, projection).populate( const query = this.findQuery(filters, pageQuery, projection).populate(
this.populate, this.populatePaths,
); );
return await this.execute(query, this.clsPopulate!); return await this.execute(query, this.clsPopulate!);
} }
@ -426,7 +426,7 @@ export abstract class BaseRepository<
async findAllAndPopulate(sort?: QuerySortDto<T>): Promise<TFull[]> { async findAllAndPopulate(sort?: QuerySortDto<T>): Promise<TFull[]> {
this.ensureCanPopulate(); this.ensureCanPopulate();
const query = this.findAllQuery(sort).populate(this.populate); const query = this.findAllQuery(sort).populate(this.populatePaths);
return await this.execute(query, this.clsPopulate!); return await this.execute(query, this.clsPopulate!);
} }
@ -463,7 +463,7 @@ export abstract class BaseRepository<
): Promise<TFull[]> { ): Promise<TFull[]> {
this.ensureCanPopulate(); this.ensureCanPopulate();
const query = this.findPageQuery(filters, pageQuery).populate( const query = this.findPageQuery(filters, pageQuery).populate(
this.populate, this.populatePaths,
); );
return await this.execute(query, this.clsPopulate!); return await this.execute(query, this.clsPopulate!);
} }