add scope to contact
This commit is contained in:
@@ -3,7 +3,7 @@ import { EntityManager, EntityRepository } from '@mikro-orm/postgresql';
|
||||
import { FilterQuery } from '@mikro-orm/core';
|
||||
import { Contact } from '../entities/contact.entity';
|
||||
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
||||
import { ContactStatusEnum } from '../interface/interface';
|
||||
import { ContactScope, ContactStatusEnum } from '../interface/interface';
|
||||
|
||||
type FindContactsOpts = {
|
||||
page?: number;
|
||||
@@ -12,6 +12,7 @@ type FindContactsOpts = {
|
||||
orderBy?: string;
|
||||
order?: 'asc' | 'desc';
|
||||
status?: ContactStatusEnum;
|
||||
scope?: ContactScope
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
@@ -25,7 +26,7 @@ export class ContactRepository extends EntityRepository<Contact> {
|
||||
* Supports: search (subject/content/phone), status, ordering.
|
||||
*/
|
||||
async findAllPaginated(opts: FindContactsOpts = {}): Promise<PaginatedResult<Contact>> {
|
||||
const { page = 1, limit = 10, search, orderBy = 'createdAt', order = 'desc', status } = opts;
|
||||
const { page = 1, limit = 10, search, scope, orderBy = 'createdAt', order = 'desc', status } = opts;
|
||||
|
||||
const offset = (page - 1) * limit;
|
||||
|
||||
@@ -34,6 +35,9 @@ export class ContactRepository extends EntityRepository<Contact> {
|
||||
if (status) {
|
||||
where.status = status;
|
||||
}
|
||||
if (scope) {
|
||||
where.scope = scope;
|
||||
}
|
||||
|
||||
if (search) {
|
||||
const pattern = `%${search}%`;
|
||||
|
||||
Reference in New Issue
Block a user