-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f55e4e2
commit 536a3fd
Showing
4 changed files
with
86 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,54 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CreateDishDto } from './dto/create-dish.dto'; | ||
import { UpdateDishDto } from './dto/update-dish.dto'; | ||
import { PrismaService } from 'src/shared/prisma.service'; | ||
|
||
@Injectable() | ||
export class DishService { | ||
create(createDishDto: CreateDishDto) { | ||
console.log(createDishDto); | ||
return 'This action adds a new dish'; | ||
constructor(private readonly prisma: PrismaService) {} | ||
|
||
async create(createDishDto: CreateDishDto) { | ||
return await this.prisma.dish.create({ | ||
data: createDishDto | ||
}); | ||
} | ||
|
||
async findAll(includeTrash: boolean = false) { | ||
return await this.prisma.dish.findMany({ | ||
where: { isActive: !includeTrash } | ||
}); | ||
} | ||
|
||
findAll() { | ||
return `This action returns all dish`; | ||
async findOne(id: number) { | ||
return await this.prisma.dish.findUnique({ | ||
where: { id } | ||
}); | ||
} | ||
|
||
findOne(id: number) { | ||
return `This action returns a #${id} dish`; | ||
async update(id: number, updateDishDto: UpdateDishDto) { | ||
return await this.prisma.dish.update({ | ||
where: { id }, | ||
data: updateDishDto | ||
}); | ||
} | ||
|
||
update(id: number, updateDishDto: UpdateDishDto) { | ||
console.log(updateDishDto); | ||
return `This action updates a #${id} dish`; | ||
async remove(id: number, permanent: boolean = false) { | ||
if (!permanent) { | ||
return await this.prisma.dish.update({ | ||
where: { id }, | ||
data: { isActive: false } | ||
}); | ||
} | ||
|
||
return await this.prisma.dish.delete({ | ||
where: { id } | ||
}); | ||
} | ||
|
||
remove(id: number) { | ||
return `This action removes a #${id} dish`; | ||
async restoreFromTrash(id: number) { | ||
return await this.prisma.dish.update({ | ||
where: { id }, | ||
data: { isActive: true } | ||
}); | ||
} | ||
} |