add scope to contact
This commit is contained in:
@@ -17,6 +17,7 @@ import { FindContactsDto } from '../dto/find-contacts.dto';
|
|||||||
import { UpdateContactStatusDto } from '../dto/update-contact-status.dto';
|
import { UpdateContactStatusDto } from '../dto/update-contact-status.dto';
|
||||||
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam, ApiQuery, ApiHeader } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam, ApiQuery, ApiHeader } from '@nestjs/swagger';
|
||||||
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
||||||
|
import { SuperAdminAuthGuard } from 'src/modules/auth/guards/superAdminAuth.guard';
|
||||||
|
|
||||||
@ApiTags('contact')
|
@ApiTags('contact')
|
||||||
@Controller()
|
@Controller()
|
||||||
@@ -37,6 +38,8 @@ export class ContactController {
|
|||||||
return this.contactService.create(createContactDto);
|
return this.contactService.create(createContactDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@UseGuards(AdminAuthGuard)
|
@UseGuards(AdminAuthGuard)
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@Get('admin/contact')
|
@Get('admin/contact')
|
||||||
@@ -48,7 +51,7 @@ export class ContactController {
|
|||||||
@ApiQuery({ name: 'order', required: false, enum: ['asc', 'desc'] })
|
@ApiQuery({ name: 'order', required: false, enum: ['asc', 'desc'] })
|
||||||
@ApiQuery({ name: 'status', required: false, enum: ['new', 'seen'] })
|
@ApiQuery({ name: 'status', required: false, enum: ['new', 'seen'] })
|
||||||
async findAllPaginated(@Query() dto: FindContactsDto) {
|
async findAllPaginated(@Query() dto: FindContactsDto) {
|
||||||
return this.contactService.findAllPaginated(dto);
|
return this.contactService.findAllPaginatedAdmin(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(AdminAuthGuard)
|
@UseGuards(AdminAuthGuard)
|
||||||
@@ -78,4 +81,27 @@ export class ContactController {
|
|||||||
async remove(@Param('id') id: string) {
|
async remove(@Param('id') id: string) {
|
||||||
await this.contactService.remove(id);
|
await this.contactService.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(SuperAdminAuthGuard)
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@Get('super-admin/contact')
|
||||||
|
@ApiOperation({ summary: 'Get paginated list of contacts (admin only)' })
|
||||||
|
@ApiQuery({ name: 'page', required: false, type: Number })
|
||||||
|
@ApiQuery({ name: 'limit', required: false, type: Number })
|
||||||
|
@ApiQuery({ name: 'search', required: false, type: String })
|
||||||
|
@ApiQuery({ name: 'orderBy', required: false, type: String })
|
||||||
|
@ApiQuery({ name: 'order', required: false, enum: ['asc', 'desc'] })
|
||||||
|
@ApiQuery({ name: 'status', required: false, enum: ['new', 'seen'] })
|
||||||
|
async findAllPaginatedForSuper(@Query() dto: FindContactsDto) {
|
||||||
|
return this.contactService.findAllPaginatedSuper(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@UseGuards(SuperAdminAuthGuard)
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@Get('super-admin/contact/:id')
|
||||||
|
@ApiOperation({ summary: 'Get contact details by ID (admin only)' })
|
||||||
|
@ApiParam({ name: 'id', description: 'Contact ID' })
|
||||||
|
async findOneForSuper(@Param('id') id: string) {
|
||||||
|
return this.contactService.findOne(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ export enum ContactStatusEnum {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum ContactScope {
|
export enum ContactScope {
|
||||||
New = 'application',
|
APPLICATION = 'application',
|
||||||
Seen = 'restaurant',
|
RESTAURANT = 'restaurant',
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { Contact } from '../entities/contact.entity';
|
|||||||
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
||||||
import { ContactStatusEnum } from '../interface/interface';
|
import { ContactStatusEnum } from '../interface/interface';
|
||||||
import { EntityManager } from '@mikro-orm/postgresql';
|
import { EntityManager } from '@mikro-orm/postgresql';
|
||||||
|
import { ContactScope } from '../interface/interface';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ContactService {
|
export class ContactService {
|
||||||
@@ -24,7 +25,7 @@ export class ContactService {
|
|||||||
return contact;
|
return contact;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAllPaginated(dto: FindContactsDto): Promise<PaginatedResult<Contact>> {
|
async findAllPaginatedAdmin(dto: FindContactsDto): Promise<PaginatedResult<Contact>> {
|
||||||
return this.contactRepository.findAllPaginated({
|
return this.contactRepository.findAllPaginated({
|
||||||
page: dto.page,
|
page: dto.page,
|
||||||
limit: dto.limit,
|
limit: dto.limit,
|
||||||
@@ -32,6 +33,18 @@ export class ContactService {
|
|||||||
orderBy: dto.orderBy,
|
orderBy: dto.orderBy,
|
||||||
order: dto.order,
|
order: dto.order,
|
||||||
status: dto.status,
|
status: dto.status,
|
||||||
|
scope: ContactScope.RESTAURANT
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async findAllPaginatedSuper(dto: FindContactsDto): Promise<PaginatedResult<Contact>> {
|
||||||
|
return this.contactRepository.findAllPaginated({
|
||||||
|
page: dto.page,
|
||||||
|
limit: dto.limit,
|
||||||
|
search: dto.search,
|
||||||
|
orderBy: dto.orderBy,
|
||||||
|
order: dto.order,
|
||||||
|
status: dto.status,
|
||||||
|
scope: ContactScope.APPLICATION
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { EntityManager, EntityRepository } from '@mikro-orm/postgresql';
|
|||||||
import { FilterQuery } from '@mikro-orm/core';
|
import { FilterQuery } from '@mikro-orm/core';
|
||||||
import { Contact } from '../entities/contact.entity';
|
import { Contact } from '../entities/contact.entity';
|
||||||
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
|
||||||
import { ContactStatusEnum } from '../interface/interface';
|
import { ContactScope, ContactStatusEnum } from '../interface/interface';
|
||||||
|
|
||||||
type FindContactsOpts = {
|
type FindContactsOpts = {
|
||||||
page?: number;
|
page?: number;
|
||||||
@@ -12,6 +12,7 @@ type FindContactsOpts = {
|
|||||||
orderBy?: string;
|
orderBy?: string;
|
||||||
order?: 'asc' | 'desc';
|
order?: 'asc' | 'desc';
|
||||||
status?: ContactStatusEnum;
|
status?: ContactStatusEnum;
|
||||||
|
scope?: ContactScope
|
||||||
};
|
};
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -25,7 +26,7 @@ export class ContactRepository extends EntityRepository<Contact> {
|
|||||||
* Supports: search (subject/content/phone), status, ordering.
|
* Supports: search (subject/content/phone), status, ordering.
|
||||||
*/
|
*/
|
||||||
async findAllPaginated(opts: FindContactsOpts = {}): Promise<PaginatedResult<Contact>> {
|
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;
|
const offset = (page - 1) * limit;
|
||||||
|
|
||||||
@@ -34,6 +35,9 @@ export class ContactRepository extends EntityRepository<Contact> {
|
|||||||
if (status) {
|
if (status) {
|
||||||
where.status = status;
|
where.status = status;
|
||||||
}
|
}
|
||||||
|
if (scope) {
|
||||||
|
where.scope = scope;
|
||||||
|
}
|
||||||
|
|
||||||
if (search) {
|
if (search) {
|
||||||
const pattern = `%${search}%`;
|
const pattern = `%${search}%`;
|
||||||
|
|||||||
Reference in New Issue
Block a user