Skip to content

Commit

Permalink
add product brand
Browse files Browse the repository at this point in the history
  • Loading branch information
bahram1249 committed Jul 22, 2024
1 parent 8d14562 commit 98e37e3
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import { imageOptions } from './file-options';
import { GetUser } from '@rahino/auth/decorator';
import { User } from '@rahino/database/models/core/user.entity';

@ApiBearerAuth()
@UseGuards(JwtGuard, PermissionGuard)
@ApiTags('HomePagePhotos')
@Controller({
path: '/api/ecommerce/homePagePhotos',
Expand All @@ -41,6 +39,8 @@ import { User } from '@rahino/database/models/core/user.entity';
export class HomePagePhotoController {
constructor(private service: HomePagePhotoService) {}

@ApiBearerAuth()
@UseGuards(JwtGuard, PermissionGuard)
@UseInterceptors(JsonResponseTransformInterceptor)
@CheckPermission({ permissionSymbol: 'ecommerce.homepagephotos.uploadImage' })
@UseInterceptors(FileInterceptor('file', imageOptions()))
Expand Down Expand Up @@ -75,7 +75,7 @@ export class HomePagePhotoController {
return await this.service.uploadImage(user, file);
}

@CheckPermission({ permissionSymbol: 'ecommerce.homepagephotos.showImage' })
//@CheckPermission({ permissionSymbol: 'ecommerce.homepagephotos.showImage' })
@ApiOperation({ description: 'show home page photo by id' })
@Get('/image/:id')
@HttpCode(HttpStatus.OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ export class CustomContentValidator implements ValidatorConstraintInterface {
const bannerContent = await this.isBannerContent(params);
const sliderContent = await this.isSliderContent(params);
const productContent = await this.isProductCategoryContent(params);
const productBrandContent = await this.isProductBrandContent(params);

if (bannerContent || sliderContent || productContent) {
if (
bannerContent ||
sliderContent ||
productContent ||
productBrandContent
) {
flag = true;
}

Expand Down Expand Up @@ -50,7 +56,15 @@ export class CustomContentValidator implements ValidatorConstraintInterface {
return (
typeof obj.title == 'string' &&
typeof obj.entityTypeId == 'number' &&
typeof obj.entityTypeSortBy == 'number'
typeof obj.sortBy == 'number'
);
}

private async isProductBrandContent(obj: any) {
return (
typeof obj.title == 'string' &&
typeof obj.brandId == 'number' &&
typeof obj.sortBy == 'number'
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { AutoMap } from 'automapper-classes';
import {
IsNotEmpty,
IsNumber,
IsString,
MaxLength,
MinLength,
} from 'class-validator';

export class ProductBrandContentDto {
@IsNotEmpty()
@IsString()
@MinLength(3)
@MaxLength(256)
@AutoMap()
public title: string;

@IsNumber()
@AutoMap()
public brandId: number;

@IsNumber()
@AutoMap()
public sortBy: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export class ProductCategoryContentDto {

@IsNumber()
@AutoMap()
public entityTypeSortBy: number;
public sortBy: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export enum HomePageTypeEnum {
SLIDER = 'slider',
BANNER = 'banner',
PRODUCTCATEGORY = 'productCategory',
PRODUCTBRAND = 'productBrand',
}
37 changes: 35 additions & 2 deletions apps/e-commerce/src/admin/home-page/home-page-validator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { QueryOptionsBuilder } from '@rahino/query-filter/sequelize-query-builde
import { Sequelize } from 'sequelize';
import { Op } from 'sequelize';
import { ECEntityTypeSort } from '@rahino/database/models/ecommerce-eav/ec-entityType-sort.entity';
import { ProductBrandContentDto } from './dto/content/product-brand-content.dto';
import { ECBrand } from '@rahino/database/models/ecommerce-eav/ec-brand.entity';

@Injectable()
export class HomePageValidatorService {
Expand All @@ -19,6 +21,8 @@ export class HomePageValidatorService {
private readonly attachmentRepository: typeof Attachment,
@InjectModel(EAVEntityType)
private readonly entityTypeRepository: typeof EAVEntityType,
@InjectModel(ECBrand)
private readonly brandRepository: typeof ECBrand,
@InjectModel(ECEntityTypeSort)
private readonly entityTypeSortRepository: typeof ECEntityTypeSort,
) {}
Expand Down Expand Up @@ -75,13 +79,42 @@ export class HomePageValidatorService {
}

const sort = await this.entityTypeSortRepository.findOne(
new QueryOptionsBuilder().filter({ id: productContent.sortBy }).build(),
);
if (!sort) {
throw new BadRequestException(
`the entityTypeSortBy-> ${productContent.sortBy} not founded!`,
);
}
}

async productBrandValidator(dto: HomePageDataDto) {
const productContent = dto.content as unknown as ProductBrandContentDto;
const brand = await this.brandRepository.findOne(
new QueryOptionsBuilder()
.filter({ id: productContent.entityTypeSortBy })
.filter({ id: productContent.brandId })
.filter(
Sequelize.where(
Sequelize.fn('isnull', Sequelize.col('ECBrand.isDeleted'), 0),
{
[Op.eq]: 0,
},
),
)
.build(),
);
if (!brand) {
throw new BadRequestException(
`the brandId with this given id (${productContent.brandId}) is not founded!`,
);
}

const sort = await this.entityTypeSortRepository.findOne(
new QueryOptionsBuilder().filter({ id: productContent.sortBy }).build(),
);
if (!sort) {
throw new BadRequestException(
`the entityTypeSortBy-> ${productContent.entityTypeSortBy} not founded!`,
`the entityTypeSortBy-> ${productContent.sortBy} not founded!`,
);
}
}
Expand Down
2 changes: 2 additions & 0 deletions apps/e-commerce/src/admin/home-page/home-page.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export class HomePageService {
await this.homePageValidatorService.bannerValidator(item);
} else if (item.type == HomePageTypeEnum.PRODUCTCATEGORY) {
await this.homePageValidatorService.productCategoryValidator(item);
} else if (item.type == HomePageTypeEnum.PRODUCTBRAND) {
await this.homePageValidatorService.productBrandValidator(item);
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/main/src/sql/core-v1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15255,7 +15255,7 @@ BEGIN
DECLARE @groupId int = null;

DECLARE @entityName nvarchar(256) = N'HomePagePhotoss'
DECLARE @groupName nvarchar(256) = N'ecommerce.admin.homepagephotos'
DECLARE @groupName nvarchar(256) = N'ecommerce.homepagephotos'

DECLARE @permissionSymbolUploadImage nvarchar(512) = @groupName + '.uploadImage';
DECLARE @permissionSymbolShowImage nvarchar(512) = @groupName + '.showImage';
Expand Down

0 comments on commit 98e37e3

Please sign in to comment.