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