background
deploy to danak / build_and_deploy (push) Has been cancelled

This commit is contained in:
2026-06-20 20:24:12 +03:30
parent 65a34b97e2
commit ef598a4c28
7 changed files with 105 additions and 7 deletions
@@ -21,6 +21,7 @@ import { Permissions } from 'src/common/decorators/permissions.decorator';
import { Permission } from 'src/common/enums/permission.enum'; import { Permission } from 'src/common/enums/permission.enum';
import { CacheResponse } from 'src/common/decorators/cache-response.decorator'; import { CacheResponse } from 'src/common/decorators/cache-response.decorator';
import { CacheKeyPrefixes } from 'src/common/constants/cache-keys.constant'; import { CacheKeyPrefixes } from 'src/common/constants/cache-keys.constant';
import { UpdateRestaurantBgDto } from '../dto/update-restaurant-bg.dto';
@ApiTags('restaurants') @ApiTags('restaurants')
@Controller() @Controller()
@@ -67,6 +68,25 @@ export class RestaurantsController {
return this.restaurantsService.remove(id); return this.restaurantsService.remove(id);
} }
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Permissions(Permission.UPDATE_RESTAURANT)
@ApiOperation({ summary: 'Update restaurant background' })
@ApiBody({ type: UpdateRestaurantBgDto })
@Patch('admin/restaurants/my-restaurant/background')
updateMyRestaurantBg(@RestId() restId: string, @Body() dto: UpdateRestaurantBgDto) {
return this.restaurantsService.updateBackground(restId, dto);
}
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Permissions(Permission.UPDATE_RESTAURANT)
@ApiOperation({ summary: 'Get backgrounds' })
@Get('admin/restaurants/background')
getBackgrounds() {
return this.restaurantsService.findAllBackgrounds();
}
/** Super Admin Endpoints */ /** Super Admin Endpoints */
@UseGuards(SuperAdminAuthGuard) @UseGuards(SuperAdminAuthGuard)
@ApiBearerAuth() @ApiBearerAuth()
@@ -0,0 +1,24 @@
import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsOptional, IsString } from 'class-validator';
export class UpdateRestaurantBgDto {
@ApiPropertyOptional({ example: 'https://cdn.example.com/backgrounds/wood.jpg', description: 'آدرس تصویر پس‌زمینه' })
@IsOptional()
@IsString()
bgUrl?: string;
@ApiPropertyOptional({ example: '0.8', description: 'شفافیت پس‌زمینه' })
@IsOptional()
@IsString()
bgOpacity?: string;
@ApiPropertyOptional({ example: '4px', description: 'میزان بلور پس‌زمینه' })
@IsOptional()
@IsString()
bgBlur?: string;
@ApiPropertyOptional({ example: 'rgba(0, 0, 0, 0.4)', description: 'رنگ لایه روی پس‌زمینه' })
@IsOptional()
@IsString()
bgOverlay?: string;
}
@@ -0,0 +1,9 @@
import { Entity, Property } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
@Entity({ tableName: 'backgrounds' })
export class Background extends BaseEntity {
@Property()
url: string;
}
@@ -100,13 +100,25 @@ export class Restaurant extends BaseEntity {
@Enum(() => PlanEnum) @Enum(() => PlanEnum)
plan: PlanEnum = PlanEnum.Base; plan: PlanEnum = PlanEnum.Base;
@Property({unique: true,nullable: true}) @Property({ unique: true, nullable: true })
subscriptionId?: string; subscriptionId?: string;
@Property({nullable: true}) @Property({ nullable: true })
subscriptionEndDate?: Date; subscriptionEndDate?: Date;
@Property({nullable: true}) @Property({ nullable: true })
subscriptionStartDate?: Date; subscriptionStartDate?: Date;
@Property({ nullable: true })
bgUrl?: string;
@Property({ nullable: true })
bgOpacity?: string;
@Property({ nullable: true })
bgBlur?: string;
@Property({ nullable: true })
bgOverlay?: string;
} }
@@ -1,6 +1,7 @@
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common'; import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
import { CreateRestaurantDto } from '../dto/create-restaurant.dto'; import { CreateRestaurantDto } from '../dto/create-restaurant.dto';
import { UpdateRestaurantDto } from '../dto/update-restaurant.dto'; import { UpdateRestaurantDto } from '../dto/update-restaurant.dto';
import { UpdateRestaurantBgDto } from '../dto/update-restaurant-bg.dto';
import { UpgradeSubscriptionDto } from '../dto/upgrade-subscription.dto'; import { UpgradeSubscriptionDto } from '../dto/upgrade-subscription.dto';
import { Restaurant } from '../entities/restaurant.entity'; import { Restaurant } from '../entities/restaurant.entity';
import { EntityManager } from '@mikro-orm/postgresql'; import { EntityManager } from '@mikro-orm/postgresql';
@@ -29,6 +30,7 @@ import { SmsLog } from '../../notifications/entities/smsLogs.entity';
import { Notification } from '../../notifications/entities/notification.entity'; import { Notification } from '../../notifications/entities/notification.entity';
import { CacheService } from 'src/modules/utils/cache.service'; import { CacheService } from 'src/modules/utils/cache.service';
import { CacheKeys } from 'src/common/constants/cache-keys.constant'; import { CacheKeys } from 'src/common/constants/cache-keys.constant';
import { BackgroundRepository } from '../repositories/background.repository';
@Injectable() @Injectable()
@@ -36,6 +38,7 @@ export class RestaurantsService {
constructor( constructor(
private readonly em: EntityManager, private readonly em: EntityManager,
private readonly restRepository: RestRepository, private readonly restRepository: RestRepository,
private readonly backgroundRepository: BackgroundRepository,
private readonly cacheService: CacheService, private readonly cacheService: CacheService,
) { } ) { }
@@ -142,8 +145,8 @@ export class RestaurantsService {
} }
async findOneBySubscriptionId(subscriptionId: string): Promise<Restaurant> { async findOneBySubscriptionId(subscriptionId: string): Promise<Restaurant> {
const restaurant = await this.restRepository.findOne({ subscriptionId }); const restaurant = await this.restRepository.findOne({ subscriptionId });
if (!restaurant) { if (!restaurant) {
throw new NotFoundException(RestMessage.NOT_FOUND); throw new NotFoundException(RestMessage.NOT_FOUND);
} }
return restaurant; return restaurant;
@@ -294,4 +297,21 @@ export class RestaurantsService {
}); });
} }
findAllBackgrounds() {
return this.backgroundRepository.findAll();
}
async updateBackground(id: string, dto: UpdateRestaurantBgDto): Promise<Restaurant> {
const restaurant = await this.restRepository.findOne({ id });
if (!restaurant) {
throw new NotFoundException(RestMessage.NOT_FOUND);
}
this.restRepository.assign(restaurant, dto);
await this.em.persistAndFlush(restaurant);
await this.invalidateRestaurantCache(restaurant.slug);
return restaurant;
}
} }
@@ -0,0 +1,10 @@
import { EntityManager, EntityRepository } from '@mikro-orm/postgresql';
import { Injectable } from '@nestjs/common';
import { Background } from '../entities/background.entity';
@Injectable()
export class BackgroundRepository extends EntityRepository<Background> {
constructor(readonly em: EntityManager) {
super(em, Background);
}
}
@@ -12,11 +12,14 @@ import { RestaurantCrone } from './crone/restaurant.crone';
import { JwtModule } from '@nestjs/jwt'; import { JwtModule } from '@nestjs/jwt';
import { AuthModule } from '../auth/auth.module'; import { AuthModule } from '../auth/auth.module';
import { UtilsModule } from '../utils/utils.module'; import { UtilsModule } from '../utils/utils.module';
import { Background } from './entities/background.entity';
import { BackgroundRepository } from './repositories/background.repository';
@Module({ @Module({
controllers: [RestaurantsController, ScheduleController], controllers: [RestaurantsController, ScheduleController],
providers: [RestaurantsService, RestRepository, ScheduleRepository, ScheduleService, RestaurantCrone], providers: [RestaurantsService, RestRepository, ScheduleRepository, ScheduleService, RestaurantCrone, BackgroundRepository],
imports: [MikroOrmModule.forFeature([Restaurant, Schedule]), JwtModule, forwardRef(() => AuthModule), UtilsModule], imports: [MikroOrmModule.forFeature([Restaurant, Schedule, Background]),
JwtModule, forwardRef(() => AuthModule), UtilsModule],
exports: [RestRepository, ScheduleRepository, ScheduleService, RestaurantsService], exports: [RestRepository, ScheduleRepository, ScheduleService, RestaurantsService],
}) })
export class RestaurantsModule { } export class RestaurantsModule { }