Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import PrismaService from '@/app/prisma/prisma.service';
- export class ProductVersionRepository extends PrismaService {
- async getLastAvailableProductVersion(productId: string, version?: string) {
- const { productFavoriteProviderId } = await this.product.findUnique({
- where: {
- id: productId,
- },
- select: {
- productFavoriteProviderId: true,
- },
- });
- const productVersion = await this.productVersion.findFirst({
- /*
- If provide product version:
- 1. productId + version + favoriteProviderId
- 2. productId + version
- If does not provide product version
- 1. productId + favoriteProviderId
- 2. productId
- */
- where: {
- OR: [
- {
- productId,
- version: version || undefined,
- providerId: productFavoriteProviderId || undefined,
- },
- {
- productId,
- version: version || undefined,
- },
- ],
- },
- orderBy: {
- createdAt: 'desc',
- },
- });
- return productVersion;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment