refactor(goods): streamline goods service and controller, remove favorites module
- Removed the PosGoodFavorite module, controller, and service to simplify the codebase. - Updated goods service to handle cache invalidation directly. - Refactored goods controller to remove commented-out code and improve clarity. - Introduced OwnedGoods module for better organization of owned goods functionality. - Updated DTOs to extend from existing structures for consistency. - Enhanced cache invalidation logic in goods service and owned goods service.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '@/prisma/prisma.service';
|
||||
import { ResponseMapper } from '@/common/response/response-mapper'
|
||||
import { Create{{pascalCase name}}Dto } from './dto/create-{{kebabCase name}}.dto';
|
||||
import { Update{{pascalCase name}}Dto } from './dto/update-{{kebabCase name}}.dto';
|
||||
|
||||
@Injectable()
|
||||
export class {{pascalCase name}}Service {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
private readonly summarySelect = {
|
||||
id: true,
|
||||
}
|
||||
|
||||
private readonly select = {
|
||||
...this.summarySelect,
|
||||
}
|
||||
|
||||
private readonly where = () => ({})
|
||||
|
||||
|
||||
async findAll() {
|
||||
const items = await this.prisma.{{camelCase name}}.findMany({
|
||||
where: this.where(),
|
||||
select: this.summarySelect,
|
||||
});
|
||||
return ResponseMapper.list(items)
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
const item = this.prisma.{{camelCase name}}.findUnique({
|
||||
where: {...this.where(), id },
|
||||
select: this.select,
|
||||
});
|
||||
|
||||
return ResponseMapper.single(item)
|
||||
}
|
||||
|
||||
async create(createDto: Create{{pascalCase name}}Dto) {
|
||||
const item = this.prisma.{{camelCase name}}.create({
|
||||
data: createDto,
|
||||
select: this.select,
|
||||
});
|
||||
|
||||
return ResponseMapper.create(item)
|
||||
}
|
||||
|
||||
async update(id: string, updateDto: Update{{pascalCase name}}Dto) {
|
||||
const item = this.prisma.{{camelCase name}}.update({
|
||||
where: { id },
|
||||
data: updateDto,
|
||||
select: this.select,
|
||||
});
|
||||
|
||||
return ResponseMapper.update(item)
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
return this.prisma.{{camelCase name}}.delete({
|
||||
where: { id },
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user