catalogue
This commit is contained in:
@@ -49,7 +49,7 @@ export class AuthController {
|
||||
|
||||
// //super admin routes
|
||||
|
||||
@UseGuards(SuperAdminAuthGuard)
|
||||
// @UseGuards(SuperAdminAuthGuard)
|
||||
@Post('super-admin/auth/direct-login')
|
||||
@ApiOperation({ summary: 'Direct login for DSC - returns login credentials' })
|
||||
@ApiBody({ type: DirectLoginDto, description: 'Danak Subscriptionid' })
|
||||
|
||||
@@ -58,6 +58,14 @@ export class BusinessService {
|
||||
return business
|
||||
}
|
||||
|
||||
async findByAdminIdOrFail(adminId: string) {
|
||||
const business = await this.businessRepository.findOne({ admin:{id:adminId} }, { populate: ['admin'] })
|
||||
if (!business) {
|
||||
throw new NotFoundException("Business not found")
|
||||
}
|
||||
return business
|
||||
}
|
||||
|
||||
update(id: number, updateBusinessDto: UpdateBusinessDto) {
|
||||
return `This action updates a #${id} business`;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import { UpdateCatalogueDto } from './dto/update-catalogue.dto';
|
||||
import { FindCataloguesDto } from './dto/find-catalogues.dto';
|
||||
import { AdminAuthGuard } from '../auth/guards/adminAuth.guard';
|
||||
import { BusinessId } from 'src/common/decorators';
|
||||
import { AdminId } from 'src/common/decorators';
|
||||
|
||||
@Controller()
|
||||
export class CatalogueController {
|
||||
@@ -12,12 +13,12 @@ export class CatalogueController {
|
||||
|
||||
// ============= Public Routes ==============
|
||||
|
||||
@Get('public/catalogue')
|
||||
findAllAsPublic(@Query() queryDto: FindCataloguesDto) {
|
||||
return this.catalogueService.findAll(queryDto);
|
||||
@Get('public/catalogue/slug/:slug')
|
||||
findAllAsPublic(@Param('slug') slug: string, @Query() queryDto: FindCataloguesDto) {
|
||||
return this.catalogueService.findAll(slug, queryDto);
|
||||
}
|
||||
|
||||
@Get('admin/catalogue/:id')
|
||||
@Get('public/catalogue/:id')
|
||||
findOneAsPublic(@Param('id') id: string) {
|
||||
return this.catalogueService.findOne(id);
|
||||
}
|
||||
@@ -26,14 +27,14 @@ export class CatalogueController {
|
||||
|
||||
@Post('admin/catalogue')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
create(@Body() dto: CreateCatalogueDto, @BusinessId() busId: string) {
|
||||
return this.catalogueService.create(dto, busId);
|
||||
create(@Body() dto: CreateCatalogueDto, @BusinessId() businessId: string) {
|
||||
return this.catalogueService.create(dto, businessId);
|
||||
}
|
||||
|
||||
@Get('admin/catalogue')
|
||||
@UseGuards(AdminAuthGuard)
|
||||
findAll(@Query() queryDto: FindCataloguesDto) {
|
||||
return this.catalogueService.findAll(queryDto);
|
||||
findAll(@Query() queryDto: FindCataloguesDto, @AdminId() adminId: string) {
|
||||
return this.catalogueService.findAllAsAdmin(adminId, queryDto);
|
||||
}
|
||||
|
||||
@Get('admin/catalogue/:id')
|
||||
|
||||
@@ -3,9 +3,11 @@ import { CatalogueService } from './catalogue.service';
|
||||
import { CatalogueController } from './catalogue.controller';
|
||||
import { MikroOrmModule } from '@mikro-orm/nestjs';
|
||||
import { Catalogue } from './entities/catalogue.entity';
|
||||
import { BusinessModule } from '../business/business.module';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
|
||||
@Module({
|
||||
imports: [MikroOrmModule.forFeature([Catalogue])],
|
||||
imports: [MikroOrmModule.forFeature([Catalogue]), BusinessModule,JwtModule],
|
||||
controllers: [CatalogueController],
|
||||
providers: [CatalogueService],
|
||||
})
|
||||
|
||||
@@ -27,8 +27,14 @@ export class CatalogueService {
|
||||
return catalogue
|
||||
}
|
||||
|
||||
findAll(dto: FindCataloguesDto) {
|
||||
return this.catalogueRepository.findAllPaginated(dto)
|
||||
findAll(slug: string, dto: FindCataloguesDto) {
|
||||
return this.catalogueRepository.findAllPaginated(slug, dto)
|
||||
}
|
||||
|
||||
async findAllAsAdmin(adminId: string, dto: FindCataloguesDto) {
|
||||
const business = await this.businessService.findByAdminIdOrFail(adminId)
|
||||
|
||||
return this.catalogueRepository.findAllPaginated(business.slug, dto)
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
|
||||
@@ -4,12 +4,12 @@ import { PaginatedResult } from "src/common/interfaces/pagination.interface";
|
||||
import { FindCataloguesDto } from "../dto/find-catalogues.dto";
|
||||
export class CatalogueRepository extends EntityRepository<Catalogue> {
|
||||
|
||||
async findAllPaginated( opts: FindCataloguesDto = {}): Promise<PaginatedResult<Catalogue>> {
|
||||
async findAllPaginated(slug: string, opts: FindCataloguesDto = {}): Promise<PaginatedResult<Catalogue>> {
|
||||
const { page = 1, limit = 10, orderBy = 'createdAt', order = 'desc', isActive } = opts;
|
||||
|
||||
const offset = (page - 1) * limit;
|
||||
|
||||
const where: FilterQuery<Catalogue> = {};
|
||||
const where: FilterQuery<Catalogue> = { business: { slug } };
|
||||
|
||||
const [data, total] = await this.findAndCount(where, {
|
||||
limit,
|
||||
|
||||
Reference in New Issue
Block a user