mirror of
https://github.com/hexastack/hexabot
synced 2025-02-22 12:28:26 +00:00
fix(api): remove duplicated populate methods
This commit is contained in:
parent
5681a810aa
commit
8442b85a85
@ -9,7 +9,7 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { FilterQuery, Model } from 'mongoose';
|
||||
import { Model } from 'mongoose';
|
||||
|
||||
import { BaseRepository } from '@/utils/generics/base-repository';
|
||||
|
||||
@ -49,20 +49,4 @@ export class ConversationRepository extends BaseRepository<
|
||||
async end(convo: Conversation | ConversationFull) {
|
||||
return await this.updateOne(convo.id, { active: false });
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a single conversation by a given criteria and populates the related fields: `sender`, `current`, and `next`.
|
||||
*
|
||||
* @param criteria The search criteria, either a string or a filter query.
|
||||
*
|
||||
* @returns A promise resolving to the populated conversation full object.
|
||||
*/
|
||||
async findOneAndPopulate(criteria: string | FilterQuery<Conversation>) {
|
||||
const query = this.findOneQuery(criteria).populate([
|
||||
'sender',
|
||||
'current',
|
||||
'next',
|
||||
]);
|
||||
return await this.executeOne(query, ConversationFull);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model, TFilterQuery } from 'mongoose';
|
||||
import { Model } from 'mongoose';
|
||||
|
||||
import { BaseRepository } from '@/utils/generics/base-repository';
|
||||
|
||||
@ -32,38 +32,4 @@ export class PermissionRepository extends BaseRepository<
|
||||
) {
|
||||
super(eventEmitter, model, Permission, PERMISSION_POPULATE, PermissionFull);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all permissions and populates the `model` and `role` relationships.
|
||||
*
|
||||
* @returns A list of populated permission entities.
|
||||
*/
|
||||
async findAllAndPopulate() {
|
||||
const query = this.findAllQuery().populate(['model', 'role']);
|
||||
return await this.execute(query, PermissionFull);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds permissions based on the specified filter and populates the `model` and `role` relationships.
|
||||
*
|
||||
* @param filter - The filter query for finding permissions.
|
||||
*
|
||||
* @returns A list of populated permission entities matching the filter.
|
||||
*/
|
||||
async findAndPopulate(filter: TFilterQuery<Permission>) {
|
||||
const query = this.findQuery(filter).populate(['model', 'role']);
|
||||
return await this.execute(query, PermissionFull);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a single permission by its ID and populates the `model` and `role` relationships.
|
||||
*
|
||||
* @param id - The ID of the permission to find.
|
||||
*
|
||||
* @returns The populated permission entity.
|
||||
*/
|
||||
async findOneAndPopulate(id: string) {
|
||||
const query = this.findOneQuery(id).populate(['model', 'role']);
|
||||
return await this.executeOne(query, PermissionFull);
|
||||
}
|
||||
}
|
||||
|
@ -9,10 +9,9 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model, TFilterQuery } from 'mongoose';
|
||||
import { Model } from 'mongoose';
|
||||
|
||||
import { BaseRepository } from '@/utils/generics/base-repository';
|
||||
import { PageQueryDto } from '@/utils/pagination/pagination-query.dto';
|
||||
|
||||
import { Permission } from '../schemas/permission.schema';
|
||||
import {
|
||||
@ -51,35 +50,4 @@ export class RoleRepository extends BaseRepository<
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and paginates Role entities based on filter criteria, and populates related fields.
|
||||
*
|
||||
* @param filter Filter criteria for querying Role entities.
|
||||
* @param pageQuery Pagination details.
|
||||
*
|
||||
* @returns Paginated result of Role entities populated with related permissions and users.
|
||||
*/
|
||||
async findPageAndPopulate(
|
||||
filter: TFilterQuery<Role>,
|
||||
pageQuery: PageQueryDto<Role>,
|
||||
) {
|
||||
const query = this.findPageQuery(filter, pageQuery).populate([
|
||||
'permissions',
|
||||
'users',
|
||||
]);
|
||||
return await this.execute(query, RoleFull);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a single Role entity by its ID, and populates related fields.
|
||||
*
|
||||
* @param id The ID of the Role to find.
|
||||
*
|
||||
* @returns The found Role entity populated with related permissions and users.
|
||||
*/
|
||||
async findOneAndPopulate(id: string) {
|
||||
const query = this.findOneQuery(id).populate(['permissions', 'users']);
|
||||
return await this.executeOne(query, RoleFull);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user