|
@@ -1,8 +1,62 @@
|
|
|
import { Injectable, NotImplementedException } from '@nestjs/common';
|
|
import { Injectable, NotImplementedException } from '@nestjs/common';
|
|
|
|
|
+import { PrismaService } from '../../prisma/prisma.service';
|
|
|
import { CreateSimulationDto } from './dto/create-simulation.dto';
|
|
import { CreateSimulationDto } from './dto/create-simulation.dto';
|
|
|
|
|
+import { ListSimulationTemplateOptionsQueryDto } from './dto/list-simulation-templates-query.dto';
|
|
|
|
|
+import { SimulationTemplateOptionDto } from './dto/simulation-template-option.dto';
|
|
|
|
|
|
|
|
@Injectable()
|
|
@Injectable()
|
|
|
export class SimulationsService {
|
|
export class SimulationsService {
|
|
|
|
|
+ constructor(private readonly prisma: PrismaService) {}
|
|
|
|
|
+
|
|
|
|
|
+ async listTemplateOptions(
|
|
|
|
|
+ hairstylistId: bigint,
|
|
|
|
|
+ query: ListSimulationTemplateOptionsQueryDto,
|
|
|
|
|
+ ): Promise<{
|
|
|
|
|
+ items: SimulationTemplateOptionDto[];
|
|
|
|
|
+ total: number;
|
|
|
|
|
+ page: number;
|
|
|
|
|
+ pageSize: number;
|
|
|
|
|
+ }> {
|
|
|
|
|
+ const where = {
|
|
|
|
|
+ isDeleted: 0,
|
|
|
|
|
+ status: 'PUBLIC' as const,
|
|
|
|
|
+ templateUrl: { not: '' },
|
|
|
|
|
+ ...(query.category ? { category: query.category } : {}),
|
|
|
|
|
+ ...(query.q ? { templateName: { contains: query.q } } : {}),
|
|
|
|
|
+ ...(query.source === 'STYLIST'
|
|
|
|
|
+ ? { isSystemTemplate: 'NO' as const, hairstylistId }
|
|
|
|
|
+ : { isSystemTemplate: 'YES' as const }),
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const [items, total] = await Promise.all([
|
|
|
|
|
+ this.prisma.hairTemplate.findMany({
|
|
|
|
|
+ where,
|
|
|
|
|
+ orderBy: { id: 'desc' },
|
|
|
|
|
+ skip: (query.page - 1) * query.pageSize,
|
|
|
|
|
+ take: query.pageSize,
|
|
|
|
|
+ }),
|
|
|
|
|
+ this.prisma.hairTemplate.count({ where }),
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ items: items.map((item) => ({
|
|
|
|
|
+ id: item.id.toString(),
|
|
|
|
|
+ templateName: item.templateName,
|
|
|
|
|
+ coverUrl: item.coverUrl,
|
|
|
|
|
+ category: item.category,
|
|
|
|
|
+ tags: item.tags
|
|
|
|
|
+ ? item.tags.split(',').map((tag) => tag.trim()).filter(Boolean)
|
|
|
|
|
+ : [],
|
|
|
|
|
+ description: item.description,
|
|
|
|
|
+ templateUrl: item.templateUrl,
|
|
|
|
|
+ isSystemTemplate: item.isSystemTemplate === 'YES',
|
|
|
|
|
+ })),
|
|
|
|
|
+ total,
|
|
|
|
|
+ page: query.page,
|
|
|
|
|
+ pageSize: query.pageSize,
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
async create(_input: CreateSimulationDto): Promise<never> {
|
|
async create(_input: CreateSimulationDto): Promise<never> {
|
|
|
throw new NotImplementedException(
|
|
throw new NotImplementedException(
|
|
|
'Simulation creation is not implemented yet',
|
|
'Simulation creation is not implemented yet',
|