Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

feat: implement get flagged products endpoint #75

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions backend/src/product/product.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ export class ProductController {
);
}
}

@Get()
async getFlaggedProducts() {
return this.productService.getFlaggedProducts();
}
}
21 changes: 20 additions & 1 deletion backend/src/product/product.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import {
HttpException,
HttpStatus,
Injectable,
InternalServerErrorException,
} from '@nestjs/common';
import { PrismaService } from 'src/prisma/prisma.service';
import { ProductDto } from './dto/product.dto';
import { Product } from 'src/interfaces/Product';
import { generateProductId } from 'src/common/utils/generateProductId';
Expand All @@ -9,6 +15,8 @@ export class ProductService {
private readonly PINATA_GATEWAY =
process.env.PINATA_GATEWAY || 'https://gateway.pinata.cloud/ipfs/';

constructor(private readonly prisma: PrismaService) {}

async pinToIPFS(product: Product) {
const url = 'https://api.pinata.cloud/pinning/pinFileToIPFS';

Expand Down Expand Up @@ -103,4 +111,15 @@ export class ProductService {
);
}
}

async getFlaggedProducts() {
try {
return await this.prisma.flaggedProduct.findMany();
} catch (error) {
throw new InternalServerErrorException(
'Failed to get flagged products:',
error
);
}
}
}
Loading