business list
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
export { BusinessSlug } from './rest-slug.decorator';
|
||||
export { AdminId } from './admin-id.decorator';
|
||||
export { BusinessId } from './business-id.decorator';
|
||||
export { RateLimit } from './rate-limit.decorator';
|
||||
|
||||
@@ -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' })
|
||||
|
||||
@@ -12,8 +12,7 @@ import { Request } from 'express';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { IAdminTokenPayload } from '../interfaces/IToken-payload';
|
||||
import { PERMISSIONS_KEY } from '../../../common/decorators/permissions.decorator';
|
||||
|
||||
|
||||
export interface AdminAuthRequest extends Request {
|
||||
adminId: string;
|
||||
restId: string;
|
||||
@@ -62,12 +61,12 @@ export class AdminAuthGuard implements CanActivate {
|
||||
request['restId'] = payload.restId;
|
||||
|
||||
// check if the user has the required permissions
|
||||
const requiredPermissions =
|
||||
this.reflector.getAllAndOverride<string[]>(PERMISSIONS_KEY, [context.getHandler(), context.getClass()]) ?? [];
|
||||
// const requiredPermissions =
|
||||
// this.reflector.getAllAndOverride<string[]>(PERMISSIONS_KEY, [context.getHandler(), context.getClass()]) ?? [];
|
||||
|
||||
if (!requiredPermissions || requiredPermissions.length === 0) {
|
||||
return true;
|
||||
}
|
||||
// if (!requiredPermissions || requiredPermissions.length === 0) {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -21,10 +21,10 @@ export class AuthService {
|
||||
|
||||
async directLogin(danakSubId: string) {
|
||||
const business = await this.businessService.findBySubIdOrFail(danakSubId)
|
||||
console.log(business)
|
||||
const admin = business.admin
|
||||
console.log(admin)
|
||||
const tokens = await this.tokensService.generateAccessAndRefreshToken(admin.id, business.id);
|
||||
return tokens
|
||||
return { tokens }
|
||||
}
|
||||
|
||||
// async requestOtp(dto: RequestOtpDto, isAdmin: boolean) {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common';
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Query } from '@nestjs/common';
|
||||
import { BusinessService } from './business.service';
|
||||
import { SetupBusinessDto } from './dto/create-business.dto';
|
||||
import { UpdateBusinessDto } from './dto/update-business.dto';
|
||||
import { SuperAdminAuthGuard } from '../auth/guards/superAdminAuth.guard';
|
||||
import { FindBusinessesDto } from './dto/find-businesses.dto';
|
||||
|
||||
@Controller('super-admin/business')
|
||||
@UseGuards(SuperAdminAuthGuard)
|
||||
export class BusinessController {
|
||||
constructor(private readonly businessService: BusinessService) { }
|
||||
|
||||
@@ -14,9 +16,9 @@ export class BusinessController {
|
||||
return this.businessService.setupAccount(dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.businessService.findAll();
|
||||
@Get('list')
|
||||
findAll(@Query() dto :FindBusinessesDto) {
|
||||
return this.businessService.findAll(dto);
|
||||
}
|
||||
|
||||
// @Get(':id')
|
||||
|
||||
@@ -5,6 +5,7 @@ import { EntityManager } from '@mikro-orm/postgresql';
|
||||
import { Business } from './entities/business.entity';
|
||||
import { Admin } from '../admin/entities/admin.entity';
|
||||
import { BusinessRepository } from './repositories/business.repository';
|
||||
import { FindBusinessesDto } from './dto/find-businesses.dto';
|
||||
|
||||
@Injectable()
|
||||
export class BusinessService {
|
||||
@@ -38,8 +39,8 @@ export class BusinessService {
|
||||
return business
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all business`;
|
||||
findAll(dto: FindBusinessesDto) {
|
||||
return this.businessRepository.findAllPaginated(dto)
|
||||
}
|
||||
|
||||
async findBySubIdOrFail(danakSubscriptionId: string) {
|
||||
@@ -51,7 +52,7 @@ export class BusinessService {
|
||||
}
|
||||
|
||||
async findByIdOrFail(businessId: string) {
|
||||
const business = await this.businessRepository.findOne({ id:businessId }, { populate: ['admin'] })
|
||||
const business = await this.businessRepository.findOne({ id: businessId }, { populate: ['admin'] })
|
||||
if (!business) {
|
||||
throw new NotFoundException("Business not found")
|
||||
}
|
||||
@@ -59,7 +60,7 @@ export class BusinessService {
|
||||
}
|
||||
|
||||
async findByAdminIdOrFail(adminId: string) {
|
||||
const business = await this.businessRepository.findOne({ admin:{id:adminId} }, { populate: ['admin'] })
|
||||
const business = await this.businessRepository.findOne({ admin: { id: adminId } }, { populate: ['admin'] })
|
||||
if (!business) {
|
||||
throw new NotFoundException("Business not found")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { IsOptional, IsNumber, IsString, IsIn, IsBoolean } from 'class-validator';
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
|
||||
export class FindBusinessesDto {
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@Type(() => Number)
|
||||
@ApiPropertyOptional({ example: 1 })
|
||||
page?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@Type(() => Number)
|
||||
@ApiPropertyOptional({ example: 10 })
|
||||
limit?: number;
|
||||
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiPropertyOptional({ example: 'createdAt' })
|
||||
orderBy?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsIn(['asc', 'desc'])
|
||||
@ApiPropertyOptional({ example: 'desc' })
|
||||
order?: 'asc' | 'desc';
|
||||
|
||||
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@Type(() => Boolean)
|
||||
@ApiPropertyOptional({ example: true })
|
||||
isActive?: boolean;
|
||||
}
|
||||
@@ -1,5 +1,38 @@
|
||||
import { EntityRepository } from "@mikro-orm/postgresql";
|
||||
import { EntityRepository, FilterQuery } from "@mikro-orm/postgresql";
|
||||
|
||||
import { Business } from "../entities/business.entity";
|
||||
import { FindBusinessesDto } from "../dto/find-businesses.dto";
|
||||
import { PaginatedResult } from "src/common/interfaces/pagination.interface";
|
||||
|
||||
export class BusinessRepository extends EntityRepository<Business> {}
|
||||
export class BusinessRepository extends EntityRepository<Business> {
|
||||
|
||||
async findAllPaginated(opts: FindBusinessesDto = {}): Promise<PaginatedResult<Business>> {
|
||||
|
||||
const { page = 1, limit = 10, orderBy = 'createdAt', order = 'desc', isActive } = opts;
|
||||
|
||||
const offset = (page - 1) * limit;
|
||||
|
||||
const where: FilterQuery<Business> = {};
|
||||
|
||||
const [data, total] = await this.findAndCount(where, {
|
||||
limit,
|
||||
offset,
|
||||
orderBy: { [orderBy]: order.toLowerCase() as 'asc' | 'desc' },
|
||||
populate: [],
|
||||
});
|
||||
|
||||
const totalPages = Math.ceil(total / limit);
|
||||
|
||||
return {
|
||||
data,
|
||||
meta: {
|
||||
total,
|
||||
page,
|
||||
limit,
|
||||
totalPages,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user